aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorKagami Sascha Rosylight <saschanaz@outlook.com>2019-11-05 23:55:15 +0900
committerKagami Sascha Rosylight <saschanaz@outlook.com>2019-11-05 23:55:15 +0900
commit1b22c10483d6c81fe9d186c9b50523ed55d5cfff (patch)
tree24895def6526c5fef9da95925747dc15b591bd39 /components/script/dom/bindings/codegen/CodegenRust.py
parent2aca5c82e475b41da24adc7899423bbcb0966b32 (diff)
downloadservo-1b22c10483d6c81fe9d186c9b50523ed55d5cfff.tar.gz
servo-1b22c10483d6c81fe9d186c9b50523ed55d5cfff.zip
Use TimerHandler IDL union type
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 86ee03d7ddd..62e0d7935a9 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -2410,6 +2410,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
'crate::dom::bindings::conversions::StringificationBehavior',
'crate::dom::bindings::conversions::root_from_handlevalue',
'std::ptr::NonNull',
+ 'std::rc::Rc',
'crate::dom::bindings::record::Record',
'crate::dom::bindings::num::Finite',
'crate::dom::bindings::root::DomRoot',
@@ -2423,6 +2424,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
'js::error::throw_type_error',
'js::rust::HandleValue',
'js::jsapi::Heap',
+ 'js::jsapi::IsCallable',
'js::jsapi::JSContext',
'js::jsapi::JSObject',
'js::rust::MutableHandleValue',
@@ -2438,9 +2440,10 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
if not t.isUnion():
continue
for memberType in t.flatMemberTypes:
- if memberType.isDictionary() or memberType.isEnum():
+ if memberType.isDictionary() or memberType.isEnum() or memberType.isCallback():
memberModule = getModuleFromObject(memberType)
- memberName = memberType.inner.identifier.name
+ memberName = (memberType.callback.identifier.name
+ if memberType.isCallback() else memberType.inner.identifier.name)
imports.append("%s::%s" % (memberModule, memberName))
if memberType.isEnum():
imports.append("%s::%sValues" % (memberModule, memberName))
@@ -4380,6 +4383,9 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
elif is_typed_array(type):
name = type.name
typeName = "typedarray::Heap" + name
+ elif type.isCallback():
+ name = type.name
+ typeName = name
else:
raise TypeError("Can't handle %s in unions yet" % type)
@@ -4418,12 +4424,19 @@ class CGUnionStruct(CGThing):
return False
def define(self):
+ def getTypeWrapper(t):
+ if type_needs_tracing(t):
+ return "RootedTraceableBox"
+ if t.isCallback():
+ return "Rc"
+ return ""
+
templateVars = map(lambda t: (getUnionTypeTemplateVars(t, self.descriptorProvider),
- type_needs_tracing(t)),
+ getTypeWrapper(t)),
self.type.flatMemberTypes)
enumValues = [
- " %s(%s)," % (v["name"], "RootedTraceableBox<%s>" % v["typeName"] if trace else v["typeName"])
- for (v, trace) in templateVars
+ " %s(%s)," % (v["name"], "%s<%s>" % (wrapper, v["typeName"]) if wrapper else v["typeName"])
+ for (v, wrapper) in templateVars
]
enumConversions = [
" %s::%s(ref inner) => inner.to_jsval(cx, rval),"
@@ -4506,7 +4519,8 @@ class CGUnionConversionStruct(CGThing):
callbackMemberTypes = filter(lambda t: t.isCallback() or t.isCallbackInterface(), memberTypes)
if len(callbackMemberTypes) > 0:
assert len(callbackMemberTypes) == 1
- raise TypeError("Can't handle callbacks in unions.")
+ typeName = callbackMemberTypes[0].name
+ callbackObject = CGGeneric(get_match(typeName))
else:
callbackObject = None
@@ -4537,7 +4551,7 @@ class CGUnionConversionStruct(CGThing):
else:
mozMapObject = None
- hasObjectTypes = object or interfaceObject or arrayObject or dateObject or mozMapObject
+ hasObjectTypes = object or interfaceObject or arrayObject or dateObject or callbackObject or mozMapObject
if hasObjectTypes:
# "object" is not distinguishable from other types
assert not object or not (interfaceObject or arrayObject or dateObject or callbackObject or mozMapObject)
@@ -4548,6 +4562,8 @@ class CGUnionConversionStruct(CGThing):
templateBody.append(interfaceObject)
if arrayObject:
templateBody.append(arrayObject)
+ if callbackObject:
+ templateBody.append(callbackObject)
if mozMapObject:
templateBody.append(mozMapObject)
conversions.append(CGIfWrapper("value.get().is_object()", templateBody))
@@ -4608,6 +4624,8 @@ class CGUnionConversionStruct(CGThing):
actualType = templateVars["typeName"]
if type_needs_tracing(t):
actualType = "RootedTraceableBox<%s>" % actualType
+ if t.isCallback():
+ actualType = "Rc<%s>" % actualType
returnType = "Result<Option<%s>, ()>" % actualType
jsConversion = templateVars["jsConversion"]