Bug 1048699 - Make Exposed=SpecificWorkerType work automatically. r=bz

--HG--
extra : rebase_source : 651bd062b015e2aa030b87a842bc7d63dccf349c
This commit is contained in:
Nikhil Marathe 2014-08-27 10:17:36 -07:00
Родитель 1b9408bc70
Коммит 362c5a201f
3 изменённых файлов: 68 добавлений и 10 удалений

Просмотреть файл

@ -742,6 +742,9 @@ class CGList(CGThing):
deps = deps.union(child.deps())
return deps
def __len__(self):
return len(self.children)
class CGGeneric(CGThing):
"""
@ -2855,8 +2858,35 @@ class CGConstructorEnabled(CGAbstractMethod):
Argument("JS::Handle<JSObject*>", "aObj")])
def definition_body(self):
body = CGList([], "\n")
conditions = []
iface = self.descriptor.interface
if not iface.isExposedInWindow():
exposedInWindowCheck = dedent(
"""
if (NS_IsMainThread()) {
return false;
}
""")
body.append(CGGeneric(exposedInWindowCheck))
if iface.isExposedInAnyWorker() and iface.isExposedOnlyInSomeWorkers():
workerGlobals = sorted(iface.getWorkerExposureSet())
workerCondition = CGList((CGGeneric('strcmp(name, "%s")'% workerGlobal)
for workerGlobal in workerGlobals), " && ")
exposedInWorkerCheck = fill(
"""
if (!NS_IsMainThread()) {
const char* name = js::GetObjectClass(aObj)->name;
if (${workerCondition}) {
return false;
}
}
""", workerCondition=workerCondition.define())
body.append(CGGeneric(exposedInWorkerCheck))
pref = iface.getExtendedAttribute("Pref")
if pref:
assert isinstance(pref, list) and len(pref) == 1
@ -2874,10 +2904,18 @@ class CGConstructorEnabled(CGAbstractMethod):
if checkPermissions is not None:
conditions.append("CheckPermissions(aCx, aObj, permissions_%i)" % checkPermissions)
# We should really have some conditions
assert len(conditions)
return CGWrapper(CGList((CGGeneric(cond) for cond in conditions),
" &&\n"),
pre="return ", post=";\n", reindent=True).define()
assert len(body) or len(conditions)
conditionsWrapper = ""
if len(conditions):
conditionsWrapper = CGWrapper(CGList((CGGeneric(cond) for cond in conditions),
" &&\n"),
pre="return ", post=";\n", reindent=True)
else:
conditionsWrapper = CGGeneric("return true;\n")
body.append(conditionsWrapper)
return body.define()
def CreateBindingJSObject(descriptor, properties, parent):
@ -11617,7 +11655,7 @@ class CGRegisterWorkerBindings(CGAbstractMethod):
# and a non-worker descriptor. When both are present we want the worker
# descriptor, but otherwise we want whatever descriptor we've got.
descriptors = self.config.getDescriptors(hasInterfaceObject=True,
isExposedInAllWorkers=True,
isExposedInAnyWorker=True,
register=True,
skipGen=False,
workers=True)
@ -11627,7 +11665,7 @@ class CGRegisterWorkerBindings(CGAbstractMethod):
filter(
lambda d: d.interface.identifier.name not in workerDescriptorIfaceNames,
self.config.getDescriptors(hasInterfaceObject=True,
isExposedInAllWorkers=True,
isExposedInAnyWorker=True,
register=True,
skipGen=False,
workers=False)))
@ -11639,6 +11677,7 @@ class CGRegisterWorkerBindings(CGAbstractMethod):
condition = (
"%s::ConstructorEnabled(aCx, aObj) && " % bindingNS
+ condition)
conditions.append(condition)
lines = [CGIfWrapper(CGGeneric("return false;\n"), condition) for
condition in conditions]
@ -14098,7 +14137,7 @@ class GlobalGenRoots():
defineIncludes = [CGHeaders.getDeclarationFilename(desc.interface)
for desc in config.getDescriptors(hasInterfaceObject=True,
register=True,
isExposedInAllWorkers=True,
isExposedInAnyWorker=True,
skipGen=False)]
curr = CGHeaders([], [], [], [], [], defineIncludes,

Просмотреть файл

@ -138,8 +138,9 @@ class Configuration:
getter = lambda x: x.interface.isJSImplemented()
elif key == 'isNavigatorProperty':
getter = lambda x: x.interface.getNavigatorProperty() != None
elif key == 'isExposedInAllWorkers':
getter = lambda x: not x.interface.isExternal() and "Worker" in x.interface._exposureGlobalNames
elif key == 'isExposedInAnyWorker':
getter = lambda x: (not x.interface.isExternal() and
x.interface.isExposedInAnyWorker())
else:
# Have to watch out: just closing over "key" is not enough,
# since we're about to mutate its value
@ -549,7 +550,10 @@ class Descriptor(DescriptorProvider):
self.interface.getExtendedAttribute("ChromeOnly") or
self.interface.getExtendedAttribute("Func") or
self.interface.getExtendedAttribute("AvailableIn") or
self.interface.getExtendedAttribute("CheckPermissions"))
self.interface.getExtendedAttribute("CheckPermissions") or
(not self.workers and not self.interface.isExposedInWindow()) or
(self.interface.isExposedInAnyWorker() and
self.interface.isExposedOnlyInSomeWorkers()))
def needsXrayResolveHooks(self):
"""

Просмотреть файл

@ -1055,6 +1055,21 @@ class IDLInterface(IDLObjectWithScope):
len(set(m.identifier.name for m in self.members if
m.isMethod() and not m.isStatic())) == 1)
def isExposedInWindow(self):
return 'Window' in self.exposureSet
def isExposedInAnyWorker(self):
return len(self.getWorkerExposureSet()) > 0
def isExposedOnlyInSomeWorkers(self):
assert self.isExposedInAnyWorker()
workerScopes = self.parentScope.globalNameMapping["Worker"]
return len(workerScopes.difference(self.exposureSet)) > 0
def getWorkerExposureSet(self):
workerScopes = self.parentScope.globalNameMapping["Worker"]
return workerScopes.intersection(self.exposureSet)
def inheritanceDepth(self):
depth = 0
parent = self.parent