diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-01-16 10:16:44 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-16 10:16:44 -0800 |
commit | e891277dd5a52bc3a2b76dfd78da9b82b4c11b40 (patch) | |
tree | da47fb84567db690b8c4649619cbe89b577c708d /components/script/dom/bindings/codegen/CodegenRust.py | |
parent | 44fa478d7bb87fea52ef4af78267738316f22587 (diff) | |
parent | 3f35c3eee22cb52de04dea764e529517f6bfef0d (diff) | |
download | servo-e891277dd5a52bc3a2b76dfd78da9b82b4c11b40.tar.gz servo-e891277dd5a52bc3a2b76dfd78da9b82b4c11b40.zip |
Auto merge of #14994 - jdm:callback_rooting, r=Manishearth,Ms2ger
Make WebIDL callbacks permanently rooted
This replicates the same model that Promise uses right now, because it requires less thinking than coming up with something else.
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14447
- [ ] There are tests for these changes
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14994)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 5df27a850d9..f531937d05e 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -769,7 +769,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, if descriptor.interface.isCallback(): name = descriptor.nativeType declType = CGWrapper(CGGeneric(name), pre="Rc<", post=">") - template = "%s::new(${val}.get().to_object())" % name + template = "%s::new(cx, ${val}.get().to_object())" % name if type.nullable(): declType = CGWrapper(declType, pre="Option<", post=">") template = wrapObjectTemplate("Some(%s)" % template, "None", @@ -2188,7 +2188,7 @@ class CGGeneric(CGThing): class CGCallbackTempRoot(CGGeneric): def __init__(self, name): - CGGeneric.__init__(self, "%s::new(${val}.get().to_object())" % name) + CGGeneric.__init__(self, "%s::new(cx, ${val}.get().to_object())" % name) def getAllTypes(descriptors, dictionaries, callbacks, typedefs): @@ -4437,10 +4437,11 @@ class ClassConstructor(ClassItem): "});\n" "// Note: callback cannot be moved after calling init.\n" "match Rc::get_mut(&mut ret) {\n" - " Some(ref mut callback) => callback.parent.init(%s),\n" + " Some(ref mut callback) => unsafe { callback.parent.init(%s, %s) },\n" " None => unreachable!(),\n" "};\n" - "ret") % (cgClass.name, '\n'.join(initializers), self.args[0].name)) + "ret") % (cgClass.name, '\n'.join(initializers), + self.args[0].name, self.args[1].name)) def declare(self, cgClass): args = ', '.join([a.declare() for a in self.args]) @@ -6229,11 +6230,11 @@ class CGCallback(CGClass): bases=[ClassBase(baseName)], constructors=self.getConstructors(), methods=realMethods + getters + setters, - decorators="#[derive(JSTraceable, PartialEq)]") + decorators="#[derive(JSTraceable, PartialEq)]\n#[allow_unrooted_interior]") def getConstructors(self): return [ClassConstructor( - [Argument("*mut JSObject", "aCallback")], + [Argument("*mut JSContext", "aCx"), Argument("*mut JSObject", "aCallback")], bodyInHeader=True, visibility="pub", explicit=False, @@ -6329,8 +6330,8 @@ class CGCallbackFunctionImpl(CGGeneric): def __init__(self, callback): impl = string.Template("""\ impl CallbackContainer for ${type} { - fn new(callback: *mut JSObject) -> Rc<${type}> { - ${type}::new(callback) + unsafe fn new(cx: *mut JSContext, callback: *mut JSObject) -> Rc<${type}> { + ${type}::new(cx, callback) } fn callback_holder(&self) -> &CallbackObject { |