Bug 1073124 part 2. Define Exposed=System things in BackstagePass::NewResolve as needed. r=bholley

This commit is contained in:
Boris Zbarsky 2014-10-17 11:30:19 -04:00
parent b9aa282cae
commit 0d7de1cbc4
4 changed files with 104 additions and 2 deletions

View File

@ -11919,6 +11919,63 @@ class CGRegisterWorkerBindings(CGAbstractMethod):
return CGList(lines, "\n").define()
class CGResolveSystemBinding(CGAbstractMethod):
def __init__(self, config):
CGAbstractMethod.__init__(self, None, 'ResolveSystemBinding', 'bool',
[Argument('JSContext*', 'aCx'),
Argument('JS::Handle<JSObject*>', 'aObj'),
Argument('JS::Handle<jsid>', 'aId'),
Argument('JS::MutableHandle<JSObject*>',
'aObjp')])
self.config = config
def definition_body(self):
descriptors = self.config.getDescriptors(hasInterfaceObject=True,
isExposedInSystemGlobals=True,
register=True,
skipGen=False)
def descNameToId(name):
return "s%s_id" % name
jsidNames = [descNameToId(desc.name) for desc in descriptors]
jsidDecls = CGList(CGGeneric("static jsid %s;\n" % name)
for name in jsidNames)
jsidInits = CGList(
(CGIfWrapper(
CGGeneric("return false;\n"),
'!InternJSString(aCx, %s, "%s")' %
(descNameToId(desc.name), desc.interface.identifier.name))
for desc in descriptors),
"\n")
jsidInits.append(CGGeneric("idsInited = true;\n"))
jsidInits = CGIfWrapper(jsidInits, "!idsInited")
jsidInits = CGList([CGGeneric("static bool idsInited = false;\n"),
jsidInits])
definitions = CGList([], "\n")
for desc in descriptors:
bindingNS = toBindingNamespace(desc.name)
defineCode = "!%s::GetConstructorObject(aCx, aObj)" % bindingNS
defineCode = CGIfWrapper(CGGeneric("return false;\n"), defineCode)
defineCode = CGList([defineCode,
CGGeneric("aObjp.set(aObj);\n"),
CGGeneric("return true;\n")])
condition = "JSID_IS_VOID(aId) || aId == %s" % descNameToId(desc.name)
if desc.isExposedConditionally():
condition = "(%s) && %s::ConstructorEnabled(aCx, aObj)" % (condition, bindingNS)
definitions.append(CGIfWrapper(defineCode, condition))
return CGList([CGGeneric("MOZ_ASSERT(NS_IsMainThread());\n"),
jsidDecls,
jsidInits,
definitions,
CGGeneric("return true;\n")],
"\n").define()
class CGRegisterProtos(CGAbstractMethod):
def __init__(self, config):
CGAbstractMethod.__init__(self, None, 'Register', 'void',
@ -14341,7 +14398,6 @@ class GlobalGenRoots():
@staticmethod
def RegisterBindings(config):
# TODO - Generate the methods we want
curr = CGRegisterProtos(config)
# Wrap all of that in our namespaces.
@ -14371,7 +14427,6 @@ class GlobalGenRoots():
@staticmethod
def RegisterWorkerBindings(config):
# TODO - Generate the methods we want
curr = CGRegisterWorkerBindings(config)
# Wrap all of that in our namespaces.
@ -14395,6 +14450,35 @@ class GlobalGenRoots():
# Done.
return curr
@staticmethod
def ResolveSystemBinding(config):
curr = CGResolveSystemBinding(config)
# Wrap all of that in our namespaces.
curr = CGNamespace.build(['mozilla', 'dom'],
CGWrapper(curr, post='\n'))
curr = CGWrapper(curr, post='\n')
# Add the includes
defineIncludes = [CGHeaders.getDeclarationFilename(desc.interface)
for desc in config.getDescriptors(hasInterfaceObject=True,
register=True,
isExposedInSystemGlobals=True,
skipGen=False)]
defineIncludes.append("nsThreadUtils.h") # For NS_IsMainThread
defineIncludes.append("js/Id.h") # For jsid
defineIncludes.append("mozilla/dom/BindingUtils.h") # InternJSString
curr = CGHeaders([], [], [], [], [], defineIncludes,
'ResolveSystemBinding', curr)
# Add include guards.
curr = CGIncludeGuard('ResolveSystemBinding', curr)
# Done.
return curr
@staticmethod
def UnionTypes(config):

View File

@ -160,6 +160,9 @@ class Configuration:
elif key == 'isExposedInAnyWorker':
getter = lambda x: (not x.interface.isExternal() and
x.interface.isExposedInAnyWorker())
elif key == 'isExposedInSystemGlobals':
getter = lambda x: (not x.interface.isExternal() and
x.interface.isExposedInSystemGlobals())
else:
# Have to watch out: just closing over "key" is not enough,
# since we're about to mutate its value

View File

@ -132,6 +132,7 @@ class WebIDLCodegenManager(LoggingMixin):
'PrototypeList.h',
'RegisterBindings.h',
'RegisterWorkerBindings.h',
'ResolveSystemBinding.h',
'UnionConversions.h',
'UnionTypes.h',
}
@ -140,6 +141,7 @@ class WebIDLCodegenManager(LoggingMixin):
GLOBAL_DEFINE_FILES = {
'RegisterBindings.cpp',
'RegisterWorkerBindings.cpp',
'ResolveSystemBinding.cpp',
'UnionTypes.cpp',
'PrototypeList.cpp',
}

View File

@ -11,8 +11,10 @@
#include "nsIPrincipal.h"
#include "mozilla/dom/workers/Workers.h"
#include "mozilla/dom/ResolveSystemBinding.h"
using mozilla::dom::workers::ResolveWorkerClasses;
using mozilla::dom::ResolveSystemBinding;
NS_INTERFACE_MAP_BEGIN(BackstagePass)
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
@ -74,6 +76,14 @@ BackstagePass::NewResolve(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
}
*_retval = ResolveSystemBinding(cx, obj, id, &objp);
NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE);
if (objp) {
*objpArg = objp;
return NS_OK;
}
return NS_OK;
}
@ -90,6 +100,9 @@ BackstagePass::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
*_retval = ResolveWorkerClasses(cx, obj, JSID_VOIDHANDLE, &ignored);
NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE);
*_retval = ResolveSystemBinding(cx, obj, JSID_VOIDHANDLE, &ignored);
NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE);
return NS_OK;
}