Replace hasInterfacePrototypeObject checks by isCallback checks in codegen.

Checking for callbacks directly makes it a lot clearer what's going on, and we
don't intend to take hasConcreteDescendant into consideration.

See also <https://bugzilla.mozilla.org/show_bug.cgi?id=1026720>.
This commit is contained in:
Ms2ger 2014-08-18 22:45:58 +02:00
parent 3f17a49564
commit ea3c2c243c
2 changed files with 48 additions and 63 deletions

View file

@ -1788,7 +1788,7 @@ JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32,
class CGWrapMethod(CGAbstractMethod): class CGWrapMethod(CGAbstractMethod):
def __init__(self, descriptor): def __init__(self, descriptor):
assert descriptor.interface.hasInterfacePrototypeObject() assert not descriptor.interface.isCallback()
if not descriptor.createGlobal: if not descriptor.createGlobal:
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)]
@ -1920,6 +1920,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
properties should be a PropertyArrays instance. properties should be a PropertyArrays instance.
""" """
def __init__(self, descriptor, properties): def __init__(self, descriptor, properties):
assert not descriptor.interface.isCallback()
args = [Argument('*mut JSContext', 'aCx'), Argument('*mut JSObject', 'aGlobal'), args = [Argument('*mut JSContext', 'aCx'), Argument('*mut JSObject', 'aGlobal'),
Argument('*mut JSObject', 'aReceiver')] Argument('*mut JSObject', 'aReceiver')]
CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', '*mut JSObject', args) CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', '*mut JSObject', args)
@ -1933,12 +1934,6 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
getParentProto = ("%s::GetProtoObject(aCx, aGlobal, aReceiver)" % getParentProto = ("%s::GetProtoObject(aCx, aGlobal, aReceiver)" %
toBindingNamespace(parentProtoName)) toBindingNamespace(parentProtoName))
needInterfaceObject = self.descriptor.interface.hasInterfaceObject()
needInterfacePrototypeObject = self.descriptor.interface.hasInterfacePrototypeObject()
# if we don't need to create anything, why are we generating this?
assert needInterfaceObject or needInterfacePrototypeObject
getParentProto = ("let parentProto: *mut JSObject = %s;\n" getParentProto = ("let parentProto: *mut JSObject = %s;\n"
"assert!(parentProto.is_not_null());\n") % getParentProto "assert!(parentProto.is_not_null());\n") % getParentProto
@ -1950,7 +1945,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
else: else:
domClass = "ptr::null()" domClass = "ptr::null()"
if needInterfaceObject: if self.descriptor.interface.hasInterfaceObject():
if self.descriptor.interface.ctor(): if self.descriptor.interface.ctor():
constructHook = CONSTRUCT_HOOK_NAME constructHook = CONSTRUCT_HOOK_NAME
constructArgs = methodLength(self.descriptor.interface.ctor()) constructArgs = methodLength(self.descriptor.interface.ctor())
@ -4049,62 +4044,60 @@ class CGDescriptor(CGThing):
def __init__(self, descriptor): def __init__(self, descriptor):
CGThing.__init__(self) CGThing.__init__(self)
assert not descriptor.concrete or descriptor.interface.hasInterfacePrototypeObject() assert not descriptor.interface.isCallback()
cgThings = [] cgThings = []
if descriptor.interface.hasInterfacePrototypeObject(): cgThings.append(CGGetProtoObjectMethod(descriptor))
cgThings.append(CGGetProtoObjectMethod(descriptor))
if descriptor.interface.hasInterfaceObject(): if descriptor.interface.hasInterfaceObject():
# https://github.com/mozilla/servo/issues/2665 # https://github.com/mozilla/servo/issues/2665
# cgThings.append(CGGetConstructorObjectMethod(descriptor)) # cgThings.append(CGGetConstructorObjectMethod(descriptor))
pass pass
if descriptor.interface.hasInterfacePrototypeObject(): (hasMethod, hasGetter, hasLenientGetter,
(hasMethod, hasGetter, hasLenientGetter, hasSetter, hasLenientSetter) = False, False, False, False, False
hasSetter, hasLenientSetter) = False, False, False, False, False for m in descriptor.interface.members:
for m in descriptor.interface.members: if m.isMethod() and not m.isIdentifierLess():
if m.isMethod() and not m.isIdentifierLess(): if m.isStatic():
assert descriptor.interface.hasInterfaceObject()
cgThings.append(CGStaticMethod(descriptor, m))
else:
cgThings.append(CGSpecializedMethod(descriptor, m))
cgThings.append(CGMemberJITInfo(descriptor, m))
hasMethod = True
elif m.isAttr():
if m.isStatic():
assert descriptor.interface.hasInterfaceObject()
cgThings.append(CGStaticGetter(descriptor, m))
else:
cgThings.append(CGSpecializedGetter(descriptor, m))
if m.hasLenientThis():
hasLenientGetter = True
else:
hasGetter = True
if not m.readonly:
if m.isStatic(): if m.isStatic():
assert descriptor.interface.hasInterfaceObject() assert descriptor.interface.hasInterfaceObject()
cgThings.append(CGStaticMethod(descriptor, m)) cgThings.append(CGStaticSetter(descriptor, m))
elif descriptor.interface.hasInterfacePrototypeObject(): else:
cgThings.append(CGSpecializedMethod(descriptor, m)) cgThings.append(CGSpecializedSetter(descriptor, m))
cgThings.append(CGMemberJITInfo(descriptor, m))
hasMethod = True
elif m.isAttr():
if m.isStatic():
assert descriptor.interface.hasInterfaceObject()
cgThings.append(CGStaticGetter(descriptor, m))
elif descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGSpecializedGetter(descriptor, m))
if m.hasLenientThis(): if m.hasLenientThis():
hasLenientGetter = True hasLenientSetter = True
else: else:
hasGetter = True hasSetter = True
if not m.readonly: if not m.isStatic():
if m.isStatic(): cgThings.append(CGMemberJITInfo(descriptor, m))
assert descriptor.interface.hasInterfaceObject() if hasMethod:
cgThings.append(CGStaticSetter(descriptor, m)) cgThings.append(CGGenericMethod(descriptor))
elif descriptor.interface.hasInterfacePrototypeObject(): if hasGetter:
cgThings.append(CGSpecializedSetter(descriptor, m)) cgThings.append(CGGenericGetter(descriptor))
if m.hasLenientThis(): if hasLenientGetter:
hasLenientSetter = True pass
else: if hasSetter:
hasSetter = True cgThings.append(CGGenericSetter(descriptor))
if hasLenientSetter:
if not m.isStatic() and descriptor.interface.hasInterfacePrototypeObject(): pass
cgThings.append(CGMemberJITInfo(descriptor, m))
if hasMethod:
cgThings.append(CGGenericMethod(descriptor))
if hasGetter:
cgThings.append(CGGenericGetter(descriptor))
if hasLenientGetter:
pass
if hasSetter:
cgThings.append(CGGenericSetter(descriptor))
if hasLenientSetter:
pass
if descriptor.concrete: if descriptor.concrete:
cgThings.append(CGClassFinalizeHook(descriptor)) cgThings.append(CGClassFinalizeHook(descriptor))
@ -4114,8 +4107,7 @@ class CGDescriptor(CGThing):
cgThings.append(CGClassConstructHook(descriptor)) cgThings.append(CGClassConstructHook(descriptor))
cgThings.append(CGInterfaceObjectJSClass(descriptor)) cgThings.append(CGInterfaceObjectJSClass(descriptor))
if descriptor.interface.hasInterfacePrototypeObject(): cgThings.append(CGPrototypeJSClass(descriptor))
cgThings.append(CGPrototypeJSClass(descriptor))
properties = PropertyArrays(descriptor) properties = PropertyArrays(descriptor)
cgThings.append(CGGeneric(str(properties))) cgThings.append(CGGeneric(str(properties)))
@ -4415,7 +4407,7 @@ class CGBindingRoot(CGThing):
""" """
def __init__(self, config, prefix, webIDLFile): def __init__(self, config, prefix, webIDLFile):
descriptors = config.getDescriptors(webIDLFile=webIDLFile, descriptors = config.getDescriptors(webIDLFile=webIDLFile,
hasInterfaceOrInterfacePrototypeObject=True) isCallback=False)
dictionaries = config.getDictionaries(webIDLFile=webIDLFile) dictionaries = config.getDictionaries(webIDLFile=webIDLFile)
cgthings = [] cgthings = []
@ -5383,7 +5375,7 @@ class GlobalGenRoots():
@staticmethod @staticmethod
def PrototypeList(config): def PrototypeList(config):
# Prototype ID enum. # Prototype ID enum.
protos = [d.name for d in config.getDescriptors(hasInterfacePrototypeObject=True)] protos = [d.name for d in config.getDescriptors(isCallback=False)]
proxies = [d.name for d in config.getDescriptors(proxy=True)] proxies = [d.name for d in config.getDescriptors(proxy=True)]
return CGList([ return CGList([

View file

@ -72,10 +72,6 @@ class Configuration:
getter = lambda x: x.interface.filename() getter = lambda x: x.interface.filename()
elif key == 'hasInterfaceObject': elif key == 'hasInterfaceObject':
getter = lambda x: x.interface.hasInterfaceObject() getter = lambda x: x.interface.hasInterfaceObject()
elif key == 'hasInterfacePrototypeObject':
getter = lambda x: x.interface.hasInterfacePrototypeObject()
elif key == 'hasInterfaceOrInterfacePrototypeObject':
getter = lambda x: x.hasInterfaceOrInterfacePrototypeObject()
elif key == 'isCallback': elif key == 'isCallback':
getter = lambda x: x.interface.isCallback() getter = lambda x: x.interface.isCallback()
elif key == 'isJSImplemented': elif key == 'isJSImplemented':
@ -258,9 +254,6 @@ class Descriptor(DescriptorProvider):
config.maxProtoChainLength = max(config.maxProtoChainLength, config.maxProtoChainLength = max(config.maxProtoChainLength,
len(self.prototypeChain)) len(self.prototypeChain))
def hasInterfaceOrInterfacePrototypeObject(self):
return self.interface.hasInterfaceObject() or self.interface.hasInterfacePrototypeObject()
def getExtendedAttributes(self, member, getter=False, setter=False): def getExtendedAttributes(self, member, getter=False, setter=False):
def maybeAppendInfallibleToAttrs(attrs, throws): def maybeAppendInfallibleToAttrs(attrs, throws):
if throws is None: if throws is None: