diff options
author | Josh Matthews <josh@joshmatthews.net> | 2014-04-24 11:44:53 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2014-05-03 14:18:31 -0400 |
commit | 895e9ee37fb572f7750c02de4fc51060990c51be (patch) | |
tree | 0fa065564d38f030f42541f9744caa4da4e6f7b7 /src/components/script/dom/bindings/codegen | |
parent | 0f2d0b1dc3d98ef109627dda061c5a54ff06a91d (diff) | |
download | servo-895e9ee37fb572f7750c02de4fc51060990c51be.tar.gz servo-895e9ee37fb572f7750c02de4fc51060990c51be.zip |
Make dictionaries contain Root<T> values instead of JS<T>, ensuring that they will not be collected while the dictionary is alive.
Diffstat (limited to 'src/components/script/dom/bindings/codegen')
-rw-r--r-- | src/components/script/dom/bindings/codegen/CodegenRust.py | 15 | ||||
-rw-r--r-- | src/components/script/dom/bindings/codegen/Configuration.py | 1 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 1aa46c6a44a..8c9eb5d6f8b 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -602,6 +602,8 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, failureCode) return handleOptional(template, declType, isOptional) + descriptorType = descriptor.memberType if isMember else descriptor.nativeType + templateBody = "" if descriptor.interface.isConsequential(): raise TypeError("Consequential interface %s being used as an " @@ -617,11 +619,14 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, descriptor, "(${val}).to_object()")) - declType = CGGeneric(descriptor.nativeType) + declType = CGGeneric(descriptorType) if type.nullable(): templateBody = "Some(%s)" % templateBody declType = CGWrapper(declType, pre="Option<", post=">") + if isMember: + templateBody += ".root()" + templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject, type, failureCode) @@ -4069,7 +4074,7 @@ class CGDictionary(CGThing): def struct(self): d = self.dictionary if d.parent: - inheritance = " pub parent: %s::%s,\n" % (self.makeModuleName(d.parent), + inheritance = " pub parent: %s::%s<'a, 'b>,\n" % (self.makeModuleName(d.parent), self.makeClassName(d.parent)) else: inheritance = "" @@ -4078,7 +4083,7 @@ class CGDictionary(CGThing): for m in self.memberInfo] return (string.Template( - "pub struct ${selfName} {\n" + + "pub struct ${selfName}<'a, 'b> {\n" + "${inheritance}" + "\n".join(memberDecls) + "\n" + "}").substitute( { "selfName": self.makeClassName(d), @@ -4104,7 +4109,7 @@ class CGDictionary(CGThing): memberInits = CGList([memberInit(m) for m in self.memberInfo]) return string.Template( - "impl ${selfName} {\n" + "impl<'a, 'b> ${selfName}<'a, 'b> {\n" " pub fn new(cx: *JSContext, val: JSVal) -> Result<${selfName}, ()> {\n" " let object = if val.is_null_or_undefined() {\n" " ptr::null()\n" @@ -4305,7 +4310,7 @@ class CGBindingRoot(CGThing): 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*', 'dom::bindings', - 'dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalRootable, OptionalRootedRootable}', + 'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary, OptionalRootable, OptionalRootedRootable, ResultRootable}', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', diff --git a/src/components/script/dom/bindings/codegen/Configuration.py b/src/components/script/dom/bindings/codegen/Configuration.py index c5b9ebb1044..dc4daa18b26 100644 --- a/src/components/script/dom/bindings/codegen/Configuration.py +++ b/src/components/script/dom/bindings/codegen/Configuration.py @@ -135,6 +135,7 @@ class Descriptor(DescriptorProvider): self.returnType = "Temporary<%s>" % ifaceName self.argumentType = "JSRef<%s>" % ifaceName + self.memberType = "Root<'a, 'b, %s>" % ifaceName self.nativeType = desc.get('nativeType', nativeTypeDefault) self.concreteType = desc.get('concreteType', ifaceName) self.createGlobal = desc.get('createGlobal', False) |