2012-03-31 08:42:20 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2012-10-01 16:56:31 +04:00
|
|
|
from WebIDL import IDLInterface, IDLExternalInterface
|
2013-01-28 17:34:31 +04:00
|
|
|
import os
|
2012-10-01 16:56:31 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
autogenerated_comment = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n"
|
|
|
|
|
|
|
|
class Configuration:
|
|
|
|
"""
|
|
|
|
Represents global configuration state based on IDL parse data and
|
|
|
|
the configuration file.
|
|
|
|
"""
|
|
|
|
def __init__(self, filename, parseData):
|
|
|
|
|
|
|
|
# Read the configuration file.
|
|
|
|
glbl = {}
|
|
|
|
execfile(filename, glbl)
|
|
|
|
config = glbl['DOMInterfaces']
|
|
|
|
|
|
|
|
# Build descriptors for all the interfaces we have in the parse data.
|
|
|
|
# This allows callers to specify a subset of interfaces by filtering
|
|
|
|
# |parseData|.
|
|
|
|
self.descriptors = []
|
|
|
|
self.interfaces = {}
|
|
|
|
self.maxProtoChainLength = 0;
|
|
|
|
for thing in parseData:
|
2012-10-01 16:56:31 +04:00
|
|
|
# Some toplevel things are sadly types, and those have an
|
|
|
|
# isInterface that doesn't mean the same thing as IDLObject's
|
|
|
|
# isInterface()...
|
|
|
|
if (not isinstance(thing, IDLInterface) and
|
|
|
|
not isinstance(thing, IDLExternalInterface)):
|
|
|
|
continue
|
2012-03-31 08:42:20 +04:00
|
|
|
iface = thing
|
|
|
|
self.interfaces[iface.identifier.name] = iface
|
2012-10-01 16:56:31 +04:00
|
|
|
if iface.identifier.name not in config:
|
|
|
|
# Completely skip consequential interfaces with no descriptor
|
2013-03-13 22:07:49 +04:00
|
|
|
# if they have no interface object because chances are we
|
|
|
|
# don't need to do anything interesting with them.
|
|
|
|
if iface.isConsequential() and not iface.hasInterfaceObject():
|
2012-10-01 16:56:31 +04:00
|
|
|
continue
|
|
|
|
entry = {}
|
|
|
|
else:
|
|
|
|
entry = config[iface.identifier.name]
|
2012-03-31 08:42:20 +04:00
|
|
|
if not isinstance(entry, list):
|
|
|
|
assert isinstance(entry, dict)
|
|
|
|
entry = [entry]
|
2013-11-01 02:28:22 +04:00
|
|
|
elif len(entry) == 1:
|
|
|
|
if entry[0].get("workers", False):
|
|
|
|
# List with only a workers descriptor means we should
|
|
|
|
# infer a mainthread descriptor. If you want only
|
|
|
|
# workers bindings, don't use a list here.
|
|
|
|
entry.append({})
|
|
|
|
else:
|
|
|
|
raise TypeError("Don't use a single-element list for "
|
|
|
|
"non-worker-only interface " + iface.identifier.name +
|
|
|
|
" in Bindings.conf")
|
|
|
|
elif len(entry) == 2:
|
|
|
|
if entry[0].get("workers", False) == entry[1].get("workers", False):
|
|
|
|
raise TypeError("The two entries for interface " + iface.identifier.name +
|
|
|
|
" in Bindings.conf should not have the same value for 'workers'")
|
|
|
|
else:
|
|
|
|
raise TypeError("Interface " + iface.identifier.name +
|
|
|
|
" should have no more than two entries in Bindings.conf")
|
2012-03-31 08:42:20 +04:00
|
|
|
self.descriptors.extend([Descriptor(self, iface, x) for x in entry])
|
|
|
|
|
2013-05-09 21:06:48 +04:00
|
|
|
# Keep the descriptor list sorted for determinism.
|
|
|
|
self.descriptors.sort(lambda x,y: cmp(x.name, y.name))
|
|
|
|
|
|
|
|
self.descriptorsByName = {}
|
|
|
|
for d in self.descriptors:
|
|
|
|
self.descriptorsByName.setdefault(d.interface.identifier.name,
|
|
|
|
[]).append(d)
|
|
|
|
|
|
|
|
self.descriptorsByFile = {}
|
|
|
|
for d in self.descriptors:
|
|
|
|
self.descriptorsByFile.setdefault(d.interface.filename(),
|
|
|
|
[]).append(d)
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
self.enums = [e for e in parseData if e.isEnum()]
|
2013-01-29 08:30:17 +04:00
|
|
|
|
|
|
|
# Figure out what our main-thread and worker dictionaries and callbacks
|
|
|
|
# are.
|
|
|
|
mainTypes = set()
|
2013-02-25 21:20:49 +04:00
|
|
|
for descriptor in ([self.getDescriptor("DummyInterface", workers=False)] +
|
|
|
|
self.getDescriptors(workers=False, isExternal=False, skipGen=False)):
|
2013-01-29 08:30:17 +04:00
|
|
|
mainTypes |= set(getFlatTypes(getTypesFromDescriptor(descriptor)))
|
|
|
|
(mainCallbacks, mainDictionaries) = findCallbacksAndDictionaries(mainTypes)
|
|
|
|
|
|
|
|
workerTypes = set();
|
2013-02-25 21:20:49 +04:00
|
|
|
for descriptor in ([self.getDescriptor("DummyInterfaceWorkers", workers=True)] +
|
|
|
|
self.getDescriptors(workers=True, isExternal=False, skipGen=False)):
|
2013-01-29 08:30:17 +04:00
|
|
|
workerTypes |= set(getFlatTypes(getTypesFromDescriptor(descriptor)))
|
|
|
|
(workerCallbacks, workerDictionaries) = findCallbacksAndDictionaries(workerTypes)
|
|
|
|
|
2012-06-12 18:22:05 +04:00
|
|
|
self.dictionaries = [d for d in parseData if d.isDictionary()]
|
2012-11-09 19:43:57 +04:00
|
|
|
self.callbacks = [c for c in parseData if
|
|
|
|
c.isCallback() and not c.isInterface()]
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-01-29 08:30:17 +04:00
|
|
|
def flagWorkerOrMainThread(items, main, worker):
|
|
|
|
for item in items:
|
|
|
|
if item in main:
|
|
|
|
item.setUserData("mainThread", True)
|
|
|
|
if item in worker:
|
|
|
|
item.setUserData("workers", True)
|
|
|
|
flagWorkerOrMainThread(self.callbacks, mainCallbacks, workerCallbacks)
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
def getInterface(self, ifname):
|
|
|
|
return self.interfaces[ifname]
|
|
|
|
def getDescriptors(self, **filters):
|
|
|
|
"""Gets the descriptors that match the given filters."""
|
|
|
|
curr = self.descriptors
|
2013-05-09 21:06:48 +04:00
|
|
|
# Collect up our filters, because we may have a webIDLFile filter that
|
|
|
|
# we always want to apply first.
|
|
|
|
tofilter = []
|
2012-03-31 08:42:20 +04:00
|
|
|
for key, val in filters.iteritems():
|
|
|
|
if key == 'webIDLFile':
|
2013-05-09 21:06:48 +04:00
|
|
|
# Special-case this part to make it fast, since most of our
|
|
|
|
# getDescriptors calls are conditioned on a webIDLFile. We may
|
|
|
|
# not have this key, in which case we have no descriptors
|
|
|
|
# either.
|
|
|
|
curr = self.descriptorsByFile.get(val, [])
|
|
|
|
continue
|
2012-03-31 08:42:20 +04:00
|
|
|
elif key == 'hasInterfaceObject':
|
|
|
|
getter = lambda x: (not x.interface.isExternal() and
|
|
|
|
x.interface.hasInterfaceObject())
|
|
|
|
elif key == 'hasInterfacePrototypeObject':
|
|
|
|
getter = lambda x: (not x.interface.isExternal() and
|
|
|
|
x.interface.hasInterfacePrototypeObject())
|
|
|
|
elif key == 'hasInterfaceOrInterfacePrototypeObject':
|
|
|
|
getter = lambda x: x.hasInterfaceOrInterfacePrototypeObject()
|
|
|
|
elif key == 'isCallback':
|
|
|
|
getter = lambda x: x.interface.isCallback()
|
|
|
|
elif key == 'isExternal':
|
|
|
|
getter = lambda x: x.interface.isExternal()
|
2013-03-19 03:05:51 +04:00
|
|
|
elif key == 'isJSImplemented':
|
|
|
|
getter = lambda x: x.interface.isJSImplemented()
|
2013-05-01 00:30:25 +04:00
|
|
|
elif key == 'isNavigatorProperty':
|
|
|
|
getter = lambda x: x.interface.getNavigatorProperty() != None
|
2012-03-31 08:42:20 +04:00
|
|
|
else:
|
2013-05-09 21:06:48 +04:00
|
|
|
# Have to watch out: just closing over "key" is not enough,
|
|
|
|
# since we're about to mutate its value
|
|
|
|
getter = (lambda attrName: lambda x: getattr(x, attrName))(key)
|
|
|
|
tofilter.append((getter, val))
|
|
|
|
for f in tofilter:
|
|
|
|
curr = filter(lambda x: f[0](x) == f[1], curr)
|
2012-03-31 08:42:20 +04:00
|
|
|
return curr
|
|
|
|
def getEnums(self, webIDLFile):
|
|
|
|
return filter(lambda e: e.filename() == webIDLFile, self.enums)
|
2013-01-29 08:30:17 +04:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _filterForFileAndWorkers(items, filters):
|
|
|
|
"""Gets the items that match the given filters."""
|
|
|
|
for key, val in filters.iteritems():
|
|
|
|
if key == 'webIDLFile':
|
|
|
|
items = filter(lambda x: x.filename() == val, items)
|
|
|
|
elif key == 'workers':
|
|
|
|
if val:
|
|
|
|
items = filter(lambda x: x.getUserData("workers", False), items)
|
|
|
|
else:
|
|
|
|
items = filter(lambda x: x.getUserData("mainThread", False), items)
|
|
|
|
else:
|
|
|
|
assert(0) # Unknown key
|
|
|
|
return items
|
|
|
|
def getDictionaries(self, **filters):
|
|
|
|
return self._filterForFileAndWorkers(self.dictionaries, filters)
|
|
|
|
def getCallbacks(self, **filters):
|
|
|
|
return self._filterForFileAndWorkers(self.callbacks, filters)
|
|
|
|
|
2012-06-19 20:09:37 +04:00
|
|
|
def getDescriptor(self, interfaceName, workers):
|
|
|
|
"""
|
|
|
|
Gets the appropriate descriptor for the given interface name
|
|
|
|
and the given workers boolean.
|
|
|
|
"""
|
2013-05-09 21:06:48 +04:00
|
|
|
for d in self.descriptorsByName[interfaceName]:
|
|
|
|
if d.workers == workers:
|
|
|
|
return d
|
2012-06-19 20:09:37 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
if workers:
|
|
|
|
for d in self.descriptorsByName[interfaceName]:
|
|
|
|
return d
|
|
|
|
|
2013-05-09 21:06:48 +04:00
|
|
|
raise NoSuchDescriptorError("For " + interfaceName + " found no matches");
|
2012-06-19 20:09:37 +04:00
|
|
|
def getDescriptorProvider(self, workers):
|
|
|
|
"""
|
|
|
|
Gets a descriptor provider that can provide descriptors as needed,
|
|
|
|
for the given workers boolean
|
|
|
|
"""
|
|
|
|
return DescriptorProvider(self, workers)
|
|
|
|
|
|
|
|
class NoSuchDescriptorError(TypeError):
|
|
|
|
def __init__(self, str):
|
|
|
|
TypeError.__init__(self, str)
|
|
|
|
|
|
|
|
class DescriptorProvider:
|
|
|
|
"""
|
|
|
|
A way of getting descriptors for interface names
|
|
|
|
"""
|
|
|
|
def __init__(self, config, workers):
|
|
|
|
self.config = config
|
|
|
|
self.workers = workers
|
|
|
|
|
|
|
|
def getDescriptor(self, interfaceName):
|
|
|
|
"""
|
|
|
|
Gets the appropriate descriptor for the given interface name given the
|
|
|
|
context of the current descriptor. This selects the appropriate
|
|
|
|
implementation for cases like workers.
|
|
|
|
"""
|
|
|
|
return self.config.getDescriptor(interfaceName, self.workers)
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-06-19 20:09:37 +04:00
|
|
|
class Descriptor(DescriptorProvider):
|
2012-03-31 08:42:20 +04:00
|
|
|
"""
|
|
|
|
Represents a single descriptor for an interface. See Bindings.conf.
|
|
|
|
"""
|
|
|
|
def __init__(self, config, interface, desc):
|
2012-06-19 20:09:37 +04:00
|
|
|
DescriptorProvider.__init__(self, config, desc.get('workers', False))
|
2012-03-31 08:42:20 +04:00
|
|
|
self.interface = interface
|
|
|
|
|
|
|
|
# Read the desc, and fill in the relevant defaults.
|
2012-08-28 21:10:09 +04:00
|
|
|
ifaceName = self.interface.identifier.name
|
2013-01-28 17:34:31 +04:00
|
|
|
if self.interface.isExternal():
|
2012-08-28 21:10:09 +04:00
|
|
|
if self.workers:
|
|
|
|
nativeTypeDefault = "JSObject"
|
|
|
|
else:
|
|
|
|
nativeTypeDefault = "nsIDOM" + ifaceName
|
2013-01-28 17:34:31 +04:00
|
|
|
elif self.interface.isCallback():
|
2013-09-10 06:10:45 +04:00
|
|
|
nativeTypeDefault = "mozilla::dom::" + ifaceName
|
2012-08-28 21:10:09 +04:00
|
|
|
else:
|
|
|
|
if self.workers:
|
|
|
|
nativeTypeDefault = "mozilla::dom::workers::" + ifaceName
|
|
|
|
else:
|
|
|
|
nativeTypeDefault = "mozilla::dom::" + ifaceName
|
|
|
|
|
|
|
|
self.nativeType = desc.get('nativeType', nativeTypeDefault)
|
2014-04-27 05:49:59 +04:00
|
|
|
# Now create a version of nativeType that doesn't have extra
|
|
|
|
# mozilla::dom:: at the beginning.
|
|
|
|
prettyNativeType = self.nativeType.split("::")
|
|
|
|
if prettyNativeType[0] == "mozilla":
|
|
|
|
prettyNativeType.pop(0)
|
|
|
|
if prettyNativeType[0] == "dom":
|
|
|
|
prettyNativeType.pop(0)
|
|
|
|
self.prettyNativeType = "::".join(prettyNativeType)
|
|
|
|
|
2013-04-04 06:22:16 +04:00
|
|
|
self.jsImplParent = desc.get('jsImplParent', self.nativeType)
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-08-28 21:10:09 +04:00
|
|
|
# Do something sane for JSObject
|
|
|
|
if self.nativeType == "JSObject":
|
2013-09-06 03:08:06 +04:00
|
|
|
headerDefault = "js/TypeDecls.h"
|
2013-03-19 03:05:51 +04:00
|
|
|
elif self.interface.isCallback() or self.interface.isJSImplemented():
|
2013-01-28 17:34:31 +04:00
|
|
|
# A copy of CGHeaders.getDeclarationFilename; we can't
|
|
|
|
# import it here, sadly.
|
|
|
|
# Use our local version of the header, not the exported one, so that
|
|
|
|
# test bindings, which don't export, will work correctly.
|
|
|
|
basename = os.path.basename(self.interface.filename())
|
|
|
|
headerDefault = basename.replace('.webidl', 'Binding.h')
|
2012-08-28 21:10:09 +04:00
|
|
|
else:
|
2012-10-01 16:45:11 +04:00
|
|
|
if self.workers:
|
|
|
|
headerDefault = "mozilla/dom/workers/bindings/%s.h" % ifaceName
|
2013-04-18 00:29:09 +04:00
|
|
|
elif not self.interface.isExternal() and self.interface.getExtendedAttribute("HeaderFile"):
|
|
|
|
headerDefault = self.interface.getExtendedAttribute("HeaderFile")[0]
|
2012-10-01 16:45:11 +04:00
|
|
|
else:
|
|
|
|
headerDefault = self.nativeType
|
|
|
|
headerDefault = headerDefault.replace("::", "/") + ".h"
|
2012-03-31 08:42:20 +04:00
|
|
|
self.headerFile = desc.get('headerFile', headerDefault)
|
2013-11-05 18:16:24 +04:00
|
|
|
self.headerIsDefault = self.headerFile == headerDefault
|
2013-04-04 06:22:16 +04:00
|
|
|
if self.jsImplParent == self.nativeType:
|
|
|
|
self.jsImplParentHeader = self.headerFile
|
|
|
|
else:
|
|
|
|
self.jsImplParentHeader = self.jsImplParent.replace("::", "/") + ".h"
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-11-05 20:58:04 +04:00
|
|
|
self.skipGen = desc.get('skipGen', False)
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
self.notflattened = desc.get('notflattened', False)
|
2012-05-23 20:44:48 +04:00
|
|
|
self.register = desc.get('register', True)
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2012-08-28 21:10:09 +04:00
|
|
|
self.hasXPConnectImpls = desc.get('hasXPConnectImpls', False)
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
# If we're concrete, we need to crawl our ancestor interfaces and mark
|
|
|
|
# them as having a concrete descendant.
|
2012-10-10 23:57:57 +04:00
|
|
|
self.concrete = (not self.interface.isExternal() and
|
|
|
|
not self.interface.isCallback() and
|
|
|
|
desc.get('concrete', True))
|
2012-10-22 21:08:52 +04:00
|
|
|
operations = {
|
|
|
|
'IndexedGetter': None,
|
|
|
|
'IndexedSetter': None,
|
|
|
|
'IndexedCreator': None,
|
|
|
|
'IndexedDeleter': None,
|
|
|
|
'NamedGetter': None,
|
|
|
|
'NamedSetter': None,
|
|
|
|
'NamedCreator': None,
|
|
|
|
'NamedDeleter': None,
|
2013-03-04 23:08:24 +04:00
|
|
|
'Stringifier': None,
|
2013-07-26 20:00:49 +04:00
|
|
|
'LegacyCaller': None,
|
|
|
|
'Jsonifier': None
|
2012-10-22 21:08:52 +04:00
|
|
|
}
|
2012-03-31 08:42:20 +04:00
|
|
|
if self.concrete:
|
2012-05-22 17:46:20 +04:00
|
|
|
self.proxy = False
|
2012-03-31 08:42:20 +04:00
|
|
|
iface = self.interface
|
2012-10-22 21:08:52 +04:00
|
|
|
def addOperation(operation, m):
|
|
|
|
if not operations[operation]:
|
|
|
|
operations[operation] = m
|
|
|
|
# Since stringifiers go on the prototype, we only need to worry
|
|
|
|
# about our own stringifier, not those of our ancestor interfaces.
|
|
|
|
for m in iface.members:
|
|
|
|
if m.isMethod() and m.isStringifier():
|
|
|
|
addOperation('Stringifier', m)
|
2013-07-26 20:00:49 +04:00
|
|
|
if m.isMethod() and m.isJsonifier():
|
|
|
|
addOperation('Jsonifier', m)
|
2013-03-04 23:08:24 +04:00
|
|
|
# Don't worry about inheriting legacycallers either: in
|
|
|
|
# practice these are on most-derived prototypes.
|
|
|
|
if m.isMethod() and m.isLegacycaller():
|
|
|
|
if not m.isIdentifierLess():
|
|
|
|
raise TypeError("We don't support legacycaller with "
|
|
|
|
"identifier.\n%s" % m.location);
|
|
|
|
if len(m.signatures()) != 1:
|
|
|
|
raise TypeError("We don't support overloaded "
|
|
|
|
"legacycaller.\n%s" % m.location)
|
|
|
|
addOperation('LegacyCaller', m)
|
2012-03-31 08:42:20 +04:00
|
|
|
while iface:
|
2012-05-22 17:46:20 +04:00
|
|
|
for m in iface.members:
|
|
|
|
if not m.isMethod():
|
|
|
|
continue
|
|
|
|
|
|
|
|
def addIndexedOrNamedOperation(operation, m):
|
|
|
|
self.proxy = True
|
|
|
|
if m.isIndexed():
|
|
|
|
operation = 'Indexed' + operation
|
|
|
|
else:
|
|
|
|
assert m.isNamed()
|
|
|
|
operation = 'Named' + operation
|
|
|
|
addOperation(operation, m)
|
2012-10-22 21:08:52 +04:00
|
|
|
|
|
|
|
if m.isGetter():
|
|
|
|
addIndexedOrNamedOperation('Getter', m)
|
|
|
|
if m.isSetter():
|
|
|
|
addIndexedOrNamedOperation('Setter', m)
|
|
|
|
if m.isCreator():
|
|
|
|
addIndexedOrNamedOperation('Creator', m)
|
|
|
|
if m.isDeleter():
|
|
|
|
addIndexedOrNamedOperation('Deleter', m)
|
2013-03-04 23:08:24 +04:00
|
|
|
if m.isLegacycaller() and iface != self.interface:
|
|
|
|
raise TypeError("We don't support legacycaller on "
|
|
|
|
"non-leaf interface %s.\n%s" %
|
|
|
|
(iface, iface.location))
|
2012-05-22 17:46:20 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
iface.setUserData('hasConcreteDescendant', True)
|
|
|
|
iface = iface.parent
|
|
|
|
|
2012-05-22 17:46:20 +04:00
|
|
|
if self.proxy:
|
2012-11-05 20:58:03 +04:00
|
|
|
if (not operations['IndexedGetter'] and
|
|
|
|
(operations['IndexedSetter'] or
|
|
|
|
operations['IndexedDeleter'] or
|
|
|
|
operations['IndexedCreator'])):
|
|
|
|
raise SyntaxError("%s supports indexed properties but does "
|
|
|
|
"not have an indexed getter.\n%s" %
|
|
|
|
(self.interface, self.interface.location))
|
|
|
|
if (not operations['NamedGetter'] and
|
|
|
|
(operations['NamedSetter'] or
|
|
|
|
operations['NamedDeleter'] or
|
|
|
|
operations['NamedCreator'])):
|
|
|
|
raise SyntaxError("%s supports named properties but does "
|
|
|
|
"not have a named getter.\n%s" %
|
|
|
|
(self.interface, self.interface.location))
|
2012-05-22 17:46:20 +04:00
|
|
|
iface = self.interface
|
|
|
|
while iface:
|
|
|
|
iface.setUserData('hasProxyDescendant', True)
|
|
|
|
iface = iface.parent
|
2012-10-22 21:08:52 +04:00
|
|
|
self.operations = operations
|
2012-05-22 17:46:20 +04:00
|
|
|
|
2013-11-28 18:03:15 +04:00
|
|
|
self.nativeOwnership = desc.get('nativeOwnership', 'refcounted')
|
|
|
|
if not self.nativeOwnership in ('owned', 'refcounted'):
|
|
|
|
raise TypeError("Descriptor for %s has unrecognized value (%s) "
|
|
|
|
"for nativeOwnership" %
|
|
|
|
(self.interface.identifier.name, self.nativeOwnership))
|
2013-09-30 08:15:37 +04:00
|
|
|
if desc.get('wantsQI', None) != None:
|
|
|
|
self._wantsQI = desc.get('wantsQI', None)
|
2012-10-10 23:57:57 +04:00
|
|
|
self.wrapperCache = (not self.interface.isCallback() and
|
2013-11-28 18:03:15 +04:00
|
|
|
(self.nativeOwnership != 'owned' and
|
|
|
|
desc.get('wrapperCache', True)))
|
2012-06-16 00:25:50 +04:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
def make_name(name):
|
|
|
|
return name + "_workers" if self.workers else name
|
|
|
|
self.name = make_name(interface.identifier.name)
|
|
|
|
|
|
|
|
# self.extendedAttributes is a dict of dicts, keyed on
|
|
|
|
# all/getterOnly/setterOnly and then on member name. Values are an
|
|
|
|
# array of extended attributes.
|
|
|
|
self.extendedAttributes = { 'all': {}, 'getterOnly': {}, 'setterOnly': {} }
|
|
|
|
|
|
|
|
def addExtendedAttribute(attribute, config):
|
|
|
|
def add(key, members, attribute):
|
|
|
|
for member in members:
|
|
|
|
self.extendedAttributes[key].setdefault(member, []).append(attribute)
|
|
|
|
|
|
|
|
if isinstance(config, dict):
|
|
|
|
for key in ['all', 'getterOnly', 'setterOnly']:
|
|
|
|
add(key, config.get(key, []), attribute)
|
|
|
|
elif isinstance(config, list):
|
|
|
|
add('all', config, attribute)
|
|
|
|
else:
|
2012-05-22 17:46:20 +04:00
|
|
|
assert isinstance(config, str)
|
|
|
|
if config == '*':
|
|
|
|
iface = self.interface
|
|
|
|
while iface:
|
|
|
|
add('all', map(lambda m: m.name, iface.members), attribute)
|
|
|
|
iface = iface.parent
|
|
|
|
else:
|
|
|
|
add('all', [config], attribute)
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-03-19 03:04:24 +04:00
|
|
|
if self.interface.isJSImplemented():
|
|
|
|
addExtendedAttribute('implicitJSContext', ['constructor'])
|
|
|
|
else:
|
|
|
|
for attribute in ['implicitJSContext', 'resultNotAddRefed']:
|
|
|
|
addExtendedAttribute(attribute, desc.get(attribute, {}))
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2014-06-03 20:20:16 +04:00
|
|
|
self._binaryNames = desc.get('binaryNames', {})
|
|
|
|
self._binaryNames.setdefault('__legacycaller', 'LegacyCall')
|
|
|
|
self._binaryNames.setdefault('__stringifier', 'Stringify')
|
2014-05-25 22:31:07 +04:00
|
|
|
|
|
|
|
if not self.interface.isExternal():
|
|
|
|
self.permissions = dict()
|
|
|
|
|
|
|
|
# Adds a permission list to this descriptor and returns the index to use.
|
|
|
|
def addPermissions(ifaceOrMember):
|
|
|
|
checkPermissions = ifaceOrMember.getExtendedAttribute("CheckPermissions")
|
|
|
|
if checkPermissions is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# It's a list of whitespace-separated strings
|
|
|
|
assert(len(checkPermissions) is 1)
|
|
|
|
assert(checkPermissions[0] is not None)
|
|
|
|
checkPermissions = checkPermissions[0]
|
|
|
|
permissionsList = checkPermissions.split()
|
|
|
|
if len(permissionsList) == 0:
|
|
|
|
raise TypeError("Need at least one permission name for CheckPermissions")
|
|
|
|
|
|
|
|
permissionsList = tuple(sorted(set(permissionsList)))
|
|
|
|
return self.permissions.setdefault(permissionsList, len(self.permissions))
|
|
|
|
|
|
|
|
self.checkPermissionsIndex = addPermissions(self.interface)
|
|
|
|
self.checkPermissionsIndicesForMembers = dict()
|
|
|
|
for m in self.interface.members:
|
|
|
|
permissionsIndex = addPermissions(m)
|
|
|
|
if permissionsIndex is not None:
|
|
|
|
self.checkPermissionsIndicesForMembers[m.identifier.name] = permissionsIndex
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
# Build the prototype chain.
|
|
|
|
self.prototypeChain = []
|
|
|
|
parent = interface
|
|
|
|
while parent:
|
2013-11-05 18:16:26 +04:00
|
|
|
self.prototypeChain.insert(0, parent.identifier.name)
|
2012-03-31 08:42:20 +04:00
|
|
|
parent = parent.parent
|
|
|
|
config.maxProtoChainLength = max(config.maxProtoChainLength,
|
|
|
|
len(self.prototypeChain))
|
|
|
|
|
2014-06-03 20:20:16 +04:00
|
|
|
def binaryNameFor(self, name):
|
|
|
|
return self._binaryNames.get(name, name)
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
def hasInterfaceOrInterfacePrototypeObject(self):
|
|
|
|
|
|
|
|
# Forward-declared interfaces don't need either interface object or
|
|
|
|
# interface prototype object as they're going to use QI (on main thread)
|
|
|
|
# or be passed as a JSObject (on worker threads).
|
|
|
|
if self.interface.isExternal():
|
|
|
|
return False
|
|
|
|
|
|
|
|
return self.interface.hasInterfaceObject() or self.interface.hasInterfacePrototypeObject()
|
|
|
|
|
|
|
|
def getExtendedAttributes(self, member, getter=False, setter=False):
|
2012-09-05 17:21:33 +04:00
|
|
|
def ensureValidThrowsExtendedAttribute(attr):
|
2012-07-14 03:29:14 +04:00
|
|
|
assert(attr is None or attr is True or len(attr) == 1)
|
|
|
|
if (attr is not None and attr is not True and
|
|
|
|
'Workers' not in attr and 'MainThread' not in attr):
|
2012-09-05 17:21:33 +04:00
|
|
|
raise TypeError("Unknown value for 'Throws': " + attr[0])
|
2012-07-14 03:29:14 +04:00
|
|
|
|
2012-09-05 17:21:33 +04:00
|
|
|
def maybeAppendInfallibleToAttrs(attrs, throws):
|
|
|
|
ensureValidThrowsExtendedAttribute(throws)
|
2012-09-05 17:21:33 +04:00
|
|
|
if (throws is None or
|
|
|
|
(throws is not True and
|
|
|
|
('Workers' not in throws or not self.workers) and
|
|
|
|
('MainThread' not in throws or self.workers))):
|
2012-07-14 03:29:14 +04:00
|
|
|
attrs.append("infallible")
|
2012-09-05 17:21:33 +04:00
|
|
|
|
|
|
|
name = member.identifier.name
|
2013-03-19 03:04:24 +04:00
|
|
|
throws = self.interface.isJSImplemented() or member.getExtendedAttribute("Throws")
|
2012-09-05 17:21:33 +04:00
|
|
|
if member.isMethod():
|
|
|
|
attrs = self.extendedAttributes['all'].get(name, [])
|
|
|
|
maybeAppendInfallibleToAttrs(attrs, throws)
|
2012-07-14 03:29:14 +04:00
|
|
|
return attrs
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
assert member.isAttr()
|
|
|
|
assert bool(getter) != bool(setter)
|
|
|
|
key = 'getterOnly' if getter else 'setterOnly'
|
2012-07-14 03:29:14 +04:00
|
|
|
attrs = self.extendedAttributes['all'].get(name, []) + self.extendedAttributes[key].get(name, [])
|
2012-09-05 17:21:33 +04:00
|
|
|
if throws is None:
|
|
|
|
throwsAttr = "GetterThrows" if getter else "SetterThrows"
|
|
|
|
throws = member.getExtendedAttribute(throwsAttr)
|
|
|
|
maybeAppendInfallibleToAttrs(attrs, throws)
|
2012-07-14 03:29:14 +04:00
|
|
|
return attrs
|
2012-11-05 20:58:03 +04:00
|
|
|
|
|
|
|
def supportsIndexedProperties(self):
|
|
|
|
return self.operations['IndexedGetter'] is not None
|
|
|
|
|
|
|
|
def supportsNamedProperties(self):
|
|
|
|
return self.operations['NamedGetter'] is not None
|
2012-12-07 00:21:18 +04:00
|
|
|
|
|
|
|
def needsConstructHookHolder(self):
|
|
|
|
assert self.interface.hasInterfaceObject()
|
2013-01-08 22:05:36 +04:00
|
|
|
return False
|
2013-01-29 08:30:17 +04:00
|
|
|
|
2013-03-13 22:07:49 +04:00
|
|
|
def needsHeaderInclude(self):
|
|
|
|
"""
|
|
|
|
An interface doesn't need a header file if it is not concrete,
|
2013-08-22 17:46:26 +04:00
|
|
|
not pref-controlled, has no prototype object, and has no
|
|
|
|
static methods or attributes.
|
2013-03-13 22:07:49 +04:00
|
|
|
"""
|
|
|
|
return (self.interface.isExternal() or self.concrete or
|
2013-08-22 17:46:26 +04:00
|
|
|
self.interface.hasInterfacePrototypeObject() or
|
|
|
|
any((m.isAttr() or m.isMethod()) and m.isStatic() for m
|
|
|
|
in self.interface.members))
|
2013-03-13 22:07:49 +04:00
|
|
|
|
2014-02-05 22:38:16 +04:00
|
|
|
def isExposedConditionally(self):
|
|
|
|
return (self.interface.getExtendedAttribute("Pref") or
|
|
|
|
self.interface.getExtendedAttribute("ChromeOnly") or
|
|
|
|
self.interface.getExtendedAttribute("Func") or
|
2014-05-25 22:31:07 +04:00
|
|
|
self.interface.getExtendedAttribute("AvailableIn") or
|
|
|
|
self.interface.getExtendedAttribute("CheckPermissions"))
|
2014-02-05 22:38:16 +04:00
|
|
|
|
2014-02-05 22:38:18 +04:00
|
|
|
def needsXrayResolveHooks(self):
|
|
|
|
"""
|
|
|
|
Generally, any interface with NeedNewResolve needs Xray
|
|
|
|
resolveOwnProperty and enumerateOwnProperties hooks. But for
|
|
|
|
the special case of plugin-loading elements, we do NOT want
|
|
|
|
those, because we don't want to instantiate plug-ins simply
|
|
|
|
due to chrome touching them and that's all those hooks do on
|
|
|
|
those elements. So we special-case those here.
|
|
|
|
"""
|
|
|
|
return (self.interface.getExtendedAttribute("NeedNewResolve") and
|
|
|
|
self.interface.identifier.name not in ["HTMLObjectElement",
|
|
|
|
"HTMLEmbedElement",
|
|
|
|
"HTMLAppletElement"])
|
|
|
|
|
2014-02-08 00:56:14 +04:00
|
|
|
def needsSpecialGenericOps(self):
|
|
|
|
"""
|
|
|
|
Returns true if this descriptor requires generic ops other than
|
|
|
|
GenericBindingMethod/GenericBindingGetter/GenericBindingSetter.
|
|
|
|
|
|
|
|
In practice we need to do this if our this value might be an XPConnect
|
|
|
|
object or if we need to coerce null/undefined to the global.
|
|
|
|
"""
|
|
|
|
return self.hasXPConnectImpls or self.interface.isOnGlobalProtoChain()
|
|
|
|
|
2013-01-29 08:30:17 +04:00
|
|
|
# Some utility methods
|
|
|
|
def getTypesFromDescriptor(descriptor):
|
|
|
|
"""
|
|
|
|
Get all argument and return types for all members of the descriptor
|
|
|
|
"""
|
|
|
|
members = [m for m in descriptor.interface.members]
|
|
|
|
if descriptor.interface.ctor():
|
|
|
|
members.append(descriptor.interface.ctor())
|
2013-04-26 03:03:05 +04:00
|
|
|
members.extend(descriptor.interface.namedConstructors)
|
2013-01-29 08:30:17 +04:00
|
|
|
signatures = [s for m in members if m.isMethod() for s in m.signatures()]
|
|
|
|
types = []
|
|
|
|
for s in signatures:
|
|
|
|
assert len(s) == 2
|
|
|
|
(returnType, arguments) = s
|
|
|
|
types.append(returnType)
|
|
|
|
types.extend(a.type for a in arguments)
|
|
|
|
|
|
|
|
types.extend(a.type for a in members if a.isAttr())
|
|
|
|
return types
|
|
|
|
|
|
|
|
def getFlatTypes(types):
|
|
|
|
retval = set()
|
|
|
|
for type in types:
|
|
|
|
type = type.unroll()
|
|
|
|
if type.isUnion():
|
|
|
|
retval |= set(type.flatMemberTypes)
|
|
|
|
else:
|
|
|
|
retval.add(type)
|
|
|
|
return retval
|
|
|
|
|
|
|
|
def getTypesFromDictionary(dictionary):
|
|
|
|
"""
|
|
|
|
Get all member types for this dictionary
|
|
|
|
"""
|
|
|
|
types = []
|
|
|
|
curDict = dictionary
|
|
|
|
while curDict:
|
|
|
|
types.extend([m.type for m in curDict.members])
|
|
|
|
curDict = curDict.parent
|
|
|
|
return types
|
|
|
|
|
|
|
|
def getTypesFromCallback(callback):
|
|
|
|
"""
|
|
|
|
Get the types this callback depends on: its return type and the
|
|
|
|
types of its arguments.
|
|
|
|
"""
|
|
|
|
sig = callback.signatures()[0]
|
|
|
|
types = [sig[0]] # Return type
|
|
|
|
types.extend(arg.type for arg in sig[1]) # Arguments
|
|
|
|
return types
|
|
|
|
|
|
|
|
def findCallbacksAndDictionaries(inputTypes):
|
|
|
|
"""
|
|
|
|
Ensure that all callbacks and dictionaries reachable from types end up in
|
|
|
|
the returned callbacks and dictionaries sets.
|
|
|
|
|
|
|
|
Note that we assume that our initial invocation already includes all types
|
|
|
|
reachable via descriptors in "types", so we only have to deal with things
|
|
|
|
that are themeselves reachable via callbacks and dictionaries.
|
|
|
|
"""
|
|
|
|
def doFindCallbacksAndDictionaries(types, callbacks, dictionaries):
|
|
|
|
unhandledTypes = set()
|
|
|
|
for type in types:
|
|
|
|
if type.isCallback() and type not in callbacks:
|
|
|
|
unhandledTypes |= getFlatTypes(getTypesFromCallback(type))
|
|
|
|
callbacks.add(type)
|
|
|
|
elif type.isDictionary() and type.inner not in dictionaries:
|
|
|
|
d = type.inner
|
|
|
|
unhandledTypes |= getFlatTypes(getTypesFromDictionary(d))
|
|
|
|
while d:
|
|
|
|
dictionaries.add(d)
|
|
|
|
d = d.parent
|
|
|
|
if len(unhandledTypes) != 0:
|
|
|
|
doFindCallbacksAndDictionaries(unhandledTypes, callbacks, dictionaries)
|
|
|
|
|
|
|
|
retCallbacks = set()
|
|
|
|
retDictionaries = set()
|
|
|
|
doFindCallbacksAndDictionaries(inputTypes, retCallbacks, retDictionaries)
|
|
|
|
return (retCallbacks, retDictionaries)
|