auto merge of #2657 : Ms2ger/servo/geckoisms, r=jdm

This commit is contained in:
bors-servo 2014-06-18 11:11:25 -04:00
commit 2c7af54952

View file

@ -1051,54 +1051,27 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
raise TypeError("Don't know how to declare return value for %s" % raise TypeError("Don't know how to declare return value for %s" %
returnType) returnType)
def isChromeOnly(m):
return m.getExtendedAttribute("ChromeOnly")
class PropertyDefiner: class PropertyDefiner:
""" """
A common superclass for defining things on prototype objects. A common superclass for defining things on prototype objects.
Subclasses should implement generateArray to generate the actual arrays of Subclasses should implement generateArray to generate the actual arrays of
things we're defining. They should also set self.chrome to the list of things we're defining. They should also set self.regular to the list of
things exposed to chrome and self.regular to the list of things exposed to things exposed to web pages.
web pages. self.chrome must be a superset of self.regular but also include
all the ChromeOnly stuff.
""" """
def __init__(self, descriptor, name): def __init__(self, descriptor, name):
self.descriptor = descriptor self.descriptor = descriptor
self.name = name self.name = name
# self.prefCacheData will store an array of (prefname, bool*)
# pairs for our bool var caches. generateArray will fill it def variableName(self):
# in as needed. if len(self.regular) > 0:
self.prefCacheData = []
def hasChromeOnly(self):
return len(self.chrome) > len(self.regular)
def hasNonChromeOnly(self):
return len(self.regular) > 0
def variableName(self, chrome):
if chrome and self.hasChromeOnly():
return "sChrome" + self.name
if self.hasNonChromeOnly():
return "s" + self.name return "s" + self.name
return "ptr::null()" return "ptr::null()"
def __str__(self): def __str__(self):
# We only need to generate id arrays for things that will end # We only need to generate id arrays for things that will end
# up used via ResolveProperty or EnumerateProperties. # up used via ResolveProperty or EnumerateProperties.
str = self.generateArray(self.regular, self.variableName(False)) return self.generateArray(self.regular, self.variableName())
if self.hasChromeOnly():
str += self.generateArray(self.chrome, self.variableName(True))
return str
@staticmethod
def getControllingPref(interfaceMember):
prefName = interfaceMember.getExtendedAttribute("Pref")
if prefName is None:
return None
# It's a list of strings
assert(len(prefName) is 1)
assert(prefName[0] is not None)
return prefName[0]
def generatePrefableArray(self, array, name, specTemplate, specTerminator, def generatePrefableArray(self, array, name, specTemplate, specTerminator,
specType, getDataTuple): specType, getDataTuple):
@ -1151,47 +1124,18 @@ class MethodDefiner(PropertyDefiner):
methods = [m for m in descriptor.interface.members if methods = [m for m in descriptor.interface.members if
m.isMethod() and m.isStatic() == static and m.isMethod() and m.isStatic() == static and
not m.isIdentifierLess()] not m.isIdentifierLess()]
self.chrome = [{"name": m.identifier.name,
"length": methodLength(m),
"flags": "JSPROP_ENUMERATE",
"pref": PropertyDefiner.getControllingPref(m) }
for m in methods]
self.regular = [{"name": m.identifier.name, self.regular = [{"name": m.identifier.name,
"length": methodLength(m), "length": methodLength(m),
"flags": "JSPROP_ENUMERATE", "flags": "JSPROP_ENUMERATE" }
"pref": PropertyDefiner.getControllingPref(m) } for m in methods]
for m in methods if not isChromeOnly(m)]
# FIXME Check for an existing iterator on the interface first. # FIXME Check for an existing iterator on the interface first.
if any(m.isGetter() and m.isIndexed() for m in methods): if any(m.isGetter() and m.isIndexed() for m in methods):
self.chrome.append({"name": 'iterator',
"methodInfo": False,
"nativeName": "JS_ArrayIterator",
"length": 0,
"flags": "JSPROP_ENUMERATE",
"pref": None })
self.regular.append({"name": 'iterator', self.regular.append({"name": 'iterator',
"methodInfo": False, "methodInfo": False,
"nativeName": "JS_ArrayIterator", "nativeName": "JS_ArrayIterator",
"length": 0, "length": 0,
"flags": "JSPROP_ENUMERATE", "flags": "JSPROP_ENUMERATE" })
"pref": None })
#if not descriptor.interface.parent and not static:
# self.chrome.append({"name": 'QueryInterface',
# "methodInfo": False,
# "length": 1,
# "flags": "0",
# "pref": None })
if static:
if not descriptor.interface.hasInterfaceObject():
# static methods go on the interface object
assert not self.hasChromeOnly() and not self.hasNonChromeOnly()
else:
if not descriptor.interface.hasInterfacePrototypeObject():
# non-static methods go on the interface prototype object
assert not self.hasChromeOnly() and not self.hasNonChromeOnly()
def generateArray(self, array, name): def generateArray(self, array, name):
if len(array) == 0: if len(array) == 0:
@ -1222,8 +1166,7 @@ class AttrDefiner(PropertyDefiner):
def __init__(self, descriptor, name): def __init__(self, descriptor, name):
PropertyDefiner.__init__(self, descriptor, name) PropertyDefiner.__init__(self, descriptor, name)
self.name = name self.name = name
self.chrome = [m for m in descriptor.interface.members if m.isAttr()] self.regular = [m for m in descriptor.interface.members if m.isAttr()]
self.regular = [m for m in self.chrome if not isChromeOnly(m)]
def generateArray(self, array, name): def generateArray(self, array, name):
if len(array) == 0: if len(array) == 0:
@ -1273,8 +1216,7 @@ class ConstDefiner(PropertyDefiner):
def __init__(self, descriptor, name): def __init__(self, descriptor, name):
PropertyDefiner.__init__(self, descriptor, name) PropertyDefiner.__init__(self, descriptor, name)
self.name = name self.name = name
self.chrome = [m for m in descriptor.interface.members if m.isConst()] self.regular = [m for m in descriptor.interface.members if m.isConst()]
self.regular = [m for m in self.chrome if not isChromeOnly(m)]
def generateArray(self, array, name): def generateArray(self, array, name):
if len(array) == 0: if len(array) == 0:
@ -1898,17 +1840,10 @@ class PropertyArrays():
def arrayNames(): def arrayNames():
return [ "staticMethods", "methods", "attrs", "consts" ] return [ "staticMethods", "methods", "attrs", "consts" ]
@staticmethod def variableNames(self):
def xrayRelevantArrayNames():
return [ "methods", "attrs", "consts" ]
def hasChromeOnly(self):
return reduce(lambda b, a: b or getattr(self, a).hasChromeOnly(),
self.arrayNames(), False)
def variableNames(self, chrome):
names = {} names = {}
for array in self.arrayNames(): for array in self.arrayNames():
names[array] = getattr(self, array).variableName(chrome) names[array] = getattr(self, array).variableName()
return names return names
def __str__(self): def __str__(self):
define = "" define = ""
@ -1942,22 +1877,6 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
# if we don't need to create anything, why are we generating this? # if we don't need to create anything, why are we generating this?
assert needInterfaceObject or needInterfacePrototypeObject assert needInterfaceObject or needInterfacePrototypeObject
prefCacheData = []
for var in self.properties.arrayNames():
props = getattr(self.properties, var)
prefCacheData.extend(props.prefCacheData)
if len(prefCacheData) is not 0:
prefCacheData = [
CGGeneric('Preferences::AddBoolVarCache(%s, "%s");' % (ptr, pref)) for
(pref, ptr) in prefCacheData]
prefCache = CGWrapper(CGIndenter(CGList(prefCacheData, "\n")),
pre=("static bool sPrefCachesInited = false;\n"
"if (!sPrefCachesInited) {\n"
" sPrefCachesInited = true;\n"),
post="\n}")
else:
prefCache = None
getParentProto = ("let parentProto: *mut JSObject = %s;\n" + getParentProto = ("let parentProto: *mut JSObject = %s;\n" +
"if parentProto.is_null() {\n" + "if parentProto.is_null() {\n" +
" return ptr::mut_null();\n" + " return ptr::mut_null();\n" +
@ -1979,7 +1898,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
domClass = "ptr::null()" domClass = "ptr::null()"
def arrayPtr(name): def arrayPtr(name):
val = ('%(' + name + ')s') % self.properties.variableNames(False) val = ('%(' + name + ')s') % self.properties.variableNames()
if val == "ptr::null()": if val == "ptr::null()":
return "None" return "None"
return "Some(%s.as_slice())" % val return "Some(%s.as_slice())" % val
@ -1999,17 +1918,10 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
arrayPtr("methods"), arrayPtr("attrs"), arrayPtr("methods"), arrayPtr("attrs"),
arrayPtr("consts"), arrayPtr("staticMethods"), arrayPtr("consts"), arrayPtr("staticMethods"),
'"' + self.descriptor.interface.identifier.name + '"' if needInterfaceObject else "ptr::null()") '"' + self.descriptor.interface.identifier.name + '"' if needInterfaceObject else "ptr::null()")
if self.properties.hasChromeOnly():
accessCheck = "xpc::AccessCheck::isChrome(js::GetObjectCompartment(aGlobal))"
chrome = CGIfWrapper(CGGeneric(call % self.properties.variableNames(True)),
accessCheck)
chrome = CGWrapper(chrome, pre="\n\n")
else:
chrome = None
functionBody = CGList( functionBody = CGList(
[CGGeneric(getParentProto), prefCache, chrome, [CGGeneric(getParentProto),
CGGeneric(call % self.properties.variableNames(False))], CGGeneric(call % self.properties.variableNames())],
"\n\n") "\n\n")
#return CGIndenter(CGWrapper(functionBody, pre="/*", post="*/return ptr::null()")).define() #return CGIndenter(CGWrapper(functionBody, pre="/*", post="*/return ptr::null()")).define()
return CGIndenter(functionBody).define() return CGIndenter(functionBody).define()
@ -3953,9 +3865,6 @@ class CGDescriptor(CGThing):
if descriptor.interface.hasInterfaceObject(): if descriptor.interface.hasInterfaceObject():
cgThings.append(CGDefineDOMInterfaceMethod(descriptor)) cgThings.append(CGDefineDOMInterfaceMethod(descriptor))
if (descriptor.interface.getExtendedAttribute("PrefControlled") is not None):
#cgThings.append(CGPrefEnabled(descriptor))
pass
if descriptor.concrete: if descriptor.concrete:
if descriptor.proxy: if descriptor.proxy: