Bug 966845 - Make ensureConstructor and initConstructor static. r=Waldo

This commit is contained in:
Bobby Holley 2014-02-05 13:50:21 -08:00
parent ec8f21dd23
commit 3493cfbdb3
4 changed files with 31 additions and 30 deletions

View File

@ -1304,7 +1304,9 @@ JS_ResolveStandardClass(JSContext *cx, HandleObject obj, HandleId id, bool *reso
if (stdnm->clasp->flags & JSCLASS_IS_ANONYMOUS)
return true;
if (!obj->as<GlobalObject>().ensureConstructor(cx, JSCLASS_CACHED_PROTO_KEY(stdnm->clasp)))
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(stdnm->clasp);
if (!GlobalObject::ensureConstructor(cx, global, key))
return false;
*resolved = true;

View File

@ -3250,7 +3250,7 @@ MaybeResolveConstructor(ExclusiveContext *cxArg, Handle<GlobalObject*> global, J
AutoResolving resolving(cx, global, name);
if (resolving.alreadyStarted())
return true;
return global->ensureConstructor(cx, key);
return GlobalObject::ensureConstructor(cx, global, key);
}
bool

View File

@ -442,19 +442,18 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
return functionProto;
}
bool
GlobalObject::ensureConstructor(JSContext *cx, JSProtoKey key)
/* static */ bool
GlobalObject::ensureConstructor(JSContext *cx, Handle<GlobalObject*> global, JSProtoKey key)
{
if (getConstructor(key).isObject())
if (global->getConstructor(key).isObject())
return true;
return initConstructor(cx, key);
return initConstructor(cx, global, key);
}
bool
GlobalObject::initConstructor(JSContext *cx, JSProtoKey key)
/* static*/ bool
GlobalObject::initConstructor(JSContext *cx, Handle<GlobalObject*> global, JSProtoKey key)
{
MOZ_ASSERT(getConstructor(key).isUndefined());
Rooted<GlobalObject*> self(cx, this);
MOZ_ASSERT(global->getConstructor(key).isUndefined());
// There are two different kinds of initialization hooks. One of them is
// the class js_InitFoo hook, defined in a JSProtoKey-keyed table at the
@ -479,7 +478,7 @@ GlobalObject::initConstructor(JSContext *cx, JSProtoKey key)
// See if there's an old-style initialization hook.
if (init) {
MOZ_ASSERT(!haveSpec);
return init(cx, self);
return init(cx, global);
}
//
@ -519,7 +518,7 @@ GlobalObject::initConstructor(JSContext *cx, JSProtoKey key)
return false;
// Stash things in the right slots and define the constructor on the global.
return DefineConstructorAndPrototype(cx, self, key, ctor, proto);
return DefineConstructorAndPrototype(cx, global, key, ctor, proto);
}
GlobalObject *
@ -578,7 +577,7 @@ GlobalObject::initStandardClasses(JSContext *cx, Handle<GlobalObject*> global)
}
for (size_t k = 0; k < JSProto_LIMIT; ++k) {
if (!global->ensureConstructor(cx, static_cast<JSProtoKey>(k)))
if (!ensureConstructor(cx, global, static_cast<JSProtoKey>(k)))
return false;
}
return true;

View File

@ -159,8 +159,8 @@ class GlobalObject : public JSObject
JS_ASSERT(key <= JSProto_LIMIT);
return getSlotForCompilation(APPLICATION_SLOTS + key);
}
bool ensureConstructor(JSContext *cx, JSProtoKey key);
bool initConstructor(JSContext *cx, JSProtoKey key);
static bool ensureConstructor(JSContext *cx, Handle<GlobalObject*> global, JSProtoKey key);
static bool initConstructor(JSContext *cx, Handle<GlobalObject*> global, JSProtoKey key);
void setConstructor(JSProtoKey key, const Value &v) {
JS_ASSERT(key <= JSProto_LIMIT);
@ -340,7 +340,7 @@ class GlobalObject : public JSObject
}
static JSObject *getOrCreateArrayPrototype(JSContext *cx, Handle<GlobalObject*> global) {
if (!global->ensureConstructor(cx, JSProto_Array))
if (!ensureConstructor(cx, global, JSProto_Array))
return nullptr;
return &global->getPrototype(JSProto_Array).toObject();
}
@ -352,25 +352,25 @@ class GlobalObject : public JSObject
}
static JSObject *getOrCreateBooleanPrototype(JSContext *cx, Handle<GlobalObject*> global) {
if (!global->ensureConstructor(cx, JSProto_Boolean))
if (!ensureConstructor(cx, global, JSProto_Boolean))
return nullptr;
return &global->getPrototype(JSProto_Boolean).toObject();
}
static JSObject *getOrCreateNumberPrototype(JSContext *cx, Handle<GlobalObject*> global) {
if (!global->ensureConstructor(cx, JSProto_Number))
if (!ensureConstructor(cx, global, JSProto_Number))
return nullptr;
return &global->getPrototype(JSProto_Number).toObject();
}
static JSObject *getOrCreateStringPrototype(JSContext *cx, Handle<GlobalObject*> global) {
if (!global->ensureConstructor(cx, JSProto_String))
if (!ensureConstructor(cx, global, JSProto_String))
return nullptr;
return &global->getPrototype(JSProto_String).toObject();
}
static JSObject *getOrCreateRegExpPrototype(JSContext *cx, Handle<GlobalObject*> global) {
if (!global->ensureConstructor(cx, JSProto_RegExp))
if (!ensureConstructor(cx, global, JSProto_RegExp))
return nullptr;
return &global->getPrototype(JSProto_RegExp).toObject();
}
@ -382,7 +382,7 @@ class GlobalObject : public JSObject
}
static JSObject *getOrCreateArrayBufferPrototype(JSContext *cx, Handle<GlobalObject*> global) {
if (!global->ensureConstructor(cx, JSProto_ArrayBuffer))
if (!ensureConstructor(cx, global, JSProto_ArrayBuffer))
return nullptr;
return &global->getPrototype(JSProto_ArrayBuffer).toObject();
}
@ -392,7 +392,7 @@ class GlobalObject : public JSObject
JSExnType exnType)
{
JSProtoKey key = GetExceptionProtoKey(exnType);
if (!global->ensureConstructor(cx, key))
if (!ensureConstructor(cx, global, key))
return nullptr;
return &global->getPrototype(key).toObject();
}
@ -473,7 +473,7 @@ class GlobalObject : public JSObject
static JSObject *getOrCreateIteratorPrototype(JSContext *cx,
Handle<GlobalObject*> global)
{
if (!global->ensureConstructor(cx, JSProto_Iterator))
if (!ensureConstructor(cx, global, JSProto_Iterator))
return nullptr;
return &global->getSlot(APPLICATION_SLOTS + JSProto_LIMIT + JSProto_Iterator).toObject();
}
@ -481,7 +481,7 @@ class GlobalObject : public JSObject
static JSObject *getOrCreateArrayIteratorPrototype(JSContext *cx,
Handle<GlobalObject*> global)
{
if (!global->ensureConstructor(cx, JSProto_Iterator))
if (!ensureConstructor(cx, global, JSProto_Iterator))
return nullptr;
return &global->getSlot(ARRAY_ITERATOR_PROTO).toObject();
}
@ -489,7 +489,7 @@ class GlobalObject : public JSObject
static JSObject *getOrCreateStringIteratorPrototype(JSContext *cx,
Handle<GlobalObject*> global)
{
if (!global->ensureConstructor(cx, JSProto_Iterator))
if (!ensureConstructor(cx, global, JSProto_Iterator))
return nullptr;
return &global->getSlot(STRING_ITERATOR_PROTO).toObject();
}
@ -497,7 +497,7 @@ class GlobalObject : public JSObject
static JSObject *getOrCreateLegacyGeneratorObjectPrototype(JSContext *cx,
Handle<GlobalObject*> global)
{
if (!global->ensureConstructor(cx, JSProto_Iterator))
if (!ensureConstructor(cx, global, JSProto_Iterator))
return nullptr;
return &global->getSlot(LEGACY_GENERATOR_OBJECT_PROTO).toObject();
}
@ -505,7 +505,7 @@ class GlobalObject : public JSObject
static JSObject *getOrCreateStarGeneratorObjectPrototype(JSContext *cx,
Handle<GlobalObject*> global)
{
if (!global->ensureConstructor(cx, JSProto_Iterator))
if (!ensureConstructor(cx, global, JSProto_Iterator))
return nullptr;
return &global->getSlot(STAR_GENERATOR_OBJECT_PROTO).toObject();
}
@ -513,7 +513,7 @@ class GlobalObject : public JSObject
static JSObject *getOrCreateStarGeneratorFunctionPrototype(JSContext *cx,
Handle<GlobalObject*> global)
{
if (!global->ensureConstructor(cx, JSProto_Iterator))
if (!ensureConstructor(cx, global, JSProto_Iterator))
return nullptr;
return &global->getSlot(APPLICATION_SLOTS + JSProto_LIMIT + JSProto_GeneratorFunction).toObject();
}
@ -521,7 +521,7 @@ class GlobalObject : public JSObject
static JSObject *getOrCreateStarGeneratorFunction(JSContext *cx,
Handle<GlobalObject*> global)
{
if (!global->ensureConstructor(cx, JSProto_Iterator))
if (!ensureConstructor(cx, global, JSProto_Iterator))
return nullptr;
return &global->getSlot(APPLICATION_SLOTS + JSProto_GeneratorFunction).toObject();
}
@ -540,7 +540,7 @@ class GlobalObject : public JSObject
JSObject *getOrCreateDataViewPrototype(JSContext *cx) {
Rooted<GlobalObject*> self(cx, this);
if (!ensureConstructor(cx, JSProto_DataView))
if (!ensureConstructor(cx, self, JSProto_DataView))
return nullptr;
return &self->getPrototype(JSProto_DataView).toObject();
}