Back out Bug 827486 for PGO bustage. CLOSED TREE
This commit is contained in:
@@ -10,7 +10,7 @@ import re
|
||||
import string
|
||||
|
||||
from WebIDL import BuiltinTypes, IDLBuiltinType, IDLNullValue, IDLSequenceType, IDLType
|
||||
from Configuration import NoSuchDescriptorError, getTypesFromDescriptor, getTypesFromDictionary, getTypesFromCallback, Descriptor
|
||||
from Configuration import NoSuchDescriptorError, getTypesFromDescriptor, getTypesFromDictionary, getTypesFromCallback
|
||||
|
||||
AUTOGENERATED_WARNING_COMMENT = \
|
||||
"/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
|
||||
@@ -476,9 +476,8 @@ class CGHeaders(CGWrapper):
|
||||
Generates the appropriate include statements.
|
||||
"""
|
||||
def __init__(self, descriptors, dictionaries, callbacks,
|
||||
callbackDescriptors,
|
||||
declareIncludes, defineIncludes, child,
|
||||
config=None, anyJSImplemented=False):
|
||||
callbackDescriptors, declareIncludes, defineIncludes, child,
|
||||
config=None):
|
||||
"""
|
||||
Builds a set of includes to cover |descriptors|.
|
||||
|
||||
@@ -587,7 +586,7 @@ class CGHeaders(CGWrapper):
|
||||
# And we need BindingUtils.h so we can wrap "this" objects
|
||||
declareIncludes.add("mozilla/dom/BindingUtils.h")
|
||||
|
||||
if len(callbackDescriptors) != 0 or anyJSImplemented:
|
||||
if len(callbackDescriptors) != 0:
|
||||
# We need CallbackInterface to serve as our parent class
|
||||
declareIncludes.add("mozilla/dom/CallbackInterface.h")
|
||||
# And we need BindingUtils.h so we can wrap "this" objects
|
||||
@@ -7076,8 +7075,7 @@ class CGBindingRoot(CGThing):
|
||||
workers=True)
|
||||
callbackDescriptors = config.getDescriptors(webIDLFile=webIDLFile,
|
||||
isCallback=True)
|
||||
jsImplemented = config.getDescriptors(webIDLFile=webIDLFile,
|
||||
isJSImplemented=True)
|
||||
|
||||
forwardDeclares = [CGClassForwardDeclare('XPCWrappedNativeScope')]
|
||||
|
||||
descriptorsForForwardDeclaration = list(descriptors)
|
||||
@@ -7231,11 +7229,6 @@ class CGBindingRoot(CGThing):
|
||||
# Do codegen for all the callback interfaces
|
||||
cgthings.extend([CGCallbackInterface(x) for x in callbackDescriptors])
|
||||
|
||||
# Do codegen for JS implemented classes
|
||||
for x in jsImplemented:
|
||||
cgthings.append(CGCallbackInterface(x))
|
||||
cgthings.append(CGJSImplClass(x))
|
||||
|
||||
# And make sure we have the right number of newlines at the end
|
||||
curr = CGWrapper(CGList(cgthings, "\n\n"), post="\n\n")
|
||||
|
||||
@@ -7274,8 +7267,7 @@ class CGBindingRoot(CGThing):
|
||||
'nsDOMQS.h'
|
||||
],
|
||||
curr,
|
||||
config,
|
||||
anyJSImplemented = len(jsImplemented) != 0)
|
||||
config)
|
||||
|
||||
# Add include guards.
|
||||
curr = CGIncludeGuard(prefix, curr)
|
||||
@@ -7629,7 +7621,7 @@ class CGNativeMember(ClassMethod):
|
||||
|
||||
|
||||
class CGExampleMethod(CGNativeMember):
|
||||
def __init__(self, descriptor, method, signature, isConstructor, breakAfter=True):
|
||||
def __init__(self, descriptor, method, signature, breakAfter=True):
|
||||
CGNativeMember.__init__(self, descriptor, method,
|
||||
CGSpecializedMethod.makeNativeName(descriptor,
|
||||
method),
|
||||
@@ -7663,45 +7655,38 @@ class CGExampleSetter(CGNativeMember):
|
||||
def define(self, cgClass):
|
||||
return ''
|
||||
|
||||
class CGBindingImplClass(CGClass):
|
||||
class CGExampleClass(CGClass):
|
||||
"""
|
||||
Common codegen for generating a C++ implementation of a WebIDL interface
|
||||
Codegen for the actual example class implemenation for this descriptor
|
||||
"""
|
||||
def __init__(self, descriptor, cgMethod, cgGetter, cgSetter):
|
||||
"""
|
||||
cgMethod, cgGetter and cgSetter are classes used to codegen methods,
|
||||
getters and setters.
|
||||
"""
|
||||
def __init__(self, descriptor):
|
||||
self.descriptor = descriptor
|
||||
self._deps = descriptor.interface.getDeps()
|
||||
|
||||
iface = descriptor.interface
|
||||
|
||||
self.methodDecls = []
|
||||
def appendMethod(m, isConstructor=False):
|
||||
methodDecls = []
|
||||
def appendMethod(m):
|
||||
sigs = m.signatures()
|
||||
for s in sigs[:-1]:
|
||||
# Don't put an empty line after overloads, until we
|
||||
# get to the last one.
|
||||
self.methodDecls.append(cgMethod(descriptor, m, s,
|
||||
isConstructor,
|
||||
breakAfter=False))
|
||||
self.methodDecls.append(cgMethod(descriptor, m, sigs[-1],
|
||||
isConstructor))
|
||||
methodDecls.append(CGExampleMethod(descriptor, m, s,
|
||||
breakAfter=False))
|
||||
methodDecls.append(CGExampleMethod(descriptor, m, sigs[-1]))
|
||||
|
||||
if iface.ctor():
|
||||
appendMethod(iface.ctor(), isConstructor=True)
|
||||
appendMethod(iface.ctor())
|
||||
for n in iface.namedConstructors:
|
||||
appendMethod(n, isConstructor=True)
|
||||
appendMethod(n)
|
||||
for m in iface.members:
|
||||
if m.isMethod():
|
||||
if m.isIdentifierLess():
|
||||
continue
|
||||
appendMethod(m)
|
||||
elif m.isAttr():
|
||||
self.methodDecls.append(cgGetter(descriptor, m))
|
||||
methodDecls.append(CGExampleGetter(descriptor, m))
|
||||
if not m.readonly:
|
||||
self.methodDecls.append(cgSetter(descriptor, m))
|
||||
methodDecls.append(CGExampleSetter(descriptor, m))
|
||||
|
||||
# Now do the special operations
|
||||
def appendSpecialOperation(name, op):
|
||||
@@ -7734,7 +7719,7 @@ class CGBindingImplClass(CGClass):
|
||||
else:
|
||||
# We already added this method
|
||||
return
|
||||
self.methodDecls.append(
|
||||
methodDecls.append(
|
||||
CGNativeMember(descriptor, op,
|
||||
name,
|
||||
(returnType, args),
|
||||
@@ -7747,7 +7732,7 @@ class CGBindingImplClass(CGClass):
|
||||
# If we support indexed properties, then we need a Length()
|
||||
# method so we know which indices are supported.
|
||||
if descriptor.supportsIndexedProperties():
|
||||
self.methodDecls.append(
|
||||
methodDecls.append(
|
||||
CGNativeMember(descriptor, FakeMember(),
|
||||
"Length",
|
||||
(BuiltinTypes[IDLBuiltinType.Types.unsigned_long],
|
||||
@@ -7756,7 +7741,7 @@ class CGBindingImplClass(CGClass):
|
||||
# And if we support named properties we need to be able to
|
||||
# enumerate the supported names.
|
||||
if descriptor.supportsNamedProperties():
|
||||
self.methodDecls.append(
|
||||
methodDecls.append(
|
||||
CGNativeMember(
|
||||
descriptor, FakeMember(),
|
||||
"GetSupportedNames",
|
||||
@@ -7767,41 +7752,18 @@ class CGBindingImplClass(CGClass):
|
||||
|
||||
wrapArgs = [Argument('JSContext*', 'aCx'),
|
||||
Argument('JSObject*', 'aScope')]
|
||||
self.methodDecls.insert(0,
|
||||
ClassMethod("WrapObject", "JSObject*",
|
||||
wrapArgs, virtual=descriptor.wrapperCache,
|
||||
breakAfterReturnDecl=" ",
|
||||
body=self.getWrapObjectBody()))
|
||||
self.methodDecls.insert(0,
|
||||
ClassMethod("GetParentObject",
|
||||
self.getGetParentObjectReturnType(),
|
||||
[], const=True,
|
||||
breakAfterReturnDecl=" ",
|
||||
body=self.getGetParentObjectBody()))
|
||||
|
||||
# Invoke CGClass.__init__ in any subclasses afterwards to do the actual codegen.
|
||||
|
||||
def getWrapObjectBody(self):
|
||||
return None
|
||||
|
||||
def getGetParentObjectReturnType(self):
|
||||
return ("// TODO: return something sensible here, and change the return type\n"
|
||||
"%s*" % self.descriptor.name)
|
||||
|
||||
def getGetParentObjectBody(self):
|
||||
return None
|
||||
|
||||
def deps(self):
|
||||
return self._deps
|
||||
|
||||
|
||||
class CGExampleClass(CGBindingImplClass):
|
||||
"""
|
||||
Codegen for the actual example class implementation for this descriptor
|
||||
"""
|
||||
def __init__(self, descriptor):
|
||||
CGBindingImplClass.__init__(self, descriptor, CGExampleMethod, CGExampleGetter, CGExampleSetter)
|
||||
|
||||
methodDecls.insert(0,
|
||||
ClassMethod("WrapObject", "JSObject*",
|
||||
wrapArgs, virtual=descriptor.wrapperCache,
|
||||
breakAfterReturnDecl=" "))
|
||||
getParentObjectReturnType = (
|
||||
"// TODO: return something sensible here, and change the return type\n"
|
||||
"%s*" % descriptor.name)
|
||||
methodDecls.insert(0,
|
||||
ClassMethod("GetParentObject",
|
||||
getParentObjectReturnType,
|
||||
[], const=True,
|
||||
breakAfterReturnDecl=" "))
|
||||
extradeclarations=(
|
||||
"public:\n"
|
||||
" NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n"
|
||||
@@ -7814,7 +7776,7 @@ class CGExampleClass(CGBindingImplClass):
|
||||
constructors=[ClassConstructor([],
|
||||
visibility="public")],
|
||||
destructor=ClassDestructor(visibility="public"),
|
||||
methods=self.methodDecls,
|
||||
methods=methodDecls,
|
||||
decorators="MOZ_FINAL",
|
||||
extradeclarations=extradeclarations)
|
||||
|
||||
@@ -7907,158 +7869,6 @@ class CGExampleRoot(CGThing):
|
||||
def define(self):
|
||||
return self.root.define()
|
||||
|
||||
|
||||
def jsImplName(name):
|
||||
return name + "JSImpl"
|
||||
|
||||
class CGJSImplMethod(CGNativeMember):
|
||||
def __init__(self, descriptor, method, signature, isConstructor, breakAfter=True):
|
||||
CGNativeMember.__init__(self, descriptor, method,
|
||||
CGSpecializedMethod.makeNativeName(descriptor,
|
||||
method),
|
||||
signature,
|
||||
descriptor.getExtendedAttributes(method),
|
||||
breakAfter=breakAfter,
|
||||
variadicIsSequence=True)
|
||||
self.signature = signature
|
||||
if isConstructor:
|
||||
self.body = self.getConstructorImpl()
|
||||
else:
|
||||
self.body = self.getImpl()
|
||||
|
||||
def getImpl(self):
|
||||
callbackArgs = [arg.name for arg in self.getArgs(self.signature[0], self.signature[1])]
|
||||
return 'return mImpl->%s(%s);' % (self.name, ", ".join(callbackArgs))
|
||||
|
||||
def getConstructorImpl(self):
|
||||
assert self.descriptor.interface.isJSImplemented()
|
||||
if self.name != 'Constructor':
|
||||
raise TypeError("Named constructors are not supported for JS implemented WebIDL. See bug 851287.")
|
||||
if len(self.signature[1]) != 0:
|
||||
raise TypeError("Constructors with arguments are unsupported. See bug 851178.")
|
||||
|
||||
return string.Template(
|
||||
""" // Get the window to use as a parent.
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global.Get());
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
// Get the JS implementation for the WebIDL interface.
|
||||
nsCOMPtr<nsISupports> implISupports = do_CreateInstance("${contractId}");
|
||||
MOZ_ASSERT(implISupports, "Failed to get JS implementation instance from contract ID.");
|
||||
if (!implISupports) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> implWrapped = do_QueryInterface(implISupports);
|
||||
MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component.");
|
||||
if (!implWrapped) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
JSObject* jsImplObj;
|
||||
if (NS_FAILED(implWrapped->GetJSObject(&jsImplObj))) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
// Construct the callback interface object.
|
||||
bool initOk;
|
||||
nsRefPtr<${callbackClass}> cbImpl = new ${callbackClass}(cx, nullptr, jsImplObj, &initOk);
|
||||
if (!initOk) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
// Build the actual implementation.
|
||||
nsRefPtr<${implClass}> impl = new ${implClass}(cbImpl, window);
|
||||
return impl.forget();""").substitute({"implClass" : self.descriptor.name,
|
||||
"callbackClass" : jsImplName(self.descriptor.name),
|
||||
"contractId" : self.descriptor.interface.getJSImplementation()
|
||||
})
|
||||
|
||||
# We're always fallible
|
||||
def callbackGetterName(attr):
|
||||
return "Get" + MakeNativeName(attr.identifier.name)
|
||||
|
||||
def callbackSetterName(attr):
|
||||
return "Set" + MakeNativeName(attr.identifier.name)
|
||||
|
||||
class CGJSImplGetter(CGNativeMember):
|
||||
def __init__(self, descriptor, attr):
|
||||
CGNativeMember.__init__(self, descriptor, attr,
|
||||
CGSpecializedGetter.makeNativeName(descriptor,
|
||||
attr),
|
||||
(attr.type, []),
|
||||
descriptor.getExtendedAttributes(attr,
|
||||
getter=True))
|
||||
self.body = self.getImpl()
|
||||
|
||||
def getImpl(self):
|
||||
callbackArgs = [arg.name for arg in self.getArgs(self.member.type, [])]
|
||||
return 'return mImpl->%s(%s);' % (callbackGetterName(self.member), ", ".join(callbackArgs))
|
||||
|
||||
class CGJSImplSetter(CGNativeMember):
|
||||
def __init__(self, descriptor, attr):
|
||||
CGNativeMember.__init__(self, descriptor, attr,
|
||||
CGSpecializedSetter.makeNativeName(descriptor,
|
||||
attr),
|
||||
(BuiltinTypes[IDLBuiltinType.Types.void],
|
||||
[FakeArgument(attr.type, attr)]),
|
||||
descriptor.getExtendedAttributes(attr,
|
||||
setter=True))
|
||||
self.body = self.getImpl()
|
||||
|
||||
def getImpl(self):
|
||||
callbackArgs = [arg.name for arg in self.getArgs(BuiltinTypes[IDLBuiltinType.Types.void],
|
||||
[FakeArgument(self.member.type, self.member)])]
|
||||
return 'mImpl->%s(%s);' % (callbackSetterName(self.member), ", ".join(callbackArgs))
|
||||
|
||||
class CGJSImplClass(CGBindingImplClass):
|
||||
def __init__(self, descriptor):
|
||||
CGBindingImplClass.__init__(self, descriptor, CGJSImplMethod, CGJSImplGetter, CGJSImplSetter)
|
||||
|
||||
extradeclarations=(
|
||||
"public:\n"
|
||||
" NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n"
|
||||
" NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(%s)\n"
|
||||
"\n"
|
||||
"private:\n"
|
||||
" nsRefPtr<%s> mImpl;\n"
|
||||
" nsCOMPtr<nsISupports> mParent;\n"
|
||||
"\n" % (descriptor.name, jsImplName(descriptor.name)))
|
||||
|
||||
extradefinitions= string.Template(
|
||||
"NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(${ifaceName}, mImpl, mParent)\n"
|
||||
"NS_IMPL_CYCLE_COLLECTING_ADDREF(${ifaceName})\n"
|
||||
"NS_IMPL_CYCLE_COLLECTING_RELEASE(${ifaceName})\n"
|
||||
"NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(${ifaceName})\n"
|
||||
" NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY\n"
|
||||
" NS_INTERFACE_MAP_ENTRY(nsISupports)\n"
|
||||
"NS_INTERFACE_MAP_END\n").substitute({ "ifaceName": self.descriptor.name })
|
||||
|
||||
CGClass.__init__(self, descriptor.name,
|
||||
bases=[ClassBase("nsISupports"),
|
||||
ClassBase("nsWrapperCache")],
|
||||
constructors=[ClassConstructor([Argument(jsImplName(descriptor.name) + "*", "aImpl"),
|
||||
Argument("nsISupports*", "aParent")],
|
||||
visibility="public",
|
||||
baseConstructors=["mImpl(aImpl)",
|
||||
"mParent(aParent)"],
|
||||
body="SetIsDOMBinding();")],
|
||||
methods=self.methodDecls,
|
||||
decorators="MOZ_FINAL",
|
||||
extradeclarations=extradeclarations,
|
||||
extradefinitions=extradefinitions)
|
||||
|
||||
def getWrapObjectBody(self):
|
||||
return "return %sBinding::Wrap(aCx, aScope, this);" % self.descriptor.name
|
||||
|
||||
def getGetParentObjectReturnType(self):
|
||||
return "nsISupports*"
|
||||
|
||||
def getGetParentObjectBody(self):
|
||||
return "return mParent;"
|
||||
|
||||
class CGCallback(CGClass):
|
||||
def __init__(self, idlObject, descriptorProvider, baseName, methods,
|
||||
getters=[], setters=[]):
|
||||
@@ -8067,8 +7877,6 @@ class CGCallback(CGClass):
|
||||
name = idlObject.identifier.name
|
||||
if descriptorProvider.workers:
|
||||
name += "Workers"
|
||||
if isinstance(descriptorProvider, Descriptor) and descriptorProvider.interface.isJSImplemented():
|
||||
name = jsImplName(name)
|
||||
# For our public methods that needThisHandling we want most of the
|
||||
# same args and the same return type as what CallbackMember
|
||||
# generates. So we want to take advantage of all its
|
||||
@@ -8231,7 +8039,7 @@ class CallbackMember(CGNativeMember):
|
||||
# will handle generating public versions that handle the "this" stuff.
|
||||
visibility = "private" if needThisHandling else "public"
|
||||
# We don't care, for callback codegen, whether our original member was
|
||||
# a method or attribute or whatnot. Just always pass FakeMember()
|
||||
# a method or attribure or whatnot. Just always pass FakeMember()
|
||||
# here.
|
||||
CGNativeMember.__init__(self, descriptorProvider, FakeMember(),
|
||||
name, (self.retvalType, args),
|
||||
@@ -8501,7 +8309,8 @@ class CallbackGetter(CallbackMember):
|
||||
self.attrName = attr.identifier.name
|
||||
CallbackMember.__init__(self,
|
||||
(attr.type, []),
|
||||
callbackGetterName(attr),
|
||||
# We're always fallible
|
||||
"Get" + MakeNativeName(attr.identifier.name),
|
||||
descriptor,
|
||||
needThisHandling=False)
|
||||
|
||||
@@ -8526,7 +8335,7 @@ class CallbackSetter(CallbackMember):
|
||||
CallbackMember.__init__(self,
|
||||
(BuiltinTypes[IDLBuiltinType.Types.void],
|
||||
[FakeArgument(attr.type, attr)]),
|
||||
callbackSetterName(attr),
|
||||
"Set" + MakeNativeName(attr.identifier.name),
|
||||
descriptor,
|
||||
needThisHandling=False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user