aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorIgor Matuszewski <Xanewok@gmail.com>2018-03-10 14:35:09 +0100
committerIgor Matuszewski <Xanewok@gmail.com>2018-03-13 22:47:36 +0100
commit17ecbaf8ff9ee6987f17cf00a243c136b1b0610e (patch)
tree3a5c49af60938d9d69c6a8941feb4a8e55796e48 /components/script/dom/bindings/codegen/CodegenRust.py
parent725f9cbefabb7a635c7530d3fa65d010d827ffa7 (diff)
downloadservo-17ecbaf8ff9ee6987f17cf00a243c136b1b0610e.tar.gz
servo-17ecbaf8ff9ee6987f17cf00a243c136b1b0610e.zip
Support objects in WebIDL unions
Fixes #17011
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index d2d090f8350..55e72086f12 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1075,20 +1075,24 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.isObject():
assert not isEnforceRange and not isClamp
- # TODO: Need to root somehow
- # https://github.com/servo/servo/issues/6382
+ templateBody = "${val}.get().to_object()"
default = "ptr::null_mut()"
- templateBody = wrapObjectTemplate("${val}.get().to_object()",
- default,
- isDefinitelyObject, type, failureCode)
- if isMember in ("Dictionary", "Union"):
+ # TODO: Do we need to do the same for dictionaries?
+ if isMember == "Union":
+ templateBody = "RootedTraceableBox::from_box(Heap::boxed(%s))" % templateBody
+ default = "RootedTraceableBox::new(Heap::default())"
+ declType = CGGeneric("RootedTraceableBox<Heap<*mut JSObject>>")
+ elif isMember == "Dictionary":
declType = CGGeneric("Heap<*mut JSObject>")
else:
# TODO: Need to root somehow
# https://github.com/servo/servo/issues/6382
declType = CGGeneric("*mut JSObject")
+ templateBody = wrapObjectTemplate(templateBody, default,
+ isDefinitelyObject, type, failureCode)
+
return handleOptional(templateBody, declType,
handleDefaultNull(default))
@@ -4291,11 +4295,13 @@ class CGUnionConversionStruct(CGThing):
else:
mozMapObject = None
- hasObjectTypes = interfaceObject or arrayObject or dateObject or object or mozMapObject
+ hasObjectTypes = object or interfaceObject or arrayObject or dateObject 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)
templateBody = CGList([], "\n")
+ if object:
+ templateBody.append(object)
if interfaceObject:
templateBody.append(interfaceObject)
if arrayObject:
@@ -4363,11 +4369,6 @@ class CGUnionConversionStruct(CGThing):
returnType = "Result<Option<%s>, ()>" % actualType
jsConversion = templateVars["jsConversion"]
- # Any code to convert to Object is unused, since we're already converting
- # from an Object value.
- if t.name == 'Object':
- return CGGeneric('')
-
return CGWrapper(
CGIndenter(jsConversion, 4),
pre="unsafe fn TryConvertTo%s(cx: *mut JSContext, value: HandleValue) -> %s {\n"