mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Merge pull request #3122 from Ms2ger/globals
Use extended attributes to define which interfaces are globals (fixes #1053); r=Manishearth
This commit is contained in:
commit
859e929a33
4 changed files with 15 additions and 11 deletions
|
@ -15,14 +15,10 @@
|
|||
|
||||
DOMInterfaces = {
|
||||
|
||||
'DedicatedWorkerGlobalScope': {
|
||||
'createGlobal': True,
|
||||
},
|
||||
'EventListener': {
|
||||
'nativeType': 'EventListenerBinding::EventListener',
|
||||
},
|
||||
'Window': {
|
||||
'createGlobal': True,
|
||||
'outerObjectHook': 'Some(bindings::utils::outerize_global)',
|
||||
},
|
||||
|
||||
|
|
|
@ -1399,7 +1399,7 @@ class CGDOMJSClass(CGThing):
|
|||
|
||||
def define(self):
|
||||
traceHook = "Some(%s)" % TRACE_HOOK_NAME
|
||||
if self.descriptor.createGlobal:
|
||||
if self.descriptor.isGlobal():
|
||||
flags = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL"
|
||||
slots = "JSCLASS_GLOBAL_SLOT_COUNT + 1"
|
||||
else:
|
||||
|
@ -1759,7 +1759,7 @@ class CGAbstractMethod(CGThing):
|
|||
def CreateBindingJSObject(descriptor, parent=None):
|
||||
create = "let mut raw: JS<%s> = JS::from_raw(&*aObject);\n" % descriptor.concreteType
|
||||
if descriptor.proxy:
|
||||
assert not descriptor.createGlobal
|
||||
assert not descriptor.isGlobal()
|
||||
create += """
|
||||
let handler = RegisterBindings::proxy_handlers[PrototypeList::proxies::%s as uint];
|
||||
let mut private = PrivateValue(squirrel_away_unique(aObject) as *const libc::c_void);
|
||||
|
@ -1773,7 +1773,7 @@ assert!(obj.is_not_null());
|
|||
|
||||
""" % (descriptor.name, parent)
|
||||
else:
|
||||
if descriptor.createGlobal:
|
||||
if descriptor.isGlobal():
|
||||
create += "let obj = CreateDOMGlobal(aCx, &Class.base as *const js::Class as *const JSClass);\n"
|
||||
else:
|
||||
create += ("let obj = with_compartment(aCx, proto, || {\n"
|
||||
|
@ -1793,7 +1793,7 @@ class CGWrapMethod(CGAbstractMethod):
|
|||
"""
|
||||
def __init__(self, descriptor):
|
||||
assert not descriptor.interface.isCallback()
|
||||
if not descriptor.createGlobal:
|
||||
if not descriptor.isGlobal():
|
||||
args = [Argument('*mut JSContext', 'aCx'), Argument('&GlobalRef', 'aScope'),
|
||||
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
||||
else:
|
||||
|
@ -1803,7 +1803,7 @@ class CGWrapMethod(CGAbstractMethod):
|
|||
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True)
|
||||
|
||||
def definition_body(self):
|
||||
if not self.descriptor.createGlobal:
|
||||
if not self.descriptor.isGlobal():
|
||||
return CGGeneric("""\
|
||||
let scope = aScope.reflector().get_jsobject();
|
||||
assert!(scope.is_not_null());
|
||||
|
|
|
@ -155,7 +155,6 @@ class Descriptor(DescriptorProvider):
|
|||
self.memberType = "Root<'a, 'b, %s>" % ifaceName
|
||||
self.nativeType = desc.get('nativeType', 'JS<%s>' % ifaceName)
|
||||
self.concreteType = desc.get('concreteType', ifaceName)
|
||||
self.createGlobal = desc.get('createGlobal', False)
|
||||
self.register = desc.get('register', True)
|
||||
self.outerObjectHook = desc.get('outerObjectHook', 'None')
|
||||
|
||||
|
@ -281,6 +280,15 @@ class Descriptor(DescriptorProvider):
|
|||
maybeAppendInfallibleToAttrs(attrs, throws)
|
||||
return attrs
|
||||
|
||||
def isGlobal(self):
|
||||
"""
|
||||
Returns true if this is the primary interface for a global object
|
||||
of some sort.
|
||||
"""
|
||||
return (self.interface.getExtendedAttribute("Global") or
|
||||
self.interface.getExtendedAttribute("PrimaryGlobal"))
|
||||
|
||||
|
||||
# Some utility methods
|
||||
def getTypesFromDescriptor(descriptor):
|
||||
"""
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// http://www.whatwg.org/html/#window
|
||||
//[PrimaryGlobal]
|
||||
[PrimaryGlobal]
|
||||
/*sealed*/ interface Window : EventTarget {
|
||||
// the current browsing context
|
||||
//[Unforgeable] readonly attribute WindowProxy window;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue