зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #1851 - Pass Option<JSVal> for optional JSVals (from Ms2ger:optional-jsval); r=jdm
Right now, we silently default to null, which is somewhat fishy. Source-Repo: https://github.com/servo/servo Source-Revision: 810699c47d52616b385dfc840ebca06d902f9233
This commit is contained in:
Родитель
bfa13f1ef0
Коммит
83e9cbca0c
|
@ -1162,10 +1162,18 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
if isMember:
|
||||
raise TypeError("Can't handle member 'any'; need to sort out "
|
||||
"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,
|
||||
"${declName} = JSVAL_NULL")
|
||||
return (templateBody, CGGeneric("JSVal"), None, isOptional, "JSVAL_NULL")
|
||||
|
||||
return (templateBody, declType, None, isOptional, "None" if isOptional else None)
|
||||
|
||||
if type.isObject():
|
||||
assert not isEnforceRange and not isClamp
|
||||
|
|
|
@ -8,6 +8,9 @@ use dom::blob::Blob;
|
|||
use dom::window::Window;
|
||||
use servo_util::str::DOMString;
|
||||
|
||||
use js::JSVAL_NULL;
|
||||
use js::jsapi::{JSVal, JSContext};
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub struct TestBinding {
|
||||
reflector: Reflector,
|
||||
|
@ -41,6 +44,8 @@ impl TestBinding {
|
|||
pub fn SetStringAttribute(&self, _: DOMString) {}
|
||||
pub fn InterfaceAttribute(&self) -> JS<Blob> { Blob::new(&self.window) }
|
||||
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 SetBooleanAttributeNullable(&self, _: Option<bool>) {}
|
||||
|
@ -83,6 +88,7 @@ impl TestBinding {
|
|||
// pub fn PassOptionalDouble(&self, _: Option<f64>) {}
|
||||
pub fn PassOptionalString(&self, _: Option<DOMString>) {}
|
||||
pub fn PassOptionalInterface(&self, _: Option<JS<Blob>>) {}
|
||||
pub fn PassOptionalAny(&self, _: *JSContext, _: Option<JSVal>) {}
|
||||
|
||||
// pub fn PassOptionalNullableBoolean(&self, _: Option<Option<bool>>) {}
|
||||
// pub fn PassOptionalNullableByte(&self, _: Option<Option<i8>>) {}
|
||||
|
@ -122,6 +128,7 @@ impl TestBinding {
|
|||
pub fn PassOptionalNullableDoubleWithDefault(&self, _: Option<f64>) {}
|
||||
// pub fn PassOptionalNullableStringWithDefault(&self, _: Option<DOMString>) {}
|
||||
pub fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<JS<Blob>>) {}
|
||||
pub fn PassOptionalAnyWithDefault(&self, _: *JSContext, _: JSVal) {}
|
||||
|
||||
pub fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
||||
pub fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
||||
|
|
|
@ -16,6 +16,7 @@ interface TestBinding {
|
|||
attribute double doubleAttribute;
|
||||
attribute DOMString stringAttribute;
|
||||
attribute Blob interfaceAttribute;
|
||||
attribute any anyAttribute;
|
||||
|
||||
attribute boolean? booleanAttributeNullable;
|
||||
attribute byte? byteAttributeNullable;
|
||||
|
@ -45,6 +46,7 @@ interface TestBinding {
|
|||
// void passOptionalDouble(optional double arg);
|
||||
void passOptionalString(optional DOMString arg);
|
||||
void passOptionalInterface(optional Blob arg);
|
||||
void passOptionalAny(optional any arg);
|
||||
|
||||
// void passOptionalNullableBoolean(optional boolean? arg);
|
||||
// void passOptionalNullableByte(optional byte? arg);
|
||||
|
@ -82,6 +84,7 @@ interface TestBinding {
|
|||
void passOptionalNullableUnsignedLongLongWithDefault(optional unsigned long long? arg = null);
|
||||
// void passOptionalNullableStringWithDefault(optional DOMString? arg = null);
|
||||
void passOptionalNullableInterfaceWithDefault(optional Blob? arg = null);
|
||||
void passOptionalAnyWithDefault(optional any arg = null);
|
||||
|
||||
void passOptionalNullableBooleanWithNonNullDefault(optional boolean? arg = false);
|
||||
void passOptionalNullableByteWithNonNullDefault(optional byte? arg = 7);
|
||||
|
|
|
@ -207,7 +207,7 @@ impl Window {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче