mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +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 = {
|
DOMInterfaces = {
|
||||||
|
|
||||||
'DedicatedWorkerGlobalScope': {
|
|
||||||
'createGlobal': True,
|
|
||||||
},
|
|
||||||
'EventListener': {
|
'EventListener': {
|
||||||
'nativeType': 'EventListenerBinding::EventListener',
|
'nativeType': 'EventListenerBinding::EventListener',
|
||||||
},
|
},
|
||||||
'Window': {
|
'Window': {
|
||||||
'createGlobal': True,
|
|
||||||
'outerObjectHook': 'Some(bindings::utils::outerize_global)',
|
'outerObjectHook': 'Some(bindings::utils::outerize_global)',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1399,7 +1399,7 @@ class CGDOMJSClass(CGThing):
|
||||||
|
|
||||||
def define(self):
|
def define(self):
|
||||||
traceHook = "Some(%s)" % TRACE_HOOK_NAME
|
traceHook = "Some(%s)" % TRACE_HOOK_NAME
|
||||||
if self.descriptor.createGlobal:
|
if self.descriptor.isGlobal():
|
||||||
flags = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL"
|
flags = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL"
|
||||||
slots = "JSCLASS_GLOBAL_SLOT_COUNT + 1"
|
slots = "JSCLASS_GLOBAL_SLOT_COUNT + 1"
|
||||||
else:
|
else:
|
||||||
|
@ -1759,7 +1759,7 @@ class CGAbstractMethod(CGThing):
|
||||||
def CreateBindingJSObject(descriptor, parent=None):
|
def CreateBindingJSObject(descriptor, parent=None):
|
||||||
create = "let mut raw: JS<%s> = JS::from_raw(&*aObject);\n" % descriptor.concreteType
|
create = "let mut raw: JS<%s> = JS::from_raw(&*aObject);\n" % descriptor.concreteType
|
||||||
if descriptor.proxy:
|
if descriptor.proxy:
|
||||||
assert not descriptor.createGlobal
|
assert not descriptor.isGlobal()
|
||||||
create += """
|
create += """
|
||||||
let handler = RegisterBindings::proxy_handlers[PrototypeList::proxies::%s as uint];
|
let handler = RegisterBindings::proxy_handlers[PrototypeList::proxies::%s as uint];
|
||||||
let mut private = PrivateValue(squirrel_away_unique(aObject) as *const libc::c_void);
|
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)
|
""" % (descriptor.name, parent)
|
||||||
else:
|
else:
|
||||||
if descriptor.createGlobal:
|
if descriptor.isGlobal():
|
||||||
create += "let obj = CreateDOMGlobal(aCx, &Class.base as *const js::Class as *const JSClass);\n"
|
create += "let obj = CreateDOMGlobal(aCx, &Class.base as *const js::Class as *const JSClass);\n"
|
||||||
else:
|
else:
|
||||||
create += ("let obj = with_compartment(aCx, proto, || {\n"
|
create += ("let obj = with_compartment(aCx, proto, || {\n"
|
||||||
|
@ -1793,7 +1793,7 @@ class CGWrapMethod(CGAbstractMethod):
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
assert not descriptor.interface.isCallback()
|
assert not descriptor.interface.isCallback()
|
||||||
if not descriptor.createGlobal:
|
if not descriptor.isGlobal():
|
||||||
args = [Argument('*mut JSContext', 'aCx'), Argument('&GlobalRef', 'aScope'),
|
args = [Argument('*mut JSContext', 'aCx'), Argument('&GlobalRef', 'aScope'),
|
||||||
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
||||||
else:
|
else:
|
||||||
|
@ -1803,7 +1803,7 @@ class CGWrapMethod(CGAbstractMethod):
|
||||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True)
|
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True)
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
if not self.descriptor.createGlobal:
|
if not self.descriptor.isGlobal():
|
||||||
return CGGeneric("""\
|
return CGGeneric("""\
|
||||||
let scope = aScope.reflector().get_jsobject();
|
let scope = aScope.reflector().get_jsobject();
|
||||||
assert!(scope.is_not_null());
|
assert!(scope.is_not_null());
|
||||||
|
|
|
@ -155,7 +155,6 @@ class Descriptor(DescriptorProvider):
|
||||||
self.memberType = "Root<'a, 'b, %s>" % ifaceName
|
self.memberType = "Root<'a, 'b, %s>" % ifaceName
|
||||||
self.nativeType = desc.get('nativeType', 'JS<%s>' % ifaceName)
|
self.nativeType = desc.get('nativeType', 'JS<%s>' % ifaceName)
|
||||||
self.concreteType = desc.get('concreteType', ifaceName)
|
self.concreteType = desc.get('concreteType', ifaceName)
|
||||||
self.createGlobal = desc.get('createGlobal', False)
|
|
||||||
self.register = desc.get('register', True)
|
self.register = desc.get('register', True)
|
||||||
self.outerObjectHook = desc.get('outerObjectHook', 'None')
|
self.outerObjectHook = desc.get('outerObjectHook', 'None')
|
||||||
|
|
||||||
|
@ -281,6 +280,15 @@ class Descriptor(DescriptorProvider):
|
||||||
maybeAppendInfallibleToAttrs(attrs, throws)
|
maybeAppendInfallibleToAttrs(attrs, throws)
|
||||||
return attrs
|
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
|
# Some utility methods
|
||||||
def getTypesFromDescriptor(descriptor):
|
def getTypesFromDescriptor(descriptor):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
// http://www.whatwg.org/html/#window
|
// http://www.whatwg.org/html/#window
|
||||||
//[PrimaryGlobal]
|
[PrimaryGlobal]
|
||||||
/*sealed*/ interface Window : EventTarget {
|
/*sealed*/ interface Window : EventTarget {
|
||||||
// the current browsing context
|
// the current browsing context
|
||||||
//[Unforgeable] readonly attribute WindowProxy window;
|
//[Unforgeable] readonly attribute WindowProxy window;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue