mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Split global logic out of CGWrapMethod
This commit is contained in:
parent
fa17814f12
commit
32a600246e
1 changed files with 40 additions and 25 deletions
|
@ -2375,9 +2375,9 @@ class CGConstructorEnabled(CGAbstractMethod):
|
||||||
|
|
||||||
|
|
||||||
def CreateBindingJSObject(descriptor, parent=None):
|
def CreateBindingJSObject(descriptor, parent=None):
|
||||||
|
assert not descriptor.isGlobal()
|
||||||
create = "let raw = Box::into_raw(object);\nlet _rt = RootedTraceable::new(&*raw);\n"
|
create = "let raw = Box::into_raw(object);\nlet _rt = RootedTraceable::new(&*raw);\n"
|
||||||
if descriptor.proxy:
|
if descriptor.proxy:
|
||||||
assert not descriptor.isGlobal()
|
|
||||||
create += """
|
create += """
|
||||||
let handler = RegisterBindings::proxy_handlers[PrototypeList::Proxies::%s as usize];
|
let handler = RegisterBindings::proxy_handlers[PrototypeList::Proxies::%s as usize];
|
||||||
rooted!(in(cx) let private = PrivateValue(raw as *const libc::c_void));
|
rooted!(in(cx) let private = PrivateValue(raw as *const libc::c_void));
|
||||||
|
@ -2388,15 +2388,6 @@ let obj = NewProxyObject(cx, handler,
|
||||||
assert!(!obj.is_null());
|
assert!(!obj.is_null());
|
||||||
rooted!(in(cx) let obj = obj);\
|
rooted!(in(cx) let obj = obj);\
|
||||||
""" % (descriptor.name, parent)
|
""" % (descriptor.name, parent)
|
||||||
elif descriptor.isGlobal():
|
|
||||||
create += ("rooted!(in(cx) let obj =\n"
|
|
||||||
" create_dom_global(\n"
|
|
||||||
" cx,\n"
|
|
||||||
" &Class.base as *const js::jsapi::Class as *const JSClass,\n"
|
|
||||||
" raw as *const libc::c_void,\n"
|
|
||||||
" Some(%s))\n"
|
|
||||||
");\n"
|
|
||||||
"assert!(!obj.is_null());" % TRACE_HOOK_NAME)
|
|
||||||
else:
|
else:
|
||||||
create += ("rooted!(in(cx) let obj = JS_NewObjectWithGivenProto(\n"
|
create += ("rooted!(in(cx) let obj = JS_NewObjectWithGivenProto(\n"
|
||||||
" cx, &Class.base as *const js::jsapi::Class as *const JSClass, proto.handle()));\n"
|
" cx, &Class.base as *const js::jsapi::Class as *const JSClass, proto.handle()));\n"
|
||||||
|
@ -2475,21 +2466,17 @@ class CGWrapMethod(CGAbstractMethod):
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
assert not descriptor.interface.isCallback()
|
assert not descriptor.interface.isCallback()
|
||||||
if not descriptor.isGlobal():
|
assert not descriptor.isGlobal()
|
||||||
args = [Argument('*mut JSContext', 'cx'), Argument('GlobalRef', 'scope'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('GlobalRef', 'scope'),
|
||||||
Argument("Box<%s>" % descriptor.concreteType, 'object')]
|
Argument("Box<%s>" % descriptor.concreteType, 'object')]
|
||||||
else:
|
|
||||||
args = [Argument('*mut JSContext', 'cx'),
|
|
||||||
Argument("Box<%s>" % descriptor.concreteType, 'object')]
|
|
||||||
retval = 'Root<%s>' % descriptor.concreteType
|
retval = 'Root<%s>' % descriptor.concreteType
|
||||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args,
|
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args,
|
||||||
pub=True, unsafe=True)
|
pub=True, unsafe=True)
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
unforgeable = CopyUnforgeablePropertiesToInstance(self.descriptor)
|
unforgeable = CopyUnforgeablePropertiesToInstance(self.descriptor)
|
||||||
if not self.descriptor.isGlobal():
|
create = CreateBindingJSObject(self.descriptor, "scope")
|
||||||
create = CreateBindingJSObject(self.descriptor, "scope")
|
return CGGeneric("""\
|
||||||
return CGGeneric("""\
|
|
||||||
let scope = scope.reflector().get_jsobject();
|
let scope = scope.reflector().get_jsobject();
|
||||||
assert!(!scope.get().is_null());
|
assert!(!scope.get().is_null());
|
||||||
assert!(((*JS_GetClass(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
|
assert!(((*JS_GetClass(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
|
||||||
|
@ -2505,10 +2492,35 @@ assert!(!proto.is_null());
|
||||||
(*raw).init_reflector(obj.get());
|
(*raw).init_reflector(obj.get());
|
||||||
|
|
||||||
Root::from_ref(&*raw)""" % {'copyUnforgeable': unforgeable, 'createObject': create})
|
Root::from_ref(&*raw)""" % {'copyUnforgeable': unforgeable, 'createObject': create})
|
||||||
else:
|
|
||||||
create = CreateBindingJSObject(self.descriptor)
|
|
||||||
return CGGeneric("""\
|
class CGWrapGlobalMethod(CGAbstractMethod):
|
||||||
%(createObject)s
|
"""
|
||||||
|
Class that generates the FooBinding::Wrap function for global interfaces.
|
||||||
|
"""
|
||||||
|
def __init__(self, descriptor):
|
||||||
|
assert not descriptor.interface.isCallback()
|
||||||
|
assert descriptor.isGlobal()
|
||||||
|
args = [Argument('*mut JSContext', 'cx'),
|
||||||
|
Argument("Box<%s>" % descriptor.concreteType, 'object')]
|
||||||
|
retval = 'Root<%s>' % descriptor.concreteType
|
||||||
|
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args,
|
||||||
|
pub=True, unsafe=True)
|
||||||
|
|
||||||
|
def definition_body(self):
|
||||||
|
unforgeable = CopyUnforgeablePropertiesToInstance(self.descriptor)
|
||||||
|
return CGGeneric("""\
|
||||||
|
let raw = Box::into_raw(object);
|
||||||
|
let _rt = RootedTraceable::new(&*raw);
|
||||||
|
|
||||||
|
rooted!(in(cx) let obj =
|
||||||
|
create_dom_global(
|
||||||
|
cx,
|
||||||
|
&Class.base as *const js::jsapi::Class as *const _,
|
||||||
|
raw as *const libc::c_void,
|
||||||
|
Some(_trace)));
|
||||||
|
assert!(!obj.is_null());
|
||||||
|
|
||||||
(*raw).init_reflector(obj.get());
|
(*raw).init_reflector(obj.get());
|
||||||
|
|
||||||
let _ac = JSAutoCompartment::new(cx, obj.get());
|
let _ac = JSAutoCompartment::new(cx, obj.get());
|
||||||
|
@ -2519,7 +2531,7 @@ JS_SplicePrototype(cx, obj.handle(), proto.handle());
|
||||||
%(copyUnforgeable)s
|
%(copyUnforgeable)s
|
||||||
|
|
||||||
Root::from_ref(&*raw)\
|
Root::from_ref(&*raw)\
|
||||||
""" % {'copyUnforgeable': unforgeable, 'createObject': create})
|
""" % {'copyUnforgeable': unforgeable})
|
||||||
|
|
||||||
|
|
||||||
class CGIDLInterface(CGThing):
|
class CGIDLInterface(CGThing):
|
||||||
|
@ -5466,7 +5478,10 @@ class CGDescriptor(CGThing):
|
||||||
cgThings.append(CGDOMJSClass(descriptor))
|
cgThings.append(CGDOMJSClass(descriptor))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
cgThings.append(CGWrapMethod(descriptor))
|
if descriptor.isGlobal():
|
||||||
|
cgThings.append(CGWrapGlobalMethod(descriptor))
|
||||||
|
else:
|
||||||
|
cgThings.append(CGWrapMethod(descriptor))
|
||||||
reexports.append('Wrap')
|
reexports.append('Wrap')
|
||||||
|
|
||||||
haveUnscopables = False
|
haveUnscopables = False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue