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.
This commit is contained in:
bors-servo 2014-03-19 19:01:48 -04:00
commit 7f188500a1
6 changed files with 30 additions and 43 deletions

View file

@ -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):
"""