Bug 816376. Create vanilla objects for the interface object of callback interfaces. r=peterv

This commit is contained in:
Boris Zbarsky 2012-12-06 15:21:18 -05:00
parent f0b49397bb
commit b3142f98f8
3 changed files with 26 additions and 9 deletions

View File

@ -221,12 +221,18 @@ CreateInterfaceObject(JSContext* cx, JSObject* global,
const char* name)
{
JSObject* constructor;
bool isCallbackInterface = constructorClass == js::Jsvalify(&js::ObjectClass);
if (constructorClass) {
JSObject* functionProto = JS_GetFunctionPrototype(cx, global);
if (!functionProto) {
JSObject* constructorProto;
if (isCallbackInterface) {
constructorProto = JS_GetObjectPrototype(cx, global);
} else {
constructorProto = JS_GetFunctionPrototype(cx, global);
}
if (!constructorProto) {
return NULL;
}
constructor = JS_NewObject(cx, constructorClass, functionProto, global);
constructor = JS_NewObject(cx, constructorClass, constructorProto, global);
} else {
MOZ_ASSERT(constructorNative);
JSFunction* fun = js::NewFunctionWithReserved(cx, Constructor, ctorNargs,
@ -244,7 +250,9 @@ CreateInterfaceObject(JSContext* cx, JSObject* global,
return NULL;
}
if (constructorClass) {
if (constructorClass && !isCallbackInterface) {
// Have to shadow Function.prototype.toString, since that throws
// on things that are not js::FunctionClass.
JSFunction* toString = js::DefineFunctionWithReserved(cx, constructor,
"toString",
InterfaceObjectToString,

View File

@ -1463,9 +1463,11 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
" return;\n" +
"}\n") % getParentProto
needConstructor = (needInterfaceObject and
not self.descriptor.hasInstanceInterface)
constructHook = "&" + CONSTRUCT_HOOK_NAME + "_holder"
if (needInterfaceObject and
self.descriptor.needsConstructHookHolder()):
constructHookHolder = "&" + CONSTRUCT_HOOK_NAME + "_holder"
else:
constructHookHolder = "nullptr"
if self.descriptor.interface.ctor():
constructArgs = methodLength(self.descriptor.interface.ctor())
else:
@ -1480,6 +1482,8 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
if needInterfaceObject:
if self.descriptor.hasInstanceInterface:
interfaceClass = "&InterfaceObjectClass.mBase"
elif self.descriptor.interface.isCallback():
interfaceClass = "js::Jsvalify(&js::ObjectClass)"
else:
interfaceClass = "nullptr"
interfaceCache = "&protoAndIfaceArray[constructors::id::%s]" % self.descriptor.name
@ -1512,7 +1516,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
" %s,\n"
" %s);" % (
protoClass, protoCache,
interfaceClass, constructHook if needConstructor else "nullptr",
interfaceClass, constructHookHolder,
constructArgs, interfaceCache,
domClass,
properties,
@ -6153,7 +6157,8 @@ class CGDescriptor(CGThing):
cgThings.append(CGClassConstructHook(descriptor))
cgThings.append(CGClassHasInstanceHook(descriptor))
cgThings.append(CGInterfaceObjectJSClass(descriptor, properties))
cgThings.append(CGClassConstructHookHolder(descriptor))
if descriptor.needsConstructHookHolder():
cgThings.append(CGClassConstructHookHolder(descriptor))
if descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGPrototypeJSClass(descriptor, properties))

View File

@ -390,3 +390,7 @@ class Descriptor(DescriptorProvider):
def supportsNamedProperties(self):
return self.operations['NamedGetter'] is not None
def needsConstructHookHolder(self):
assert self.interface.hasInterfaceObject()
return not self.hasInstanceInterface and not self.interface.isCallback()