Bug 722729. Expose a public API for LinkConstructorAndPrototype. r=bhackett

This commit is contained in:
Boris Zbarsky 2012-01-31 22:40:49 -05:00
parent 9334322db3
commit a16c2d5b2f
3 changed files with 16 additions and 8 deletions

View File

@ -3133,6 +3133,12 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
nargs, ps, fs, static_ps, static_fs);
}
JS_PUBLIC_API(JSBool)
JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto)
{
return LinkConstructorAndPrototype(cx, ctor, proto);
}
#ifdef JS_THREADSAFE
JS_PUBLIC_API(JSClass *)
JS_GetClass(JSContext *cx, JSObject *obj)

View File

@ -3645,6 +3645,13 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
JSPropertySpec *ps, JSFunctionSpec *fs,
JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
/*
* Set up ctor.prototype = proto and proto.constructor = ctor with the
* right property flags.
*/
extern JS_PUBLIC_API(JSBool)
JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto);
#ifdef JS_THREADSAFE
extern JS_PUBLIC_API(JSClass *)
JS_GetClass(JSContext *cx, JSObject *obj);

View File

@ -59,7 +59,6 @@ namespace dom {
namespace binding {
static jsid s_constructor_id = JSID_VOID;
static jsid s_prototype_id = JSID_VOID;
static jsid s_length_id = JSID_VOID;
@ -82,8 +81,7 @@ DefineStaticJSVals(JSContext *cx)
{
JSAutoRequest ar(cx);
return SET_JSID_TO_STRING(cx, constructor) &&
SET_JSID_TO_STRING(cx, prototype) &&
return SET_JSID_TO_STRING(cx, prototype) &&
SET_JSID_TO_STRING(cx, length) &&
DefinePropertyStaticJSVals(cx);
}
@ -452,13 +450,10 @@ ListBase<LC>::getPrototype(JSContext *cx, XPCWrappedNativeScope *scope)
}
JSObject *interface = JS_NewObject(cx, Jsvalify(&sInterfaceClass), NULL, global);
if (!interface ||
!JS_DefinePropertyById(cx, interface, s_prototype_id, OBJECT_TO_JSVAL(interfacePrototype),
nsnull, nsnull, JSPROP_PERMANENT | JSPROP_READONLY))
if (!interface)
return NULL;
if (!JS_DefinePropertyById(cx, interfacePrototype, s_constructor_id,
OBJECT_TO_JSVAL(interface), nsnull, nsnull, 0))
if (!JS_LinkConstructorAndPrototype(cx, interface, interfacePrototype))
return NULL;
if (!JS_DefineProperty(cx, global, sInterfaceClass.name, OBJECT_TO_JSVAL(interface), NULL,