mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Auto merge of #5569 - Ms2ger:object, r=jdm
This commit is contained in:
commit
3fb666cf60
3 changed files with 42 additions and 7 deletions
|
@ -582,7 +582,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
|
||||
# A helper function for wrapping up the template body for
|
||||
# possibly-nullable objecty stuff
|
||||
def wrapObjectTemplate(templateBody, isDefinitelyObject, type,
|
||||
def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,
|
||||
failureCode=None):
|
||||
if not isDefinitelyObject:
|
||||
# Handle the non-object cases by wrapping up the whole
|
||||
|
@ -593,7 +593,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
if type.nullable():
|
||||
templateBody += (
|
||||
"} else if (${val}).is_null_or_undefined() {\n"
|
||||
" None\n")
|
||||
" %s\n") % nullValue
|
||||
templateBody += (
|
||||
"} else {\n" +
|
||||
CGIndenter(onFailureNotAnObject(failureCode)).define() +
|
||||
|
@ -632,7 +632,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
template = "%s::new((${val}).to_object())" % name
|
||||
if type.nullable():
|
||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||
template = wrapObjectTemplate("Some(%s)" % template, isDefinitelyObject, type,
|
||||
template = wrapObjectTemplate("Some(%s)" % template, "None",
|
||||
isDefinitelyObject, type,
|
||||
failureCode)
|
||||
|
||||
return handleOptional(template, declType, handleDefaultNull("None"))
|
||||
|
@ -675,8 +676,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
if isMember:
|
||||
templateBody += ".root()"
|
||||
|
||||
templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject,
|
||||
type, failureCode)
|
||||
templateBody = wrapObjectTemplate(templateBody, "None",
|
||||
isDefinitelyObject, type, failureCode)
|
||||
|
||||
return handleOptional(templateBody, declType, handleDefaultNull("None"))
|
||||
|
||||
|
@ -821,6 +822,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
onFailureNotCallable(failureCode)).define()
|
||||
template = wrapObjectTemplate(
|
||||
template,
|
||||
"None",
|
||||
isDefinitelyObject,
|
||||
type,
|
||||
failureCode)
|
||||
|
@ -853,7 +855,15 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
return handleOptional("${val}", declType, default)
|
||||
|
||||
if type.isObject():
|
||||
raise TypeError("Can't handle object arguments yet")
|
||||
assert not isEnforceRange and not isClamp
|
||||
|
||||
declType = CGGeneric("*mut JSObject")
|
||||
templateBody = wrapObjectTemplate("${val}.to_object()",
|
||||
"ptr::null_mut()",
|
||||
isDefinitelyObject, type, failureCode)
|
||||
|
||||
return handleOptional(templateBody, declType,
|
||||
handleDefaultNull("ptr::null_mut()"))
|
||||
|
||||
if type.isDictionary():
|
||||
if failureCode is not None:
|
||||
|
|
|
@ -24,6 +24,7 @@ use js::jsapi::{JSContext, JSObject};
|
|||
use js::jsval::{JSVal, NullValue};
|
||||
|
||||
use std::borrow::ToOwned;
|
||||
use std::ptr;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct TestBinding {
|
||||
|
@ -78,6 +79,8 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn ArrayAttribute(self, _: *mut JSContext) -> *mut JSObject { NullValue().to_object_or_null() }
|
||||
fn AnyAttribute(self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||
fn SetAnyAttribute(self, _: *mut JSContext, _: JSVal) {}
|
||||
fn ObjectAttribute(self, _: *mut JSContext) -> *mut JSObject { panic!() }
|
||||
fn SetObjectAttribute(self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
|
||||
fn GetBooleanAttributeNullable(self) -> Option<bool> { Some(false) }
|
||||
fn SetBooleanAttributeNullable(self, _: Option<bool>) {}
|
||||
|
@ -119,6 +122,8 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
Some(Blob::new(global.r(), None, ""))
|
||||
}
|
||||
fn SetInterfaceAttributeNullable(self, _: Option<JSRef<Blob>>) {}
|
||||
fn GetObjectAttributeNullable(self, _: *mut JSContext) -> *mut JSObject { ptr::null_mut() }
|
||||
fn SetObjectAttributeNullable(self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn GetUnionAttributeNullable(self) -> Option<HTMLElementOrLong> { Some(eLong(0)) }
|
||||
fn SetUnionAttributeNullable(self, _: Option<HTMLElementOrLong>) {}
|
||||
fn GetUnion2AttributeNullable(self) -> Option<EventOrString> { Some(eString("".to_owned())) }
|
||||
|
@ -147,6 +152,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
Blob::new(global.r(), None, "")
|
||||
}
|
||||
fn ReceiveAny(self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||
fn ReceiveObject(self, _: *mut JSContext) -> *mut JSObject { panic!() }
|
||||
fn ReceiveUnion(self) -> HTMLElementOrLong { eLong(0) }
|
||||
fn ReceiveUnion2(self) -> EventOrString { eString("".to_owned()) }
|
||||
|
||||
|
@ -171,6 +177,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
let global = self.global.root();
|
||||
Some(Blob::new(global.r(), None, ""))
|
||||
}
|
||||
fn ReceiveNullableObject(self, _: *mut JSContext) -> *mut JSObject { ptr::null_mut() }
|
||||
fn ReceiveNullableUnion(self) -> Option<HTMLElementOrLong> { Some(eLong(0)) }
|
||||
fn ReceiveNullableUnion2(self) -> Option<EventOrString> { Some(eString("".to_owned())) }
|
||||
|
||||
|
@ -196,6 +203,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn PassUnion2(self, _: EventOrString) {}
|
||||
fn PassUnion3(self, _: BlobOrString) {}
|
||||
fn PassAny(self, _: *mut JSContext, _: JSVal) {}
|
||||
fn PassObject(self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn PassCallbackFunction(self, _: Function) {}
|
||||
fn PassCallbackInterface(self, _: EventListener) {}
|
||||
|
||||
|
@ -217,6 +225,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn PassNullableByteString(self, _: Option<ByteString>) {}
|
||||
// fn PassNullableEnum(self, _: Option<TestEnum>) {}
|
||||
fn PassNullableInterface(self, _: Option<JSRef<Blob>>) {}
|
||||
fn PassNullableObject(self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn PassNullableUnion(self, _: Option<HTMLElementOrLong>) {}
|
||||
fn PassNullableUnion2(self, _: Option<EventOrString>) {}
|
||||
fn PassNullableCallbackFunction(self, _: Option<Function>) {}
|
||||
|
@ -243,6 +252,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn PassOptionalUnion(self, _: Option<HTMLElementOrLong>) {}
|
||||
fn PassOptionalUnion2(self, _: Option<EventOrString>) {}
|
||||
fn PassOptionalAny(self, _: *mut JSContext, _: JSVal) {}
|
||||
fn PassOptionalObject(self, _: *mut JSContext, _: Option<*mut JSObject>) {}
|
||||
fn PassOptionalCallbackFunction(self, _: Option<Function>) {}
|
||||
fn PassOptionalCallbackInterface(self, _: Option<EventListener>) {}
|
||||
|
||||
|
@ -264,6 +274,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn PassOptionalNullableByteString(self, _: Option<Option<ByteString>>) {}
|
||||
// fn PassOptionalNullableEnum(self, _: Option<Option<TestEnum>>) {}
|
||||
fn PassOptionalNullableInterface(self, _: Option<Option<JSRef<Blob>>>) {}
|
||||
fn PassOptionalNullableObject(self, _: *mut JSContext, _: Option<*mut JSObject>) {}
|
||||
fn PassOptionalNullableUnion(self, _: Option<Option<HTMLElementOrLong>>) {}
|
||||
fn PassOptionalNullableUnion2(self, _: Option<Option<EventOrString>>) {}
|
||||
fn PassOptionalNullableCallbackFunction(self, _: Option<Option<Function>>) {}
|
||||
|
@ -300,6 +311,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn PassOptionalNullableByteStringWithDefault(self, _: Option<ByteString>) {}
|
||||
// fn PassOptionalNullableEnumWithDefault(self, _: Option<TestEnum>) {}
|
||||
fn PassOptionalNullableInterfaceWithDefault(self, _: Option<JSRef<Blob>>) {}
|
||||
fn PassOptionalNullableObjectWithDefault(self, _: *mut JSContext, _: *mut JSObject) {}
|
||||
fn PassOptionalNullableUnionWithDefault(self, _: Option<HTMLElementOrLong>) {}
|
||||
fn PassOptionalNullableUnion2WithDefault(self, _: Option<EventOrString>) {}
|
||||
// fn PassOptionalNullableCallbackFunctionWithDefault(self, _: Option<Function>) {}
|
||||
|
@ -345,6 +357,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn PassVariadicUnion2(self, _: Vec<EventOrString>) {}
|
||||
fn PassVariadicUnion3(self, _: Vec<BlobOrString>) {}
|
||||
fn PassVariadicAny(self, _: *mut JSContext, _: Vec<JSVal>) {}
|
||||
fn PassVariadicObject(self, _: *mut JSContext, _: Vec<*mut JSObject>) {}
|
||||
}
|
||||
|
||||
impl TestBinding {
|
||||
|
|
|
@ -23,6 +23,7 @@ dictionary TestDictionary {
|
|||
TestEnum enumValue;
|
||||
Blob interfaceValue;
|
||||
any anyValue;
|
||||
object objectValue;
|
||||
};
|
||||
|
||||
dictionary TestDictionaryDefaults {
|
||||
|
@ -60,6 +61,7 @@ dictionary TestDictionaryDefaults {
|
|||
DOMString? nullableStringValue = "foo";
|
||||
USVString? nullableUsvstringValue = "foo";
|
||||
// TestEnum? nullableEnumValue = "bar";
|
||||
object? nullableObjectValue = null;
|
||||
};
|
||||
|
||||
interface TestBinding {
|
||||
|
@ -85,6 +87,7 @@ interface TestBinding {
|
|||
attribute (Event or DOMString) union2Attribute;
|
||||
readonly attribute Uint8ClampedArray arrayAttribute;
|
||||
attribute any anyAttribute;
|
||||
attribute object objectAttribute;
|
||||
|
||||
attribute boolean? booleanAttributeNullable;
|
||||
attribute byte? byteAttributeNullable;
|
||||
|
@ -104,6 +107,7 @@ interface TestBinding {
|
|||
attribute ByteString? byteStringAttributeNullable;
|
||||
readonly attribute TestEnum? enumAttributeNullable;
|
||||
attribute Blob? interfaceAttributeNullable;
|
||||
attribute object? objectAttributeNullable;
|
||||
attribute (HTMLElement or long)? unionAttributeNullable;
|
||||
attribute (Event or DOMString)? union2AttributeNullable;
|
||||
[BinaryName="BinaryRenamedAttribute"] attribute DOMString attrToBinaryRename;
|
||||
|
@ -129,6 +133,7 @@ interface TestBinding {
|
|||
TestEnum receiveEnum();
|
||||
Blob receiveInterface();
|
||||
any receiveAny();
|
||||
object receiveObject();
|
||||
(HTMLElement or long) receiveUnion();
|
||||
(Event or DOMString) receiveUnion2();
|
||||
|
||||
|
@ -150,6 +155,7 @@ interface TestBinding {
|
|||
ByteString? receiveNullableByteString();
|
||||
TestEnum? receiveNullableEnum();
|
||||
Blob? receiveNullableInterface();
|
||||
object? receiveNullableObject();
|
||||
(HTMLElement or long)? receiveNullableUnion();
|
||||
(Event or DOMString)? receiveNullableUnion2();
|
||||
|
||||
|
@ -175,6 +181,7 @@ interface TestBinding {
|
|||
void passUnion2((Event or DOMString) data);
|
||||
void passUnion3((Blob or DOMString) data);
|
||||
void passAny(any arg);
|
||||
void passObject(object arg);
|
||||
void passCallbackFunction(Function fun);
|
||||
void passCallbackInterface(EventListener listener);
|
||||
|
||||
|
@ -196,6 +203,7 @@ interface TestBinding {
|
|||
void passNullableByteString(ByteString? arg);
|
||||
// void passNullableEnum(TestEnum? arg);
|
||||
void passNullableInterface(Blob? arg);
|
||||
void passNullableObject(object? arg);
|
||||
void passNullableUnion((HTMLElement or long)? arg);
|
||||
void passNullableUnion2((Event or DOMString)? data);
|
||||
void passNullableCallbackFunction(Function? fun);
|
||||
|
@ -222,6 +230,7 @@ interface TestBinding {
|
|||
void passOptionalUnion(optional (HTMLElement or long) arg);
|
||||
void passOptionalUnion2(optional (Event or DOMString) data);
|
||||
void passOptionalAny(optional any arg);
|
||||
void passOptionalObject(optional object arg);
|
||||
void passOptionalCallbackFunction(optional Function fun);
|
||||
void passOptionalCallbackInterface(optional EventListener listener);
|
||||
|
||||
|
@ -243,6 +252,7 @@ interface TestBinding {
|
|||
void passOptionalNullableByteString(optional ByteString? arg);
|
||||
// void passOptionalNullableEnum(optional TestEnum? arg);
|
||||
void passOptionalNullableInterface(optional Blob? arg);
|
||||
void passOptionalNullableObject(optional object? arg);
|
||||
void passOptionalNullableUnion(optional (HTMLElement or long)? arg);
|
||||
void passOptionalNullableUnion2(optional (Event or DOMString)? data);
|
||||
void passOptionalNullableCallbackFunction(optional Function? fun);
|
||||
|
@ -277,6 +287,7 @@ interface TestBinding {
|
|||
void passOptionalNullableByteStringWithDefault(optional ByteString? arg = null);
|
||||
// void passOptionalNullableEnumWithDefault(optional TestEnum? arg = null);
|
||||
void passOptionalNullableInterfaceWithDefault(optional Blob? arg = null);
|
||||
void passOptionalNullableObjectWithDefault(optional object? arg = null);
|
||||
void passOptionalNullableUnionWithDefault(optional (HTMLElement or long)? arg = null);
|
||||
void passOptionalNullableUnion2WithDefault(optional (Event or DOMString)? data = null);
|
||||
// void passOptionalNullableCallbackFunctionWithDefault(optional Function? fun = null);
|
||||
|
@ -324,6 +335,7 @@ interface TestBinding {
|
|||
void passVariadicUnion2((Event or DOMString)... args);
|
||||
void passVariadicUnion3((Blob or DOMString)... args);
|
||||
void passVariadicAny(any... args);
|
||||
void passVariadicObject(object... args);
|
||||
|
||||
static attribute boolean booleanAttributeStatic;
|
||||
static void receiveVoidStatic();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue