diff options
author | bors-servo <release+servo@mozilla.com> | 2014-03-19 19:01:48 -0400 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2014-03-19 19:01:48 -0400 |
commit | 7f188500a12373677c7ef9feb999276c30f1068a (patch) | |
tree | 3dceb32bd373a305f494160c037700cbd5b03956 /src/components/script/dom/bindings/codegen/CodegenRust.py | |
parent | 26f9543e60414d5ff3890d36c5370d0804c2cf18 (diff) | |
parent | 4ad3b6ccd160107d96df4d6925a8241403f2242a (diff) | |
download | servo-7f188500a12373677c7ef9feb999276c30f1068a.tar.gz servo-7f188500a12373677c7ef9feb999276c30f1068a.zip |
auto merge of #1915 : Ms2ger/servo/wrap-return-js, r=jdm
This lets us avoid the sketchy tricks in JS::new and Window::new, where we
kept an unsafe pointer to the native object across the Wrap call that
consumed the owned pointer.
Diffstat (limited to 'src/components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | src/components/script/dom/bindings/codegen/CodegenRust.py | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 305a53a8096..cb9dd703604 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -2060,7 +2060,7 @@ def DOMObjectPointerArg(descriptor): return DOMObjectPointerType(descriptor) + descriptor.concreteType def CreateBindingJSObject(descriptor, parent=None): - create = " let raw: *mut %s = &mut *aObject;\n" % descriptor.concreteType; + create = " let mut raw: JS<%s> = JS::from_raw(&mut *aObject);\n" % descriptor.concreteType if descriptor.proxy: assert not descriptor.createGlobal handler = """ @@ -2071,9 +2071,7 @@ def CreateBindingJSObject(descriptor, parent=None): &PrivateValue(squirrel_away_unboxed(aObject) as *libc::c_void), proto, %s, ptr::null(), ptr::null()); - if obj.is_null() { - return ptr::null(); - } + assert!(obj.is_not_null()); """ % (parent) else: @@ -2081,9 +2079,7 @@ def CreateBindingJSObject(descriptor, parent=None): create += " let obj = CreateDOMGlobal(aCx, &Class.base);\n" else: create += " let obj = JS_NewObject(aCx, &Class.base, proto, %s);\n" % parent - create += """ if obj.is_null() { - return ptr::null(); - } + create += """ assert!(obj.is_not_null()); JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32, PrivateValue(squirrel_away_unboxed(aObject) as *libc::c_void)); @@ -2099,7 +2095,8 @@ class CGWrapMethod(CGAbstractMethod): else: args = [Argument('*JSContext', 'aCx'), Argument(DOMObjectPointerArg(descriptor), 'aObject', mutable=True)] - CGAbstractMethod.__init__(self, descriptor, 'Wrap', '*JSObject', args, pub=True) + retval = 'JS<%s>' % descriptor.concreteType + CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True) def definition_body(self): if not self.descriptor.createGlobal: @@ -2110,22 +2107,20 @@ class CGWrapMethod(CGAbstractMethod): //JSAutoCompartment ac(aCx, scope); let proto = GetProtoObject(aCx, scope, scope); - if proto.is_null() { - return ptr::null(); - } + assert!(proto.is_not_null()); %s - (*raw).mut_reflector().set_jsobject(obj); + raw.mut_reflector().set_jsobject(obj); - return obj;""" % CreateBindingJSObject(self.descriptor, "scope") + return raw;""" % CreateBindingJSObject(self.descriptor, "scope") else: return """ %s let proto = GetProtoObject(aCx, obj, obj); JS_SetPrototype(aCx, obj, proto); - (*raw).mut_reflector().set_jsobject(obj); - return obj;""" % CreateBindingJSObject(self.descriptor) + raw.mut_reflector().set_jsobject(obj); + return raw;""" % CreateBindingJSObject(self.descriptor) class CGAbstractExternMethod(CGAbstractMethod): """ |