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/.
|
|
|
|
|
2016-06-02 17:34:39 +03:00
|
|
|
from WebIDL import IDLImplementsStatement
|
2013-01-28 17:34:31 +04:00
|
|
|
import os
|
2014-10-01 22:43:26 +04:00
|
|
|
from collections import defaultdict
|
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"
|
|
|
|
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2016-07-08 07:37:54 +03:00
|
|
|
class DescriptorProvider:
|
|
|
|
"""
|
2016-07-08 07:37:54 +03:00
|
|
|
A way of getting descriptors for interface names. Subclasses must
|
|
|
|
have a getDescriptor method callable with the interface name only.
|
2016-07-08 07:37:54 +03:00
|
|
|
"""
|
2016-07-08 07:37:54 +03:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
2016-07-08 07:37:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Configuration(DescriptorProvider):
|
2012-03-31 08:42:20 +04:00
|
|
|
"""
|
|
|
|
Represents global configuration state based on IDL parse data and
|
|
|
|
the configuration file.
|
|
|
|
"""
|
2015-01-10 14:46:41 +03:00
|
|
|
def __init__(self, filename, parseData, generatedEvents=[]):
|
2016-07-08 07:37:54 +03:00
|
|
|
DescriptorProvider.__init__(self)
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
# 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 = {}
|
2015-10-15 20:06:44 +03:00
|
|
|
self.descriptorsByName = {}
|
2015-04-28 19:25:55 +03:00
|
|
|
self.optimizedOutDescriptorNames = set()
|
2015-08-10 20:11:42 +03:00
|
|
|
self.generatedEvents = generatedEvents
|
|
|
|
self.maxProtoChainLength = 0
|
2012-03-31 08:42:20 +04:00
|
|
|
for thing in parseData:
|
2014-09-24 17:11:29 +04:00
|
|
|
if isinstance(thing, IDLImplementsStatement):
|
|
|
|
# Our build system doesn't support dep build involving
|
|
|
|
# addition/removal of "implements" statements that appear in a
|
|
|
|
# different .webidl file than their LHS interface. Make sure we
|
2017-01-25 00:11:30 +03:00
|
|
|
# don't have any of those. See similar block below for partial
|
|
|
|
# interfaces!
|
2014-09-24 17:11:29 +04:00
|
|
|
#
|
|
|
|
# But whitelist a RHS that is LegacyQueryInterface,
|
|
|
|
# since people shouldn't be adding any of those.
|
|
|
|
if (thing.implementor.filename() != thing.filename() and
|
|
|
|
thing.implementee.identifier.name != "LegacyQueryInterface"):
|
|
|
|
raise TypeError(
|
|
|
|
"The binding build system doesn't really support "
|
|
|
|
"'implements' statements which don't appear in the "
|
|
|
|
"file in which the left-hand side of the statement is "
|
|
|
|
"defined. Don't do this unless your right-hand side "
|
|
|
|
"is LegacyQueryInterface.\n"
|
|
|
|
"%s\n"
|
|
|
|
"%s" %
|
|
|
|
(thing.location, thing.implementor.location))
|
2015-05-14 05:19:22 +03:00
|
|
|
|
2015-08-10 20:11:42 +03:00
|
|
|
assert not thing.isType()
|
2015-05-14 05:19:22 +03:00
|
|
|
|
2016-06-02 17:34:39 +03:00
|
|
|
if not thing.isInterface() and not thing.isNamespace():
|
2012-10-01 16:56:31 +04:00
|
|
|
continue
|
2012-03-31 08:42:20 +04:00
|
|
|
iface = thing
|
2017-01-25 00:11:30 +03:00
|
|
|
# Our build system doesn't support dep builds involving
|
|
|
|
# addition/removal of partial interfaces that appear in a different
|
|
|
|
# .webidl file than the interface they are extending. Make sure we
|
|
|
|
# don't have any of those. See similar block above for "implements"
|
|
|
|
# statements!
|
|
|
|
if not iface.isExternal():
|
|
|
|
for partialIface in iface.getPartialInterfaces():
|
|
|
|
if (partialIface.filename() != iface.filename() and
|
|
|
|
# Unfortunately, NavigatorProperty does exactly the
|
|
|
|
# thing we're trying to prevent here. I'm not sure how
|
|
|
|
# to deal with that, short of effectively requiring a
|
|
|
|
# clobber when NavigatorProperty is added/removed and
|
|
|
|
# whitelisting the things it outputs here as
|
|
|
|
# restrictively as I can.
|
|
|
|
(partialIface.identifier.name != "Navigator" or
|
|
|
|
len(partialIface.members) != 1 or
|
|
|
|
partialIface.members[0].location != partialIface.location or
|
|
|
|
partialIface.members[0].identifier.location.filename() !=
|
|
|
|
"<builtin>")):
|
|
|
|
raise TypeError(
|
|
|
|
"The binding build system doesn't really support "
|
|
|
|
"partial interfaces which don't appear in the "
|
|
|
|
"file in which the interface they are extending is "
|
|
|
|
"defined. Don't do this.\n"
|
|
|
|
"%s\n"
|
|
|
|
"%s" %
|
|
|
|
(partialIface.location, iface.location))
|
2012-03-31 08:42:20 +04:00
|
|
|
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():
|
2015-04-28 19:25:55 +03:00
|
|
|
self.optimizedOutDescriptorNames.add(iface.identifier.name)
|
2012-10-01 16:56:31 +04:00
|
|
|
continue
|
|
|
|
entry = {}
|
|
|
|
else:
|
|
|
|
entry = config[iface.identifier.name]
|
2016-07-08 07:37:54 +03:00
|
|
|
assert not isinstance(entry, list)
|
|
|
|
desc = Descriptor(self, iface, entry)
|
|
|
|
self.descriptors.append(desc)
|
2015-10-15 20:06:44 +03:00
|
|
|
# Setting up descriptorsByName while iterating through interfaces
|
|
|
|
# means we can get the nativeType of iterable interfaces without
|
|
|
|
# having to do multiple loops.
|
2016-07-08 07:37:54 +03:00
|
|
|
assert desc.interface.identifier.name not in self.descriptorsByName
|
|
|
|
self.descriptorsByName[desc.interface.identifier.name] = desc
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2013-05-09 21:06:48 +04:00
|
|
|
# Keep the descriptor list sorted for determinism.
|
2015-08-10 19:53:45 +03:00
|
|
|
self.descriptors.sort(lambda x, y: cmp(x.name, y.name))
|
2013-05-09 21:06:48 +04:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2014-10-01 22:43:26 +04:00
|
|
|
# Dictionary mapping from a union type name to a set of filenames where
|
|
|
|
# union types with that name are used.
|
|
|
|
self.filenamesPerUnion = defaultdict(set)
|
|
|
|
|
2016-07-08 07:37:55 +03:00
|
|
|
# Dictionary mapping from a filename to a list of types for
|
|
|
|
# the union types used in that file. If a union type is used
|
|
|
|
# in multiple files then it will be added to the list for the
|
|
|
|
# None key. Note that the list contains a type for every use
|
|
|
|
# of a union type, so there can be multiple entries with union
|
|
|
|
# types that have the same name.
|
2014-10-01 22:43:26 +04:00
|
|
|
self.unionsPerFilename = defaultdict(list)
|
|
|
|
|
2016-07-08 07:37:55 +03:00
|
|
|
for (t, _) in getAllTypes(self.descriptors, self.dictionaries, self.callbacks):
|
2015-07-01 07:15:30 +03:00
|
|
|
while True:
|
2017-02-15 08:00:17 +03:00
|
|
|
if t.isRecord():
|
2015-07-01 07:15:30 +03:00
|
|
|
t = t.inner
|
|
|
|
elif t.unroll() != t:
|
|
|
|
t = t.unroll()
|
2015-07-31 20:30:55 +03:00
|
|
|
elif t.isPromise():
|
|
|
|
t = t.promiseInnerType()
|
2015-07-01 07:15:30 +03:00
|
|
|
else:
|
|
|
|
break
|
2014-10-01 22:43:26 +04:00
|
|
|
if t.isUnion():
|
|
|
|
filenamesForUnion = self.filenamesPerUnion[t.name]
|
|
|
|
if t.filename() not in filenamesForUnion:
|
2016-01-30 00:56:04 +03:00
|
|
|
# We have a to be a bit careful: some of our built-in
|
|
|
|
# typedefs are for unions, and those unions end up with
|
|
|
|
# "<unknown>" as the filename. If that happens, we don't
|
|
|
|
# want to try associating this union with one particular
|
|
|
|
# filename, since there isn't one to associate it with,
|
|
|
|
# really.
|
|
|
|
if t.filename() == "<unknown>":
|
|
|
|
uniqueFilenameForUnion = None
|
|
|
|
elif len(filenamesForUnion) == 0:
|
2014-10-01 22:43:26 +04:00
|
|
|
# This is the first file that we found a union with this
|
|
|
|
# name in, record the union as part of the file.
|
|
|
|
uniqueFilenameForUnion = t.filename()
|
|
|
|
else:
|
|
|
|
# We already found a file that contains a union with
|
|
|
|
# this name.
|
|
|
|
if len(filenamesForUnion) == 1:
|
|
|
|
# This is the first time we found a union with this
|
|
|
|
# name in another file.
|
|
|
|
for f in filenamesForUnion:
|
|
|
|
# Filter out unions with this name from the
|
|
|
|
# unions for the file where we previously found
|
|
|
|
# them.
|
|
|
|
unionsForFilename = self.unionsPerFilename[f]
|
2016-07-08 07:37:55 +03:00
|
|
|
unionsForFilename = filter(lambda u: u.name != t.name,
|
2014-10-01 22:43:26 +04:00
|
|
|
unionsForFilename)
|
|
|
|
if len(unionsForFilename) == 0:
|
|
|
|
del self.unionsPerFilename[f]
|
|
|
|
else:
|
|
|
|
self.unionsPerFilename[f] = unionsForFilename
|
|
|
|
# Unions with this name appear in multiple files, record
|
|
|
|
# the filename as None, so that we can detect that.
|
|
|
|
uniqueFilenameForUnion = None
|
2016-07-08 07:37:55 +03:00
|
|
|
self.unionsPerFilename[uniqueFilenameForUnion].append(t)
|
2014-10-01 22:43:26 +04:00
|
|
|
filenamesForUnion.add(t.filename())
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
def getInterface(self, ifname):
|
|
|
|
return self.interfaces[ifname]
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
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':
|
2016-02-05 22:20:08 +03:00
|
|
|
getter = lambda x: x.interface.isNavigatorProperty()
|
2014-08-27 21:17:36 +04:00
|
|
|
elif key == 'isExposedInAnyWorker':
|
2015-02-09 19:42:27 +03:00
|
|
|
getter = lambda x: x.interface.isExposedInAnyWorker()
|
2016-02-22 12:41:09 +03:00
|
|
|
elif key == 'isExposedInWorkerDebugger':
|
|
|
|
getter = lambda x: x.interface.isExposedInWorkerDebugger()
|
2016-11-06 11:54:29 +03:00
|
|
|
elif key == 'isExposedInAnyWorklet':
|
|
|
|
getter = lambda x: x.interface.isExposedInAnyWorklet()
|
2014-10-17 19:30:19 +04:00
|
|
|
elif key == 'isExposedInSystemGlobals':
|
2015-02-09 19:42:27 +03:00
|
|
|
getter = lambda x: x.interface.isExposedInSystemGlobals()
|
2014-11-16 23:01:32 +03:00
|
|
|
elif key == 'isExposedInWindow':
|
2015-02-09 19:42:27 +03:00
|
|
|
getter = lambda x: x.interface.isExposedInWindow()
|
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
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
def getEnums(self, webIDLFile):
|
|
|
|
return filter(lambda e: e.filename() == webIDLFile, self.enums)
|
2013-01-29 08:30:17 +04:00
|
|
|
|
2016-07-08 07:37:54 +03:00
|
|
|
def getDictionaries(self, webIDLFile):
|
|
|
|
return filter(lambda d: d.filename() == webIDLFile, self.dictionaries)
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2016-07-08 07:37:54 +03:00
|
|
|
def getCallbacks(self, webIDLFile):
|
|
|
|
return filter(lambda c: c.filename() == webIDLFile, self.callbacks)
|
2013-01-29 08:30:17 +04:00
|
|
|
|
2016-07-08 07:37:54 +03:00
|
|
|
def getDescriptor(self, interfaceName):
|
2012-06-19 20:09:37 +04:00
|
|
|
"""
|
2016-07-08 07:37:54 +03:00
|
|
|
Gets the appropriate descriptor for the given interface name.
|
2012-06-19 20:09:37 +04:00
|
|
|
"""
|
2015-04-28 19:25:55 +03:00
|
|
|
# We may have optimized out this descriptor, but the chances of anyone
|
|
|
|
# asking about it are then slim. Put the check for that _after_ we've
|
2016-07-08 07:37:54 +03:00
|
|
|
# done our normal lookup. But that means we have to do our normal
|
|
|
|
# lookup in a way that will not throw if it fails.
|
|
|
|
d = self.descriptorsByName.get(interfaceName, None)
|
|
|
|
if d:
|
|
|
|
return d
|
2013-11-05 18:16:26 +04:00
|
|
|
|
2015-04-28 19:25:55 +03:00
|
|
|
if interfaceName in self.optimizedOutDescriptorNames:
|
|
|
|
raise NoSuchDescriptorError(
|
|
|
|
"No descriptor for '%s', which is a mixin ([NoInterfaceObject] "
|
|
|
|
"and a consequential interface) without an explicit "
|
|
|
|
"Bindings.conf annotation." % interfaceName)
|
|
|
|
|
2015-08-10 20:11:42 +03:00
|
|
|
raise NoSuchDescriptorError("For " + interfaceName + " found no matches")
|
2015-08-10 19:57:39 +03:00
|
|
|
|
|
|
|
|
2012-06-19 20:09:37 +04:00
|
|
|
class NoSuchDescriptorError(TypeError):
|
|
|
|
def __init__(self, str):
|
|
|
|
TypeError.__init__(self, str)
|
|
|
|
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2015-01-12 19:52:21 +03:00
|
|
|
def methodReturnsJSObject(method):
|
|
|
|
assert method.isMethod()
|
|
|
|
if method.returnsPromise():
|
|
|
|
return True
|
|
|
|
|
|
|
|
for signature in method.signatures():
|
|
|
|
returnType = signature[0]
|
|
|
|
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2015-03-04 05:01:58 +03:00
|
|
|
|
|
|
|
def MemberIsUnforgeable(member, descriptor):
|
|
|
|
# Note: "or" and "and" return either their LHS or RHS, not
|
|
|
|
# necessarily booleans. Make sure to return a boolean from this
|
|
|
|
# method, because callers will compare its return value to
|
|
|
|
# booleans.
|
|
|
|
return bool((member.isAttr() or member.isMethod()) and
|
|
|
|
not member.isStatic() and
|
|
|
|
(member.isUnforgeable() or
|
|
|
|
descriptor.interface.getExtendedAttribute("Unforgeable")))
|
|
|
|
|
|
|
|
|
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):
|
2016-07-08 07:37:54 +03:00
|
|
|
DescriptorProvider.__init__(self)
|
|
|
|
self.config = config
|
2012-03-31 08:42:20 +04:00
|
|
|
self.interface = interface
|
|
|
|
|
2016-10-11 01:16:26 +03:00
|
|
|
self.wantsXrays = (not interface.isExternal() and
|
|
|
|
interface.isExposedInWindow())
|
|
|
|
|
|
|
|
if self.wantsXrays:
|
|
|
|
# We could try to restrict self.wantsXrayExpandoClass further. For
|
|
|
|
# example, we could set it to false if all of our slots store
|
|
|
|
# Gecko-interface-typed things, because we don't use Xray expando
|
|
|
|
# slots for those. But note that we would need to check the types
|
|
|
|
# of not only the members of "interface" but also of all its
|
|
|
|
# ancestors, because those can have members living in our slots too.
|
|
|
|
# For now, do the simple thing.
|
|
|
|
self.wantsXrayExpandoClass = (interface.totalMembersInSlots != 0)
|
2015-02-26 17:40:08 +03:00
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
# Read the desc, and fill in the relevant defaults.
|
2012-08-28 21:10:09 +04:00
|
|
|
ifaceName = self.interface.identifier.name
|
2015-10-15 20:06:44 +03:00
|
|
|
# For generated iterator interfaces for other iterable interfaces, we
|
|
|
|
# just use IterableIterator as the native type, templated on the
|
|
|
|
# nativeType of the iterable interface. That way we can have a
|
|
|
|
# templated implementation for all the duplicated iterator
|
|
|
|
# functionality.
|
|
|
|
if self.interface.isIteratorInterface():
|
|
|
|
itrName = self.interface.iterableInterface.identifier.name
|
|
|
|
itrDesc = self.getDescriptor(itrName)
|
2015-10-16 22:54:51 +03:00
|
|
|
nativeTypeDefault = iteratorNativeType(itrDesc)
|
2015-10-15 20:06:44 +03:00
|
|
|
|
|
|
|
elif self.interface.isExternal():
|
2015-02-25 00:04:22 +03:00
|
|
|
nativeTypeDefault = "nsIDOM" + ifaceName
|
2012-08-28 21:10:09 +04:00
|
|
|
else:
|
2016-07-08 07:37:55 +03:00
|
|
|
nativeTypeDefault = "mozilla::dom::" + ifaceName
|
2012-08-28 21:10:09 +04:00
|
|
|
|
|
|
|
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:
|
2016-07-08 07:37:55 +03:00
|
|
|
if not self.interface.isExternal() and self.interface.getExtendedAttribute("HeaderFile"):
|
2013-04-18 00:29:09 +04:00
|
|
|
headerDefault = self.interface.getExtendedAttribute("HeaderFile")[0]
|
2015-10-15 20:06:44 +03:00
|
|
|
elif self.interface.isIteratorInterface():
|
|
|
|
headerDefault = "mozilla/dom/IterableIterator.h"
|
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
|
|
|
|
|
|
|
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
|
2016-06-02 17:34:39 +03:00
|
|
|
not self.interface.isNamespace() and
|
2012-10-10 23:57:57 +04:00
|
|
|
desc.get('concrete', True))
|
2015-03-04 05:01:58 +03:00
|
|
|
self.hasUnforgeableMembers = (self.concrete and
|
|
|
|
any(MemberIsUnforgeable(m, self) for m in
|
|
|
|
self.interface.members))
|
2014-09-06 00:36:32 +04:00
|
|
|
self.operations = {
|
2012-10-22 21:08:52 +04:00
|
|
|
'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
|
|
|
}
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2014-10-20 06:26:20 +04:00
|
|
|
# Stringifiers and jsonifiers need to be set up whether an interface is
|
|
|
|
# concrete or not, because they're actually prototype methods and hence
|
|
|
|
# can apply to instances of descendant interfaces. Legacy callers and
|
|
|
|
# named/indexed operations only need to be set up on concrete
|
|
|
|
# interfaces, since they affect the JSClass we end up using, not the
|
|
|
|
# prototype object.
|
|
|
|
def addOperation(operation, m):
|
|
|
|
if not self.operations[operation]:
|
|
|
|
self.operations[operation] = m
|
|
|
|
|
|
|
|
# Since stringifiers go on the prototype, we only need to worry
|
|
|
|
# about our own stringifier, not those of our ancestor interfaces.
|
|
|
|
if not self.interface.isExternal():
|
|
|
|
for m in self.interface.members:
|
2012-10-22 21:08:52 +04:00
|
|
|
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)
|
2014-10-20 06:26:20 +04:00
|
|
|
|
|
|
|
if self.concrete:
|
|
|
|
self.proxy = False
|
|
|
|
iface = self.interface
|
|
|
|
for m in iface.members:
|
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 "
|
2015-08-10 20:11:42 +03:00
|
|
|
"identifier.\n%s" % m.location)
|
2013-03-04 23:08:24 +04:00
|
|
|
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):
|
|
|
|
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
|
|
|
|
|
2014-09-06 00:36:32 +04:00
|
|
|
self.proxy = (self.supportsIndexedProperties() or
|
|
|
|
(self.supportsNamedProperties() and
|
2016-04-30 05:59:40 +03:00
|
|
|
not self.hasNamedPropertiesObject) or
|
|
|
|
self.hasNonOrdinaryGetPrototypeOf())
|
2014-09-06 00:36:32 +04:00
|
|
|
|
2012-05-22 17:46:20 +04:00
|
|
|
if self.proxy:
|
2014-09-06 00:36:32 +04:00
|
|
|
if (not self.operations['IndexedGetter'] and
|
|
|
|
(self.operations['IndexedSetter'] or
|
|
|
|
self.operations['IndexedDeleter'] or
|
|
|
|
self.operations['IndexedCreator'])):
|
2012-11-05 20:58:03 +04:00
|
|
|
raise SyntaxError("%s supports indexed properties but does "
|
|
|
|
"not have an indexed getter.\n%s" %
|
|
|
|
(self.interface, self.interface.location))
|
2014-09-06 00:36:32 +04:00
|
|
|
if (not self.operations['NamedGetter'] and
|
|
|
|
(self.operations['NamedSetter'] or
|
|
|
|
self.operations['NamedDeleter'] or
|
|
|
|
self.operations['NamedCreator'])):
|
2012-11-05 20:58:03 +04:00
|
|
|
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
|
|
|
|
|
2015-08-10 20:11:42 +03:00
|
|
|
if desc.get('wantsQI', None) is not None:
|
2013-09-30 08:15:37 +04:00
|
|
|
self._wantsQI = desc.get('wantsQI', None)
|
2012-10-10 23:57:57 +04:00
|
|
|
self.wrapperCache = (not self.interface.isCallback() and
|
2015-10-15 20:06:44 +03:00
|
|
|
not self.interface.isIteratorInterface() and
|
2014-11-01 17:22:21 +03:00
|
|
|
desc.get('wrapperCache', True))
|
2012-06-16 00:25:50 +04:00
|
|
|
|
2016-07-08 07:37:55 +03:00
|
|
|
self.name = interface.identifier.name
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
# self.extendedAttributes is a dict of dicts, keyed on
|
|
|
|
# all/getterOnly/setterOnly and then on member name. Values are an
|
|
|
|
# array of extended attributes.
|
2015-08-10 19:53:45 +03:00
|
|
|
self.extendedAttributes = {'all': {}, 'getterOnly': {}, 'setterOnly': {}}
|
2012-03-31 08:42:20 +04:00
|
|
|
|
|
|
|
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:
|
2014-08-28 02:43:56 +04:00
|
|
|
for attribute in ['implicitJSContext']:
|
2013-03-19 03:04:24 +04:00
|
|
|
addExtendedAttribute(attribute, desc.get(attribute, {}))
|
2012-03-31 08:42:20 +04:00
|
|
|
|
2016-02-05 22:20:08 +03:00
|
|
|
if self.interface.identifier.name == 'Navigator':
|
|
|
|
for m in self.interface.members:
|
|
|
|
if m.isAttr() and m.navigatorObjectGetter:
|
|
|
|
# These getters call ConstructNavigatorObject to construct
|
|
|
|
# the value, and ConstructNavigatorObject needs a JSContext.
|
|
|
|
self.extendedAttributes['all'].setdefault(m.identifier.name, []).append('implicitJSContext')
|
|
|
|
|
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():
|
2014-07-24 23:57:02 +04:00
|
|
|
def isTestInterface(iface):
|
|
|
|
return (iface.identifier.name in ["TestInterface",
|
|
|
|
"TestJSImplInterface",
|
|
|
|
"TestRenamedInterface"])
|
2014-07-15 03:08:45 +04:00
|
|
|
|
2014-09-20 06:58:26 +04:00
|
|
|
for member in self.interface.members:
|
|
|
|
if not member.isAttr() and not member.isMethod():
|
|
|
|
continue
|
|
|
|
binaryName = member.getExtendedAttribute("BinaryName")
|
|
|
|
if binaryName:
|
|
|
|
assert isinstance(binaryName, list)
|
|
|
|
assert len(binaryName) == 1
|
|
|
|
self._binaryNames.setdefault(member.identifier.name,
|
|
|
|
binaryName[0])
|
|
|
|
|
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)
|
|
|
|
|
2014-09-09 17:19:09 +04:00
|
|
|
@property
|
|
|
|
def prototypeNameChain(self):
|
|
|
|
return map(lambda p: self.getDescriptor(p).name, self.prototypeChain)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def parentPrototypeName(self):
|
|
|
|
if len(self.prototypeChain) == 1:
|
|
|
|
return None
|
|
|
|
return self.getDescriptor(self.prototypeChain[-2]).name
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
def hasInterfaceOrInterfacePrototypeObject(self):
|
|
|
|
|
|
|
|
# Forward-declared interfaces don't need either interface object or
|
2016-07-08 07:37:55 +03:00
|
|
|
# interface prototype object as they're going to use QI.
|
2012-03-31 08:42:20 +04:00
|
|
|
if self.interface.isExternal():
|
|
|
|
return False
|
|
|
|
|
|
|
|
return self.interface.hasInterfaceObject() or self.interface.hasInterfacePrototypeObject()
|
|
|
|
|
2014-09-06 00:36:32 +04:00
|
|
|
@property
|
|
|
|
def hasNamedPropertiesObject(self):
|
|
|
|
if self.interface.isExternal():
|
|
|
|
return False
|
|
|
|
|
|
|
|
return self.isGlobal() and self.supportsNamedProperties()
|
|
|
|
|
2012-03-31 08:42:20 +04:00
|
|
|
def getExtendedAttributes(self, member, getter=False, setter=False):
|
2017-01-18 07:52:13 +03:00
|
|
|
def ensureValidBoolExtendedAttribute(attr, name):
|
2016-07-08 07:37:55 +03:00
|
|
|
if (attr is not None and attr is not True):
|
2017-01-18 07:52:13 +03:00
|
|
|
raise TypeError("Unknown value for '%s': %s" % (name, attr[0]))
|
|
|
|
|
|
|
|
def ensureValidThrowsExtendedAttribute(attr):
|
|
|
|
ensureValidBoolExtendedAttribute(attr, "Throws")
|
|
|
|
|
|
|
|
def ensureValidCanOOMExtendedAttribute(attr):
|
|
|
|
ensureValidBoolExtendedAttribute(attr, "CanOOM")
|
2012-07-14 03:29:14 +04:00
|
|
|
|
2012-09-05 17:21:33 +04:00
|
|
|
def maybeAppendInfallibleToAttrs(attrs, throws):
|
|
|
|
ensureValidThrowsExtendedAttribute(throws)
|
2016-07-08 07:37:55 +03:00
|
|
|
if throws is None:
|
2012-07-14 03:29:14 +04:00
|
|
|
attrs.append("infallible")
|
2012-09-05 17:21:33 +04:00
|
|
|
|
2017-01-18 07:52:13 +03:00
|
|
|
def maybeAppendCanOOMToAttrs(attrs, canOOM):
|
|
|
|
ensureValidCanOOMExtendedAttribute(canOOM)
|
|
|
|
if canOOM is not None:
|
|
|
|
attrs.append("canOOM")
|
|
|
|
|
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")
|
2017-01-18 07:52:13 +03:00
|
|
|
canOOM = member.getExtendedAttribute("CanOOM")
|
2012-09-05 17:21:33 +04:00
|
|
|
if member.isMethod():
|
2015-01-12 19:52:21 +03:00
|
|
|
# JSObject-returning [NewObject] methods must be fallible,
|
|
|
|
# since they have to (fallibly) allocate the new JSObject.
|
|
|
|
if (member.getExtendedAttribute("NewObject") and
|
|
|
|
methodReturnsJSObject(member)):
|
|
|
|
throws = True
|
2012-09-05 17:21:33 +04:00
|
|
|
attrs = self.extendedAttributes['all'].get(name, [])
|
|
|
|
maybeAppendInfallibleToAttrs(attrs, throws)
|
2017-01-18 07:52:13 +03:00
|
|
|
maybeAppendCanOOMToAttrs(attrs, canOOM)
|
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)
|
2017-01-18 07:52:13 +03:00
|
|
|
if canOOM is None:
|
|
|
|
canOOMAttr = "GetterCanOOM" if getter else "SetterCanOOM"
|
|
|
|
canOOM = member.getExtendedAttribute(canOOMAttr)
|
|
|
|
maybeAppendCanOOMToAttrs(attrs, canOOM)
|
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
|
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
def lengthNeedsCallerType(self):
|
|
|
|
"""
|
|
|
|
Determine whether our length getter needs a caller type; this is needed
|
|
|
|
in some indexed-getter proxy algorithms. The idea is that if our
|
|
|
|
indexed getter needs a caller type, our automatically-generated Length()
|
|
|
|
calls need one too.
|
|
|
|
"""
|
|
|
|
assert self.supportsIndexedProperties()
|
|
|
|
indexedGetter = self.operations['IndexedGetter']
|
|
|
|
return indexedGetter.getExtendedAttribute("NeedsCallerType")
|
|
|
|
|
2012-11-05 20:58:03 +04:00
|
|
|
def supportsNamedProperties(self):
|
|
|
|
return self.operations['NamedGetter'] is not None
|
2012-12-07 00:21:18 +04:00
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
def supportedNamesNeedCallerType(self):
|
|
|
|
"""
|
|
|
|
Determine whether our GetSupportedNames call needs a caller type. The
|
|
|
|
idea is that if your named getter needs a caller type, then so does
|
|
|
|
GetSupportedNames.
|
|
|
|
"""
|
|
|
|
assert self.supportsNamedProperties()
|
|
|
|
namedGetter = self.operations['NamedGetter']
|
|
|
|
return namedGetter.getExtendedAttribute("NeedsCallerType")
|
|
|
|
|
2016-04-30 05:59:40 +03:00
|
|
|
def hasNonOrdinaryGetPrototypeOf(self):
|
|
|
|
return self.interface.getExtendedAttribute("NonOrdinaryGetPrototypeOf")
|
|
|
|
|
2013-03-13 22:07:49 +04:00
|
|
|
def needsHeaderInclude(self):
|
|
|
|
"""
|
2015-06-17 20:42:06 +03:00
|
|
|
An interface doesn't need a header file if it is not concrete, not
|
|
|
|
pref-controlled, has no prototype object, has no static methods or
|
|
|
|
attributes and has no parent. The parent matters because we assert
|
|
|
|
things about refcounting that depend on the actual underlying type if we
|
|
|
|
have a parent.
|
|
|
|
|
2013-03-13 22:07:49 +04:00
|
|
|
"""
|
|
|
|
return (self.interface.isExternal() or self.concrete or
|
2015-08-10 19:26:29 +03:00
|
|
|
self.interface.hasInterfacePrototypeObject() or
|
|
|
|
any((m.isAttr() or m.isMethod()) and m.isStatic() for m in self.interface.members) or
|
|
|
|
self.interface.parent)
|
2013-03-13 22:07:49 +04:00
|
|
|
|
2014-08-29 00:33:39 +04:00
|
|
|
def hasThreadChecks(self):
|
2016-05-14 01:11:16 +03:00
|
|
|
# isExposedConditionally does not necessarily imply thread checks
|
|
|
|
# (since at least [SecureContext] is independent of them), but we're
|
|
|
|
# only used to decide whether to include nsThreadUtils.h, so we don't
|
|
|
|
# worry about that.
|
2014-11-16 23:01:32 +03:00
|
|
|
return ((self.isExposedConditionally() and
|
|
|
|
not self.interface.isExposedInWindow()) or
|
|
|
|
self.interface.isExposedInSomeButNotAllWorkers())
|
2014-08-29 00:33:39 +04:00
|
|
|
|
2014-02-05 22:38:16 +04:00
|
|
|
def isExposedConditionally(self):
|
2014-11-16 23:01:32 +03:00
|
|
|
return (self.interface.isExposedConditionally() or
|
|
|
|
self.interface.isExposedInSomeButNotAllWorkers())
|
2014-02-05 22:38:16 +04:00
|
|
|
|
2014-02-05 22:38:18 +04:00
|
|
|
def needsXrayResolveHooks(self):
|
|
|
|
"""
|
2014-11-08 03:07:12 +03:00
|
|
|
Generally, any interface with NeedResolve needs Xray
|
2014-02-05 22:38:18 +04:00
|
|
|
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.
|
|
|
|
"""
|
2014-11-08 03:07:12 +03:00
|
|
|
return (self.interface.getExtendedAttribute("NeedResolve") and
|
2014-02-05 22:38:18 +04:00
|
|
|
self.interface.identifier.name not in ["HTMLObjectElement",
|
2017-07-11 02:00:30 +03:00
|
|
|
"HTMLEmbedElement"])
|
2016-11-04 19:41:26 +03:00
|
|
|
def needsXrayNamedDeleterHook(self):
|
|
|
|
return self.operations["NamedDeleter"] is not None
|
2014-02-05 22:38:18 +04:00
|
|
|
|
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()
|
|
|
|
|
2014-08-05 06:20:34 +04:00
|
|
|
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"))
|
|
|
|
|
2016-05-10 05:25:40 +03:00
|
|
|
@property
|
|
|
|
def namedPropertiesEnumerable(self):
|
|
|
|
"""
|
|
|
|
Returns whether this interface should have enumerable named properties
|
|
|
|
"""
|
|
|
|
assert self.proxy
|
|
|
|
assert self.supportsNamedProperties()
|
|
|
|
iface = self.interface
|
|
|
|
while iface:
|
|
|
|
if iface.getExtendedAttribute("LegacyUnenumerableNamedProperties"):
|
|
|
|
return False
|
|
|
|
iface = iface.parent
|
|
|
|
return True
|
|
|
|
|
2016-05-09 18:08:31 +03:00
|
|
|
@property
|
|
|
|
def registersGlobalNamesOnWindow(self):
|
|
|
|
return (not self.interface.isExternal() and
|
|
|
|
self.interface.hasInterfaceObject() and
|
|
|
|
self.interface.isExposedInWindow() and
|
|
|
|
self.register)
|
|
|
|
|
2016-07-08 07:37:54 +03:00
|
|
|
def getDescriptor(self, interfaceName):
|
|
|
|
"""
|
2016-07-08 07:37:54 +03:00
|
|
|
Gets the appropriate descriptor for the given interface name.
|
2016-07-08 07:37:54 +03:00
|
|
|
"""
|
2016-07-08 07:37:54 +03:00
|
|
|
return self.config.getDescriptor(interfaceName)
|
2016-07-08 07:37:54 +03:00
|
|
|
|
2015-08-10 19:57:39 +03:00
|
|
|
|
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())
|
2016-07-27 19:47:53 +03:00
|
|
|
|
|
|
|
if descriptor.interface.maplikeOrSetlikeOrIterable:
|
|
|
|
maplikeOrSetlikeOrIterable = descriptor.interface.maplikeOrSetlikeOrIterable
|
|
|
|
if maplikeOrSetlikeOrIterable.hasKeyType():
|
|
|
|
types.append(maplikeOrSetlikeOrIterable.keyType)
|
|
|
|
if maplikeOrSetlikeOrIterable.hasValueType():
|
|
|
|
types.append(maplikeOrSetlikeOrIterable.valueType)
|
2013-01-29 08:30:17 +04:00
|
|
|
return types
|
|
|
|
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2013-01-29 08:30:17 +04:00
|
|
|
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
|
|
|
|
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2013-01-29 08:30:17 +04:00
|
|
|
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
|
|
|
|
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2013-01-29 08:30:17 +04:00
|
|
|
def getTypesFromCallback(callback):
|
|
|
|
"""
|
|
|
|
Get the types this callback depends on: its return type and the
|
|
|
|
types of its arguments.
|
|
|
|
"""
|
|
|
|
sig = callback.signatures()[0]
|
2015-08-10 19:53:45 +03:00
|
|
|
types = [sig[0]] # Return type
|
|
|
|
types.extend(arg.type for arg in sig[1]) # Arguments
|
2013-01-29 08:30:17 +04:00
|
|
|
return types
|
|
|
|
|
2015-08-10 19:57:39 +03:00
|
|
|
|
2014-10-01 22:43:26 +04:00
|
|
|
def getAllTypes(descriptors, dictionaries, callbacks):
|
|
|
|
"""
|
|
|
|
Generate all the types we're dealing with. For each type, a tuple
|
2016-07-08 07:37:55 +03:00
|
|
|
containing type, dictionary is yielded. The dictionary can be None if the
|
|
|
|
type does not come from a dictionary.
|
2014-10-01 22:43:26 +04:00
|
|
|
"""
|
|
|
|
for d in descriptors:
|
|
|
|
if d.interface.isExternal():
|
|
|
|
continue
|
|
|
|
for t in getTypesFromDescriptor(d):
|
2016-07-08 07:37:55 +03:00
|
|
|
yield (t, None)
|
2014-10-01 22:43:26 +04:00
|
|
|
for dictionary in dictionaries:
|
|
|
|
for t in getTypesFromDictionary(dictionary):
|
2016-07-08 07:37:55 +03:00
|
|
|
yield (t, dictionary)
|
2014-10-01 22:43:26 +04:00
|
|
|
for callback in callbacks:
|
|
|
|
for t in getTypesFromCallback(callback):
|
2016-07-08 07:37:55 +03:00
|
|
|
yield (t, None)
|
2015-10-16 22:54:51 +03:00
|
|
|
|
|
|
|
def iteratorNativeType(descriptor):
|
|
|
|
assert descriptor.interface.isIterable()
|
|
|
|
iterableDecl = descriptor.interface.maplikeOrSetlikeOrIterable
|
2016-02-18 06:58:07 +03:00
|
|
|
assert iterableDecl.isPairIterator()
|
|
|
|
return "mozilla::dom::IterableIterator<%s>" % descriptor.nativeType
|