aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py25
-rw-r--r--components/script/dom/bindings/trace.rs7
2 files changed, 19 insertions, 13 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"
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index 5153b70e72f..f0c704b0b0a 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -765,7 +765,12 @@ unsafe impl<T: JSTraceable + 'static> JSTraceable for RootedTraceableBox<T> {
impl<T: JSTraceable + 'static> RootedTraceableBox<T> {
/// DomRoot a JSTraceable thing for the life of this RootedTraceable
pub fn new(traceable: T) -> RootedTraceableBox<T> {
- let traceable = Box::into_raw(Box::new(traceable));
+ Self::from_box(Box::new(traceable))
+ }
+
+ /// Consumes a boxed JSTraceable and roots it for the life of this RootedTraceable.
+ pub fn from_box(boxed_traceable: Box<T>) -> RootedTraceableBox<T> {
+ let traceable = Box::into_raw(boxed_traceable);
unsafe {
RootedTraceableSet::add(traceable);
}