From 17ecbaf8ff9ee6987f17cf00a243c136b1b0610e Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Sat, 10 Mar 2018 14:35:09 +0100 Subject: Support objects in WebIDL unions Fixes #17011 --- .../script/dom/bindings/codegen/CodegenRust.py | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'components/script/dom/bindings/codegen/CodegenRust.py') 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>") + 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, ()>" % 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" -- cgit v1.2.3