Bug 1270601 part 2. Add codegen support for IDL namespaces. r=peterv

This commit is contained in:
Boris Zbarsky 2016-06-02 10:34:39 -04:00
Родитель 7e52059153
Коммит 98b4dca6e9
6 изменённых файлов: 75 добавлений и 6 удалений

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

@ -1901,6 +1901,17 @@ DOMInterfaces = {
'headerFile': 'TestBindingHeader.h',
'register': False
},
'TestNamespace' : {
'headerFile': 'TestBindingHeader.h',
'register': False,
},
'TestRenamedNamespace' : {
'headerFile': 'TestBindingHeader.h',
'register': False,
},
}
# These are temporary, until they've been converted to use new DOM bindings

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

@ -638,11 +638,15 @@ def InterfaceObjectProtoGetter(descriptor):
"""
parentInterface = descriptor.interface.parent
if parentInterface:
assert not descriptor.interface.isNamespace()
parentIfaceName = parentInterface.identifier.name
parentDesc = descriptor.getDescriptor(parentIfaceName)
prefix = toBindingNamespace(parentDesc.name)
protoGetter = prefix + "::GetConstructorObject"
protoHandleGetter = prefix + "::GetConstructorObjectHandle"
elif descriptor.interface.isNamespace():
protoGetter = "JS_GetObjectPrototype"
protoHandleGetter = None
else:
protoGetter = "JS_GetFunctionPrototype"
protoHandleGetter = None
@ -661,7 +665,10 @@ class CGInterfaceObjectJSClass(CGThing):
def define(self):
if self.descriptor.interface.ctor():
assert not self.descriptor.interface.isNamespace()
ctorname = CONSTRUCT_HOOK_NAME
elif self.descriptor.interface.isNamespace():
ctorname = "nullptr"
else:
ctorname = "ThrowingConstructor"
if NeedsGeneratedHasInstance(self.descriptor):
@ -680,6 +687,9 @@ class CGInterfaceObjectJSClass(CGThing):
if ctorname == "ThrowingConstructor" and hasinstance == "InterfaceHasInstance":
ret = ""
classOpsPtr = "&sBoringInterfaceObjectClassClassOps"
elif ctorname == "nullptr" and hasinstance == "nullptr":
ret = ""
classOpsPtr = "JS_NULL_CLASS_OPS"
else:
ret = fill(
"""
@ -703,33 +713,51 @@ class CGInterfaceObjectJSClass(CGThing):
hasInstance=hasinstance)
classOpsPtr = "&sInterfaceObjectClassOps"
if self.descriptor.interface.isNamespace():
classString = self.descriptor.interface.getExtendedAttribute("ClassString")
if classString is None:
classString = "Object"
else:
classString = classString[0]
toStringResult = "[object %s]" % classString
objectOps = "JS_NULL_OBJECT_OPS"
else:
classString = "Function"
toStringResult = ("function %s() {\\n [native code]\\n}" %
self.descriptor.interface.identifier.name)
# We need non-default ObjectOps so we can actually make
# use of our toStringResult.
objectOps = "&sInterfaceObjectClassObjectOps"
ret = ret + fill(
"""
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
{
"Function",
"${classString}",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(${slotCount}),
${classOpsPtr},
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
&sInterfaceObjectClassObjectOps
${objectOps}
},
eInterface,
${prototypeID},
${depth},
${hooks},
"function ${name}() {\\n [native code]\\n}",
"${toStringResult}",
${protoGetter}
};
""",
classString=classString,
slotCount=slotCount,
ctorname=ctorname,
hasInstance=hasinstance,
classOpsPtr=classOpsPtr,
hooks=NativePropertyHooks(self.descriptor),
name=self.descriptor.interface.identifier.name,
objectOps=objectOps,
prototypeID=prototypeID,
depth=depth,
toStringResult=toStringResult,
protoGetter=protoGetter)
return ret

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

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from WebIDL import IDLInterface, IDLExternalInterface, IDLImplementsStatement
from WebIDL import IDLImplementsStatement
import os
from collections import defaultdict
@ -53,7 +53,7 @@ class Configuration:
assert not thing.isType()
if not thing.isInterface():
if not thing.isInterface() and not thing.isNamespace():
continue
iface = thing
self.interfaces[iface.identifier.name] = iface
@ -433,6 +433,7 @@ class Descriptor(DescriptorProvider):
# them as having a concrete descendant.
self.concrete = (not self.interface.isExternal() and
not self.interface.isCallback() and
not self.interface.isNamespace() and
desc.get('concrete', True))
self.hasUnforgeableMembers = (self.concrete and
any(MemberIsUnforgeable(m, self) for m in

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

@ -1759,6 +1759,12 @@ class IDLNamespace(IDLInterfaceOrNamespace):
if identifier == "Exposed":
convertExposedAttrToGlobalNameSet(attr,
self._exposureGlobalNames)
elif identifier == "ClassString":
# Takes a string value to override the default "Object" if
# desired.
if not attr.hasValue():
raise WebIDLError("[%s] must have a value" % identifier,
[attr.location])
else:
raise WebIDLError("Unknown extended attribute %s on namespace" %
identifier,

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

@ -1424,6 +1424,16 @@ public:
virtual nsISupports* GetParentObject();
};
class TestNamespace {
public:
static bool Foo(const GlobalObject&);
static int32_t Bar(const GlobalObject&);
static void Baz(const GlobalObject&);
};
class TestRenamedNamespace {
};
} // namespace dom
} // namespace mozilla

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

@ -1217,6 +1217,19 @@ interface TestDeprecatedInterface {
interface TestInterfaceWithPromiseConstructorArg {
};
namespace TestNamespace {
readonly attribute boolean foo;
long bar();
};
partial namespace TestNamespace {
void baz();
};
[ClassString="RenamedNamespaceClassName"]
namespace TestRenamedNamespace {
};
[SecureContext]
interface TestSecureContextInterface {
static void alsoSecureContext();