mirror of
https://github.com/servo/servo.git
synced 2025-06-17 12:54:28 +00:00
auto merge of #1851 : Ms2ger/servo/optional-jsval, r=jdm
Right now, we silently default to null, which is somewhat fishy.
This commit is contained in:
commit
810699c47d
4 changed files with 21 additions and 3 deletions
|
@ -1162,10 +1162,18 @@ for (uint32_t i = 0; i < length; ++i) {
|
||||||
if isMember:
|
if isMember:
|
||||||
raise TypeError("Can't handle member 'any'; need to sort out "
|
raise TypeError("Can't handle member 'any'; need to sort out "
|
||||||
"rooting issues")
|
"rooting issues")
|
||||||
templateBody = "${declName} = ${val};"
|
|
||||||
|
declType = CGGeneric("JSVal")
|
||||||
|
value = CGGeneric("${val}")
|
||||||
|
if isOptional:
|
||||||
|
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||||
|
value = CGWrapper(value, pre="Some(", post=")")
|
||||||
|
|
||||||
|
templateBody = "${declName} = %s;" % value.define()
|
||||||
templateBody = handleDefaultNull(templateBody,
|
templateBody = handleDefaultNull(templateBody,
|
||||||
"${declName} = JSVAL_NULL")
|
"${declName} = JSVAL_NULL")
|
||||||
return (templateBody, CGGeneric("JSVal"), None, isOptional, "JSVAL_NULL")
|
|
||||||
|
return (templateBody, declType, None, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
if type.isObject():
|
if type.isObject():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
|
|
@ -8,6 +8,9 @@ use dom::blob::Blob;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
|
use js::JSVAL_NULL;
|
||||||
|
use js::jsapi::{JSVal, JSContext};
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
pub struct TestBinding {
|
pub struct TestBinding {
|
||||||
reflector: Reflector,
|
reflector: Reflector,
|
||||||
|
@ -41,6 +44,8 @@ impl TestBinding {
|
||||||
pub fn SetStringAttribute(&self, _: DOMString) {}
|
pub fn SetStringAttribute(&self, _: DOMString) {}
|
||||||
pub fn InterfaceAttribute(&self) -> JS<Blob> { Blob::new(&self.window) }
|
pub fn InterfaceAttribute(&self) -> JS<Blob> { Blob::new(&self.window) }
|
||||||
pub fn SetInterfaceAttribute(&self, _: &JS<Blob>) {}
|
pub fn SetInterfaceAttribute(&self, _: &JS<Blob>) {}
|
||||||
|
pub fn AnyAttribute(&self, _: *JSContext) -> JSVal { JSVAL_NULL }
|
||||||
|
pub fn SetAnyAttribute(&self, _: *JSContext, _: JSVal) {}
|
||||||
|
|
||||||
pub fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
pub fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
||||||
pub fn SetBooleanAttributeNullable(&self, _: Option<bool>) {}
|
pub fn SetBooleanAttributeNullable(&self, _: Option<bool>) {}
|
||||||
|
@ -83,6 +88,7 @@ impl TestBinding {
|
||||||
// pub fn PassOptionalDouble(&self, _: Option<f64>) {}
|
// pub fn PassOptionalDouble(&self, _: Option<f64>) {}
|
||||||
pub fn PassOptionalString(&self, _: Option<DOMString>) {}
|
pub fn PassOptionalString(&self, _: Option<DOMString>) {}
|
||||||
pub fn PassOptionalInterface(&self, _: Option<JS<Blob>>) {}
|
pub fn PassOptionalInterface(&self, _: Option<JS<Blob>>) {}
|
||||||
|
pub fn PassOptionalAny(&self, _: *JSContext, _: Option<JSVal>) {}
|
||||||
|
|
||||||
// pub fn PassOptionalNullableBoolean(&self, _: Option<Option<bool>>) {}
|
// pub fn PassOptionalNullableBoolean(&self, _: Option<Option<bool>>) {}
|
||||||
// pub fn PassOptionalNullableByte(&self, _: Option<Option<i8>>) {}
|
// pub fn PassOptionalNullableByte(&self, _: Option<Option<i8>>) {}
|
||||||
|
@ -122,6 +128,7 @@ impl TestBinding {
|
||||||
pub fn PassOptionalNullableDoubleWithDefault(&self, _: Option<f64>) {}
|
pub fn PassOptionalNullableDoubleWithDefault(&self, _: Option<f64>) {}
|
||||||
// pub fn PassOptionalNullableStringWithDefault(&self, _: Option<DOMString>) {}
|
// pub fn PassOptionalNullableStringWithDefault(&self, _: Option<DOMString>) {}
|
||||||
pub fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<JS<Blob>>) {}
|
pub fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<JS<Blob>>) {}
|
||||||
|
pub fn PassOptionalAnyWithDefault(&self, _: *JSContext, _: JSVal) {}
|
||||||
|
|
||||||
pub fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
pub fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
||||||
pub fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
pub fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
||||||
|
|
|
@ -16,6 +16,7 @@ interface TestBinding {
|
||||||
attribute double doubleAttribute;
|
attribute double doubleAttribute;
|
||||||
attribute DOMString stringAttribute;
|
attribute DOMString stringAttribute;
|
||||||
attribute Blob interfaceAttribute;
|
attribute Blob interfaceAttribute;
|
||||||
|
attribute any anyAttribute;
|
||||||
|
|
||||||
attribute boolean? booleanAttributeNullable;
|
attribute boolean? booleanAttributeNullable;
|
||||||
attribute byte? byteAttributeNullable;
|
attribute byte? byteAttributeNullable;
|
||||||
|
@ -45,6 +46,7 @@ interface TestBinding {
|
||||||
// void passOptionalDouble(optional double arg);
|
// void passOptionalDouble(optional double arg);
|
||||||
void passOptionalString(optional DOMString arg);
|
void passOptionalString(optional DOMString arg);
|
||||||
void passOptionalInterface(optional Blob arg);
|
void passOptionalInterface(optional Blob arg);
|
||||||
|
void passOptionalAny(optional any arg);
|
||||||
|
|
||||||
// void passOptionalNullableBoolean(optional boolean? arg);
|
// void passOptionalNullableBoolean(optional boolean? arg);
|
||||||
// void passOptionalNullableByte(optional byte? arg);
|
// void passOptionalNullableByte(optional byte? arg);
|
||||||
|
@ -82,6 +84,7 @@ interface TestBinding {
|
||||||
void passOptionalNullableUnsignedLongLongWithDefault(optional unsigned long long? arg = null);
|
void passOptionalNullableUnsignedLongLongWithDefault(optional unsigned long long? arg = null);
|
||||||
// void passOptionalNullableStringWithDefault(optional DOMString? arg = null);
|
// void passOptionalNullableStringWithDefault(optional DOMString? arg = null);
|
||||||
void passOptionalNullableInterfaceWithDefault(optional Blob? arg = null);
|
void passOptionalNullableInterfaceWithDefault(optional Blob? arg = null);
|
||||||
|
void passOptionalAnyWithDefault(optional any arg = null);
|
||||||
|
|
||||||
void passOptionalNullableBooleanWithNonNullDefault(optional boolean? arg = false);
|
void passOptionalNullableBooleanWithNonNullDefault(optional boolean? arg = false);
|
||||||
void passOptionalNullableByteWithNonNullDefault(optional byte? arg = 7);
|
void passOptionalNullableByteWithNonNullDefault(optional byte? arg = 7);
|
||||||
|
|
|
@ -207,7 +207,7 @@ impl Window {
|
||||||
pub fn Print(&self) {
|
pub fn Print(&self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: JSVal) -> JSVal {
|
pub fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option<JSVal>) -> JSVal {
|
||||||
JSVAL_NULL
|
JSVAL_NULL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue