mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Bug 983261. Improve example codegen for non-leaf and non-root interfaces. r=khuey
This commit is contained in:
parent
20d2acf564
commit
7627aed509
@ -10568,25 +10568,92 @@ class CGExampleClass(CGBindingImplClass):
|
||||
def __init__(self, descriptor):
|
||||
CGBindingImplClass.__init__(self, descriptor, CGExampleMethod, CGExampleGetter, CGExampleSetter)
|
||||
|
||||
extradeclarations=(
|
||||
"public:\n"
|
||||
" NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n"
|
||||
" NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(%s)\n"
|
||||
"\n" % descriptor.nativeType.split('::')[-1])
|
||||
self.refcounted = descriptor.nativeOwnership == "refcounted"
|
||||
|
||||
CGClass.__init__(self, descriptor.nativeType.split('::')[-1],
|
||||
bases=[ClassBase("nsISupports /* Change nativeOwnership in the binding configuration if you don't want this */"),
|
||||
ClassBase("nsWrapperCache /* Change wrapperCache in the binding configuration if you don't want this */")],
|
||||
self.parentIface = descriptor.interface.parent
|
||||
if self.parentIface:
|
||||
self.parentDesc = descriptor.getDescriptor(
|
||||
self.parentIface.identifier.name)
|
||||
bases = [ClassBase(self.nativeLeafName(self.parentDesc))]
|
||||
else:
|
||||
bases = []
|
||||
if self.refcounted:
|
||||
bases.append(ClassBase("nsISupports /* Change nativeOwnership in the binding configuration if you don't want this */"))
|
||||
if descriptor.wrapperCache:
|
||||
bases.append(ClassBase("nsWrapperCache /* Change wrapperCache in the binding configuration if you don't want this */"))
|
||||
else:
|
||||
bases.append(ClassBase("NonRefcountedDOMObject"))
|
||||
|
||||
if self.refcounted:
|
||||
if self.parentIface:
|
||||
extradeclarations=(
|
||||
"public:\n"
|
||||
" NS_DECL_ISUPPORTS_INHERITED\n"
|
||||
" NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(%s, %s)\n"
|
||||
"\n" % (self.nativeLeafName(descriptor),
|
||||
self.nativeLeafName(self.parentDesc)))
|
||||
else:
|
||||
extradeclarations=(
|
||||
"public:\n"
|
||||
" NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n"
|
||||
" NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(%s)\n"
|
||||
"\n" % self.nativeLeafName(descriptor))
|
||||
else:
|
||||
extradeclarations=""
|
||||
|
||||
if descriptor.interface.hasChildInterfaces():
|
||||
decorators = ""
|
||||
else:
|
||||
decorators = "MOZ_FINAL"
|
||||
|
||||
CGClass.__init__(self, self.nativeLeafName(descriptor),
|
||||
bases=bases,
|
||||
constructors=[ClassConstructor([],
|
||||
visibility="public")],
|
||||
destructor=ClassDestructor(visibility="public"),
|
||||
methods=self.methodDecls,
|
||||
decorators="MOZ_FINAL",
|
||||
decorators=decorators,
|
||||
extradeclarations=extradeclarations)
|
||||
|
||||
def define(self):
|
||||
# Just override CGClass and do our own thing
|
||||
classImpl = """
|
||||
if self.descriptor.wrapperCache:
|
||||
setDOMBinding = " SetIsDOMBinding();\n"
|
||||
else:
|
||||
setDOMBinding = ""
|
||||
if self.refcounted:
|
||||
ctordtor = """${nativeType}::${nativeType}()
|
||||
{
|
||||
%s}
|
||||
|
||||
${nativeType}::~${nativeType}()
|
||||
{
|
||||
}
|
||||
""" % setDOMBinding
|
||||
else:
|
||||
ctordtor = """${nativeType}::${nativeType}()
|
||||
{
|
||||
MOZ_COUNT_CTOR(${nativeType});
|
||||
}
|
||||
|
||||
${nativeType}::~${nativeType}()
|
||||
{
|
||||
MOZ_COUNT_DTOR(${nativeType});
|
||||
}
|
||||
"""
|
||||
|
||||
if self.refcounted:
|
||||
if self.parentIface:
|
||||
classImpl = """
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED_0(${nativeType}, ${parentType})
|
||||
NS_IMPL_ADDREF_INHERITED(${nativeType}, ${parentType})
|
||||
NS_IMPL_RELEASE_INHERITED(${nativeType}, ${parentType})
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(${nativeType})
|
||||
NS_INTERFACE_MAP_END_INHERITING(${parentType})
|
||||
|
||||
"""
|
||||
else:
|
||||
classImpl = """
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(${nativeType})
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(${nativeType})
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(${nativeType})
|
||||
@ -10595,27 +10662,28 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(${nativeType})
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
${nativeType}::${nativeType}()
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
${nativeType}::~${nativeType}()
|
||||
{
|
||||
}
|
||||
"""
|
||||
else:
|
||||
classImpl = ""
|
||||
|
||||
classImpl += """%s
|
||||
JSObject*
|
||||
${nativeType}::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
{
|
||||
return ${ifaceName}Binding::Wrap(aCx, aScope, this);
|
||||
}
|
||||
|
||||
"""
|
||||
""" % ctordtor
|
||||
return string.Template(classImpl).substitute(
|
||||
{ "ifaceName": self.descriptor.name,
|
||||
"nativeType": self.descriptor.nativeType.split('::')[-1] }
|
||||
"nativeType": self.nativeLeafName(self.descriptor),
|
||||
"parentType": self.nativeLeafName(self.parentDesc) if self.parentIface else "",
|
||||
}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def nativeLeafName(descriptor):
|
||||
return descriptor.nativeType.split('::')[-1]
|
||||
|
||||
class CGExampleRoot(CGThing):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user