Bug 827486, part 6 - generate headers and code for JS implemented WebIDL classes. r=bz

This commit is contained in:
Andrew McCreight 2013-03-18 16:05:51 -07:00
Родитель 45987003c3
Коммит b605a583db
3 изменённых файлов: 20 добавлений и 8 удалений

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

@ -10,7 +10,7 @@ import re
import string
from WebIDL import BuiltinTypes, IDLBuiltinType, IDLNullValue, IDLSequenceType, IDLType
from Configuration import NoSuchDescriptorError, getTypesFromDescriptor, getTypesFromDictionary, getTypesFromCallback
from Configuration import NoSuchDescriptorError, getTypesFromDescriptor, getTypesFromDictionary, getTypesFromCallback, Descriptor
AUTOGENERATED_WARNING_COMMENT = \
"/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
@ -476,8 +476,9 @@ class CGHeaders(CGWrapper):
Generates the appropriate include statements.
"""
def __init__(self, descriptors, dictionaries, callbacks,
callbackDescriptors, declareIncludes, defineIncludes, child,
config=None):
callbackDescriptors,
declareIncludes, defineIncludes, child,
config=None, anyJSImplemented=False):
"""
Builds a set of includes to cover |descriptors|.
@ -586,7 +587,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:
if len(callbackDescriptors) != 0 or anyJSImplemented:
# 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
@ -7075,7 +7076,8 @@ 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)
@ -7229,6 +7231,11 @@ 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")
@ -7267,7 +7274,8 @@ class CGBindingRoot(CGThing):
'nsDOMQS.h'
],
curr,
config)
config,
anyJSImplemented = len(jsImplemented) != 0)
# Add include guards.
curr = CGIncludeGuard(prefix, curr)
@ -8059,6 +8067,8 @@ 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

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

@ -113,6 +113,8 @@ class Configuration:
getter = lambda x: x.interface.isCallback()
elif key == 'isExternal':
getter = lambda x: x.interface.isExternal()
elif key == 'isJSImplemented':
getter = lambda x: x.interface.isJSImplemented()
else:
getter = lambda x: getattr(x, key)
curr = filter(lambda x: getter(x) == val, curr)
@ -213,7 +215,7 @@ class Descriptor(DescriptorProvider):
# Do something sane for JSObject
if self.nativeType == "JSObject":
headerDefault = "jsapi.h"
elif self.interface.isCallback():
elif self.interface.isCallback() or self.interface.isJSImplemented():
# 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

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

@ -779,7 +779,7 @@ class IDLInterface(IDLObjectWithScope):
return self._callback
def isSingleOperationInterface(self):
assert self.isCallback()
assert self.isCallback() or self.isJSImplemented()
return (
# Not inheriting from another interface
not self.parent and