1320408 - Part 14: Change some GlobalObject methods to static method.

This commit is contained in:
Gaming4JC 2019-06-08 23:28:04 -04:00 • committed by Roy Tam
commit cc8cb910dd
37 changed files with 287 additions and 259 deletions

View file

@ -1117,7 +1117,7 @@ JSObject*
AtomicsObject::initClass(JSContext* cx, Handle<GlobalObject*> global) AtomicsObject::initClass(JSContext* cx, Handle<GlobalObject*> global)
{ {
// Create Atomics Object. // Create Atomics Object.
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!objProto) if (!objProto)
return nullptr; return nullptr;
RootedObject Atomics(cx, NewObjectWithGivenProto(cx, &AtomicsObject::class_, objProto, RootedObject Atomics(cx, NewObjectWithGivenProto(cx, &AtomicsObject::class_, objProto,

View file

@ -270,7 +270,7 @@ Collator(JSContext* cx, const CallArgs& args, bool construct)
// See https://github.com/tc39/ecma402/issues/57 // See https://github.com/tc39/ecma402/issues/57
if (!construct) { if (!construct) {
// ES Intl 1st ed., 10.1.2.1 step 3 // ES Intl 1st ed., 10.1.2.1 step 3
JSObject* intl = cx->global()->getOrCreateIntlObject(cx); JSObject* intl = GlobalObject::getOrCreateIntlObject(cx, cx->global());
if (!intl) if (!intl)
return false; return false;
RootedValue self(cx, args.thisv()); RootedValue self(cx, args.thisv());
@ -298,7 +298,7 @@ Collator(JSContext* cx, const CallArgs& args, bool construct)
return false; return false;
if (!proto) { if (!proto) {
proto = cx->global()->getOrCreateCollatorPrototype(cx); proto = GlobalObject::getOrCreateCollatorPrototype(cx, cx->global());
if (!proto) if (!proto)
return false; return false;
} }
@ -358,11 +358,12 @@ collator_finalize(FreeOp* fop, JSObject* obj)
static JSObject* static JSObject*
CreateCollatorPrototype(JSContext* cx, HandleObject Intl, Handle<GlobalObject*> global) CreateCollatorPrototype(JSContext* cx, HandleObject Intl, Handle<GlobalObject*> global)
{ {
RootedFunction ctor(cx, global->createConstructor(cx, &Collator, cx->names().Collator, 0)); RootedFunction ctor(cx, GlobalObject::createConstructor(cx, &Collator, cx->names().Collator,
0));
if (!ctor) if (!ctor)
return nullptr; return nullptr;
RootedNativeObject proto(cx, global->createBlankPrototype(cx, &CollatorClass)); RootedNativeObject proto(cx, GlobalObject::createBlankPrototype(cx, global, &CollatorClass));
if (!proto) if (!proto)
return nullptr; return nullptr;
proto->setReservedSlot(UCOLLATOR_SLOT, PrivateValue(nullptr)); proto->setReservedSlot(UCOLLATOR_SLOT, PrivateValue(nullptr));
@ -772,7 +773,7 @@ NumberFormat(JSContext* cx, const CallArgs& args, bool construct)
// See https://github.com/tc39/ecma402/issues/57 // See https://github.com/tc39/ecma402/issues/57
if (!construct) { if (!construct) {
// ES Intl 1st ed., 11.1.2.1 step 3 // ES Intl 1st ed., 11.1.2.1 step 3
JSObject* intl = cx->global()->getOrCreateIntlObject(cx); JSObject* intl = GlobalObject::getOrCreateIntlObject(cx, cx->global());
if (!intl) if (!intl)
return false; return false;
RootedValue self(cx, args.thisv()); RootedValue self(cx, args.thisv());
@ -800,7 +801,7 @@ NumberFormat(JSContext* cx, const CallArgs& args, bool construct)
return false; return false;
if (!proto) { if (!proto) {
proto = cx->global()->getOrCreateNumberFormatPrototype(cx); proto = GlobalObject::getOrCreateNumberFormatPrototype(cx, cx->global());
if (!proto) if (!proto)
return false; return false;
} }
@ -862,11 +863,12 @@ static JSObject*
CreateNumberFormatPrototype(JSContext* cx, HandleObject Intl, Handle<GlobalObject*> global) CreateNumberFormatPrototype(JSContext* cx, HandleObject Intl, Handle<GlobalObject*> global)
{ {
RootedFunction ctor(cx); RootedFunction ctor(cx);
ctor = global->createConstructor(cx, &NumberFormat, cx->names().NumberFormat, 0); ctor = GlobalObject::createConstructor(cx, &NumberFormat, cx->names().NumberFormat, 0);
if (!ctor) if (!ctor)
return nullptr; return nullptr;
RootedNativeObject proto(cx, global->createBlankPrototype(cx, &NumberFormatClass)); RootedNativeObject proto(cx, GlobalObject::createBlankPrototype(cx, global,
&NumberFormatClass));
if (!proto) if (!proto)
return nullptr; return nullptr;
proto->setReservedSlot(UNUMBER_FORMAT_SLOT, PrivateValue(nullptr)); proto->setReservedSlot(UNUMBER_FORMAT_SLOT, PrivateValue(nullptr));
@ -1250,7 +1252,7 @@ DateTimeFormat(JSContext* cx, const CallArgs& args, bool construct)
// See https://github.com/tc39/ecma402/issues/57 // See https://github.com/tc39/ecma402/issues/57
if (!construct) { if (!construct) {
// ES Intl 1st ed., 12.1.2.1 step 3 // ES Intl 1st ed., 12.1.2.1 step 3
JSObject* intl = cx->global()->getOrCreateIntlObject(cx); JSObject* intl = GlobalObject::getOrCreateIntlObject(cx, cx->global());
if (!intl) if (!intl)
return false; return false;
RootedValue self(cx, args.thisv()); RootedValue self(cx, args.thisv());
@ -1278,7 +1280,7 @@ DateTimeFormat(JSContext* cx, const CallArgs& args, bool construct)
return false; return false;
if (!proto) { if (!proto) {
proto = cx->global()->getOrCreateDateTimeFormatPrototype(cx); proto = GlobalObject::getOrCreateDateTimeFormatPrototype(cx, cx->global());
if (!proto) if (!proto)
return false; return false;
} }
@ -1340,11 +1342,12 @@ static JSObject*
CreateDateTimeFormatPrototype(JSContext* cx, HandleObject Intl, Handle<GlobalObject*> global) CreateDateTimeFormatPrototype(JSContext* cx, HandleObject Intl, Handle<GlobalObject*> global)
{ {
RootedFunction ctor(cx); RootedFunction ctor(cx);
ctor = global->createConstructor(cx, &DateTimeFormat, cx->names().DateTimeFormat, 0); ctor = GlobalObject::createConstructor(cx, &DateTimeFormat, cx->names().DateTimeFormat, 0);
if (!ctor) if (!ctor)
return nullptr; return nullptr;
RootedNativeObject proto(cx, global->createBlankPrototype(cx, &DateTimeFormatClass)); RootedNativeObject proto(cx, GlobalObject::createBlankPrototype(cx, global,
&DateTimeFormatClass));
if (!proto) if (!proto)
return nullptr; return nullptr;
proto->setReservedSlot(UDATE_FORMAT_SLOT, PrivateValue(nullptr)); proto->setReservedSlot(UDATE_FORMAT_SLOT, PrivateValue(nullptr));
@ -2731,10 +2734,10 @@ static const JSFunctionSpec intl_static_methods[] = {
* Initializes the Intl Object and its standard built-in properties. * Initializes the Intl Object and its standard built-in properties.
* Spec: ECMAScript Internationalization API Specification, 8.0, 8.1 * Spec: ECMAScript Internationalization API Specification, 8.0, 8.1
*/ */
bool /* static */ bool
GlobalObject::initIntlObject(JSContext* cx, Handle<GlobalObject*> global) GlobalObject::initIntlObject(JSContext* cx, Handle<GlobalObject*> global)
{ {
RootedObject proto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!proto) if (!proto)
return false; return false;

View file

@ -164,7 +164,7 @@ MapIteratorObject::kind() const
return MapObject::IteratorKind(i); return MapObject::IteratorKind(i);
} }
bool /* static */ bool
GlobalObject::initMapIteratorProto(JSContext* cx, Handle<GlobalObject*> global) GlobalObject::initMapIteratorProto(JSContext* cx, Handle<GlobalObject*> global)
{ {
Rooted<JSObject*> base(cx, GlobalObject::getOrCreateIteratorPrototype(cx, global)); Rooted<JSObject*> base(cx, GlobalObject::getOrCreateIteratorPrototype(cx, global));
@ -924,7 +924,7 @@ SetIteratorObject::kind() const
return SetObject::IteratorKind(i); return SetObject::IteratorKind(i);
} }
bool /* static */ bool
GlobalObject::initSetIteratorProto(JSContext* cx, Handle<GlobalObject*> global) GlobalObject::initSetIteratorProto(JSContext* cx, Handle<GlobalObject*> global)
{ {
Rooted<JSObject*> base(cx, GlobalObject::getOrCreateIteratorPrototype(cx, global)); Rooted<JSObject*> base(cx, GlobalObject::getOrCreateIteratorPrototype(cx, global));

View file

@ -103,7 +103,7 @@ GlobalObject::initImportEntryProto(JSContext* cx, Handle<GlobalObject*> global)
JS_PS_END JS_PS_END
}; };
RootedObject proto(cx, global->createBlankPrototype<PlainObject>(cx)); RootedObject proto(cx, GlobalObject::createBlankPrototype<PlainObject>(cx, global));
if (!proto) if (!proto)
return false; return false;
@ -169,7 +169,7 @@ GlobalObject::initExportEntryProto(JSContext* cx, Handle<GlobalObject*> global)
JS_PS_END JS_PS_END
}; };
RootedObject proto(cx, global->createBlankPrototype<PlainObject>(cx)); RootedObject proto(cx, GlobalObject::createBlankPrototype<PlainObject>(cx, global));
if (!proto) if (!proto)
return false; return false;
@ -1020,7 +1020,7 @@ GlobalObject::initModuleProto(JSContext* cx, Handle<GlobalObject*> global)
JS_FS_END JS_FS_END
}; };
RootedObject proto(cx, global->createBlankPrototype<PlainObject>(cx)); RootedObject proto(cx, GlobalObject::createBlankPrototype<PlainObject>(cx, global));
if (!proto) if (!proto)
return false; return false;

View file

@ -2734,7 +2734,7 @@ PromiseTask::executeAndFinish(JSContext* cx)
static JSObject* static JSObject*
CreatePromisePrototype(JSContext* cx, JSProtoKey key) CreatePromisePrototype(JSContext* cx, JSProtoKey key)
{ {
return cx->global()->createBlankPrototype(cx, &PromiseObject::protoClass_); return GlobalObject::createBlankPrototype(cx, cx->global(), &PromiseObject::protoClass_);
} }
static const JSFunctionSpec promise_methods[] = { static const JSFunctionSpec promise_methods[] = {

View file

@ -268,7 +268,8 @@ static const JSFunctionSpec methods[] = {
JSObject* JSObject*
js::InitReflect(JSContext* cx, HandleObject obj) js::InitReflect(JSContext* cx, HandleObject obj)
{ {
RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx)); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!proto) if (!proto)
return nullptr; return nullptr;

View file

@ -801,7 +801,7 @@ const JSFunctionSpec js::regexp_methods[] = {
name(JSContext* cx, unsigned argc, Value* vp) \ name(JSContext* cx, unsigned argc, Value* vp) \
{ \ { \
CallArgs args = CallArgsFromVp(argc, vp); \ CallArgs args = CallArgsFromVp(argc, vp); \
RegExpStatics* res = cx->global()->getRegExpStatics(cx); \ RegExpStatics* res = GlobalObject::getRegExpStatics(cx, cx->global()); \
if (!res) \ if (!res) \
return false; \ return false; \
code; \ code; \
@ -827,7 +827,7 @@ DEFINE_STATIC_GETTER(static_paren9_getter, STATIC_PAREN_GETTER_CODE(9))
static bool \ static bool \
name(JSContext* cx, unsigned argc, Value* vp) \ name(JSContext* cx, unsigned argc, Value* vp) \
{ \ { \
RegExpStatics* res = cx->global()->getRegExpStatics(cx); \ RegExpStatics* res = GlobalObject::getRegExpStatics(cx, cx->global()); \
if (!res) \ if (!res) \
return false; \ return false; \
code; \ code; \
@ -838,7 +838,7 @@ static bool
static_input_setter(JSContext* cx, unsigned argc, Value* vp) static_input_setter(JSContext* cx, unsigned argc, Value* vp)
{ {
CallArgs args = CallArgsFromVp(argc, vp); CallArgs args = CallArgsFromVp(argc, vp);
RegExpStatics* res = cx->global()->getRegExpStatics(cx); RegExpStatics* res = GlobalObject::getRegExpStatics(cx, cx->global());
if (!res) if (!res)
return false; return false;
@ -923,7 +923,7 @@ ExecuteRegExp(JSContext* cx, HandleObject regexp, HandleString string,
RegExpStatics* res; RegExpStatics* res;
if (staticsUpdate == UpdateRegExpStatics) { if (staticsUpdate == UpdateRegExpStatics) {
res = cx->global()->getRegExpStatics(cx); res = GlobalObject::getRegExpStatics(cx, cx->global());
if (!res) if (!res)
return RegExpRunStatus_Error; return RegExpRunStatus_Error;
} else { } else {

View file

@ -475,7 +475,7 @@ const Class SimdObject::class_ = {
&SimdObjectClassOps &SimdObjectClassOps
}; };
bool /* static */ bool
GlobalObject::initSimdObject(JSContext* cx, Handle<GlobalObject*> global) GlobalObject::initSimdObject(JSContext* cx, Handle<GlobalObject*> global)
{ {
// SIMD relies on the TypedObject module being initialized. // SIMD relies on the TypedObject module being initialized.
@ -483,11 +483,11 @@ GlobalObject::initSimdObject(JSContext* cx, Handle<GlobalObject*> global)
// to be able to call GetTypedObjectModule(). It is NOT necessary // to be able to call GetTypedObjectModule(). It is NOT necessary
// to install the TypedObjectModule global, but at the moment // to install the TypedObjectModule global, but at the moment
// those two things are not separable. // those two things are not separable.
if (!global->getOrCreateTypedObjectModule(cx)) if (!GlobalObject::getOrCreateTypedObjectModule(cx, global))
return false; return false;
RootedObject globalSimdObject(cx); RootedObject globalSimdObject(cx);
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!objProto) if (!objProto)
return false; return false;
@ -510,7 +510,7 @@ static bool
CreateSimdType(JSContext* cx, Handle<GlobalObject*> global, HandlePropertyName stringRepr, CreateSimdType(JSContext* cx, Handle<GlobalObject*> global, HandlePropertyName stringRepr,
SimdType simdType, const JSFunctionSpec* methods) SimdType simdType, const JSFunctionSpec* methods)
{ {
RootedObject funcProto(cx, global->getOrCreateFunctionPrototype(cx)); RootedObject funcProto(cx, GlobalObject::getOrCreateFunctionPrototype(cx, global));
if (!funcProto) if (!funcProto)
return false; return false;
@ -531,7 +531,7 @@ CreateSimdType(JSContext* cx, Handle<GlobalObject*> global, HandlePropertyName s
return false; return false;
// Create prototype property, which inherits from Object.prototype. // Create prototype property, which inherits from Object.prototype.
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!objProto) if (!objProto)
return false; return false;
Rooted<TypedProto*> proto(cx); Rooted<TypedProto*> proto(cx);
@ -551,7 +551,7 @@ CreateSimdType(JSContext* cx, Handle<GlobalObject*> global, HandlePropertyName s
} }
// Bind type descriptor to the global SIMD object // Bind type descriptor to the global SIMD object
RootedObject globalSimdObject(cx, global->getOrCreateSimdGlobalObject(cx)); RootedObject globalSimdObject(cx, GlobalObject::getOrCreateSimdGlobalObject(cx, global));
MOZ_ASSERT(globalSimdObject); MOZ_ASSERT(globalSimdObject);
RootedValue typeValue(cx, ObjectValue(*typeDescr)); RootedValue typeValue(cx, ObjectValue(*typeDescr));
@ -568,7 +568,7 @@ CreateSimdType(JSContext* cx, Handle<GlobalObject*> global, HandlePropertyName s
return !!typeDescr; return !!typeDescr;
} }
bool /* static */ bool
GlobalObject::initSimdType(JSContext* cx, Handle<GlobalObject*> global, SimdType simdType) GlobalObject::initSimdType(JSContext* cx, Handle<GlobalObject*> global, SimdType simdType)
{ {
#define CREATE_(Type) \ #define CREATE_(Type) \
@ -584,13 +584,13 @@ GlobalObject::initSimdType(JSContext* cx, Handle<GlobalObject*> global, SimdType
#undef CREATE_ #undef CREATE_
} }
SimdTypeDescr* /* static */ SimdTypeDescr*
GlobalObject::getOrCreateSimdTypeDescr(JSContext* cx, Handle<GlobalObject*> global, GlobalObject::getOrCreateSimdTypeDescr(JSContext* cx, Handle<GlobalObject*> global,
SimdType simdType) SimdType simdType)
{ {
MOZ_ASSERT(unsigned(simdType) < unsigned(SimdType::Count), "Invalid SIMD type"); MOZ_ASSERT(unsigned(simdType) < unsigned(SimdType::Count), "Invalid SIMD type");
RootedObject globalSimdObject(cx, global->getOrCreateSimdGlobalObject(cx)); RootedObject globalSimdObject(cx, GlobalObject::getOrCreateSimdGlobalObject(cx, global));
if (!globalSimdObject) if (!globalSimdObject)
return nullptr; return nullptr;
@ -628,8 +628,8 @@ SimdObject::resolve(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool*
JSObject* JSObject*
js::InitSimdClass(JSContext* cx, HandleObject obj) js::InitSimdClass(JSContext* cx, HandleObject obj)
{ {
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
return global->getOrCreateSimdGlobalObject(cx); return GlobalObject::getOrCreateSimdGlobalObject(cx, global);
} }
template<typename V> template<typename V>

View file

@ -53,17 +53,17 @@ const JSFunctionSpec SymbolObject::staticMethods[] = {
JSObject* JSObject*
SymbolObject::initClass(JSContext* cx, HandleObject obj) SymbolObject::initClass(JSContext* cx, HandleObject obj)
{ {
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
// This uses &JSObject::class_ because: "The Symbol prototype object is an // This uses &JSObject::class_ because: "The Symbol prototype object is an
// ordinary object. It is not a Symbol instance and does not have a // ordinary object. It is not a Symbol instance and does not have a
// [[SymbolData]] internal slot." (ES6 rev 24, 19.4.3) // [[SymbolData]] internal slot." (ES6 rev 24, 19.4.3)
RootedObject proto(cx, global->createBlankPrototype<PlainObject>(cx)); RootedObject proto(cx, GlobalObject::createBlankPrototype<PlainObject>(cx, global));
if (!proto) if (!proto)
return nullptr; return nullptr;
RootedFunction ctor(cx, global->createConstructor(cx, construct, RootedFunction ctor(cx, GlobalObject::createConstructor(cx, construct,
ClassName(JSProto_Symbol, cx), 0)); ClassName(JSProto_Symbol, cx), 0));
if (!ctor) if (!ctor)
return nullptr; return nullptr;

View file

@ -1124,11 +1124,11 @@ DefineSimpleTypeDescr(JSContext* cx,
typename T::Type type, typename T::Type type,
HandlePropertyName className) HandlePropertyName className)
{ {
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!objProto) if (!objProto)
return false; return false;
RootedObject funcProto(cx, global->getOrCreateFunctionPrototype(cx)); RootedObject funcProto(cx, GlobalObject::getOrCreateFunctionPrototype(cx, global));
if (!funcProto) if (!funcProto)
return false; return false;
@ -1185,7 +1185,7 @@ DefineMetaTypeDescr(JSContext* cx,
if (!className) if (!className)
return nullptr; return nullptr;
RootedObject funcProto(cx, global->getOrCreateFunctionPrototype(cx)); RootedObject funcProto(cx, GlobalObject::getOrCreateFunctionPrototype(cx, global));
if (!funcProto) if (!funcProto)
return nullptr; return nullptr;
@ -1197,7 +1197,7 @@ DefineMetaTypeDescr(JSContext* cx,
// Create ctor.prototype.prototype, which inherits from Object.__proto__ // Create ctor.prototype.prototype, which inherits from Object.__proto__
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!objProto) if (!objProto)
return nullptr; return nullptr;
RootedObject protoProto(cx); RootedObject protoProto(cx);
@ -1216,7 +1216,7 @@ DefineMetaTypeDescr(JSContext* cx,
const int constructorLength = 2; const int constructorLength = 2;
RootedFunction ctor(cx); RootedFunction ctor(cx);
ctor = global->createConstructor(cx, T::construct, className, constructorLength); ctor = GlobalObject::createConstructor(cx, T::construct, className, constructorLength);
if (!ctor || if (!ctor ||
!LinkConstructorAndPrototype(cx, ctor, proto) || !LinkConstructorAndPrototype(cx, ctor, proto) ||
!DefinePropertiesAndFunctions(cx, proto, !DefinePropertiesAndFunctions(cx, proto,
@ -1240,10 +1240,10 @@ DefineMetaTypeDescr(JSContext* cx,
* initializer for the `TypedObject` class populate the * initializer for the `TypedObject` class populate the
* `TypedObject` global (which is referred to as "module" herein). * `TypedObject` global (which is referred to as "module" herein).
*/ */
bool /* static */ bool
GlobalObject::initTypedObjectModule(JSContext* cx, Handle<GlobalObject*> global) GlobalObject::initTypedObjectModule(JSContext* cx, Handle<GlobalObject*> global)
{ {
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!objProto) if (!objProto)
return false; return false;
@ -1317,9 +1317,8 @@ GlobalObject::initTypedObjectModule(JSContext* cx, Handle<GlobalObject*> global)
JSObject* JSObject*
js::InitTypedObjectModuleObject(JSContext* cx, HandleObject obj) js::InitTypedObjectModuleObject(JSContext* cx, HandleObject obj)
{ {
MOZ_ASSERT(obj->is<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); return GlobalObject::getOrCreateTypedObjectModule(cx, global);
return global->getOrCreateTypedObjectModule(cx);
} }
/****************************************************************************** /******************************************************************************

View file

@ -350,14 +350,14 @@ InitWeakMapClass(JSContext* cx, HandleObject obj, bool defineMembers)
{ {
MOZ_ASSERT(obj->isNative()); MOZ_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedPlainObject proto(cx, NewBuiltinClassInstance<PlainObject>(cx)); RootedPlainObject proto(cx, NewBuiltinClassInstance<PlainObject>(cx));
if (!proto) if (!proto)
return nullptr; return nullptr;
RootedFunction ctor(cx, global->createConstructor(cx, WeakMap_construct, RootedFunction ctor(cx, GlobalObject::createConstructor(cx, WeakMap_construct,
cx->names().WeakMap, 0)); cx->names().WeakMap, 0));
if (!ctor) if (!ctor)
return nullptr; return nullptr;

View file

@ -41,14 +41,15 @@ const JSFunctionSpec WeakSetObject::methods[] = {
}; };
JSObject* JSObject*
WeakSetObject::initClass(JSContext* cx, JSObject* obj) WeakSetObject::initClass(JSContext* cx, HandleObject obj)
{ {
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedPlainObject proto(cx, NewBuiltinClassInstance<PlainObject>(cx)); RootedPlainObject proto(cx, NewBuiltinClassInstance<PlainObject>(cx));
if (!proto) if (!proto)
return nullptr; return nullptr;
Rooted<JSFunction*> ctor(cx, global->createConstructor(cx, construct, ClassName(JSProto_WeakSet, cx), 0)); Rooted<JSFunction*> ctor(cx, GlobalObject::createConstructor(cx, construct,
ClassName(JSProto_WeakSet, cx), 0));
if (!ctor || if (!ctor ||
!LinkConstructorAndPrototype(cx, ctor, proto) || !LinkConstructorAndPrototype(cx, ctor, proto) ||
!DefinePropertiesAndFunctions(cx, proto, properties, methods) || !DefinePropertiesAndFunctions(cx, proto, properties, methods) ||

View file

@ -16,7 +16,7 @@ class WeakSetObject : public NativeObject
public: public:
static const unsigned RESERVED_SLOTS = 1; static const unsigned RESERVED_SLOTS = 1;
static JSObject* initClass(JSContext* cx, JSObject* obj); static JSObject* initClass(JSContext* cx, HandleObject obj);
static const Class class_; static const Class class_;
private: private:

View file

@ -1053,7 +1053,7 @@ PrepareAndExecuteRegExp(JSContext* cx, MacroAssembler& masm, Register regexp, Re
Address pairsVectorAddress(masm.getStackPointer(), pairsVectorStartOffset); Address pairsVectorAddress(masm.getStackPointer(), pairsVectorStartOffset);
RegExpStatics* res = cx->global()->getRegExpStatics(cx); RegExpStatics* res = GlobalObject::getRegExpStatics(cx, cx->global());
if (!res) if (!res)
return false; return false;
#ifdef JS_USE_LINK_REGISTER #ifdef JS_USE_LINK_REGISTER

View file

@ -1022,7 +1022,7 @@ JS_ResolveStandardClass(JSContext* cx, HandleObject obj, HandleId id, bool* reso
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
assertSameCompartment(cx, obj, id); assertSameCompartment(cx, obj, id);
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
*resolved = false; *resolved = false;
if (!JSID_IS_ATOM(id)) if (!JSID_IS_ATOM(id))
@ -1066,10 +1066,7 @@ JS_ResolveStandardClass(JSContext* cx, HandleObject obj, HandleId id, bool* reso
// more way: its prototype chain is lazily initialized. That is, // more way: its prototype chain is lazily initialized. That is,
// global->getProto() might be null right now because we haven't created // global->getProto() might be null right now because we haven't created
// Object.prototype yet. Force it now. // Object.prototype yet. Force it now.
if (!global->getOrCreateObjectPrototype(cx)) return GlobalObject::getOrCreateObjectPrototype(cx, global);
return false;
return true;
} }
JS_PUBLIC_API(bool) JS_PUBLIC_API(bool)
@ -1102,8 +1099,7 @@ JS_EnumerateStandardClasses(JSContext* cx, HandleObject obj)
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
assertSameCompartment(cx, obj); assertSameCompartment(cx, obj);
MOZ_ASSERT(obj->is<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
return GlobalObject::initStandardClasses(cx, global); return GlobalObject::initStandardClasses(cx, global);
} }
@ -1159,7 +1155,8 @@ JS_GetObjectPrototype(JSContext* cx, HandleObject forObj)
{ {
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
assertSameCompartment(cx, forObj); assertSameCompartment(cx, forObj);
return forObj->global().getOrCreateObjectPrototype(cx); Rooted<GlobalObject*> global(cx, &forObj->global());
return GlobalObject::getOrCreateObjectPrototype(cx, global);
} }
JS_PUBLIC_API(JSObject*) JS_PUBLIC_API(JSObject*)
@ -1167,7 +1164,8 @@ JS_GetFunctionPrototype(JSContext* cx, HandleObject forObj)
{ {
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
assertSameCompartment(cx, forObj); assertSameCompartment(cx, forObj);
return forObj->global().getOrCreateFunctionPrototype(cx); Rooted<GlobalObject*> global(cx, &forObj->global());
return GlobalObject::getOrCreateFunctionPrototype(cx, global);
} }
JS_PUBLIC_API(JSObject*) JS_PUBLIC_API(JSObject*)
@ -6015,7 +6013,8 @@ JS_SetRegExpInput(JSContext* cx, HandleObject obj, HandleString input)
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
assertSameCompartment(cx, input); assertSameCompartment(cx, input);
RegExpStatics* res = obj->as<GlobalObject>().getRegExpStatics(cx); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RegExpStatics* res = GlobalObject::getRegExpStatics(cx, global);
if (!res) if (!res)
return false; return false;
@ -6030,7 +6029,8 @@ JS_ClearRegExpStatics(JSContext* cx, HandleObject obj)
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
MOZ_ASSERT(obj); MOZ_ASSERT(obj);
RegExpStatics* res = obj->as<GlobalObject>().getRegExpStatics(cx); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RegExpStatics* res = GlobalObject::getRegExpStatics(cx, global);
if (!res) if (!res)
return false; return false;
@ -6045,7 +6045,8 @@ JS_ExecuteRegExp(JSContext* cx, HandleObject obj, HandleObject reobj, char16_t*
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
CHECK_REQUEST(cx); CHECK_REQUEST(cx);
RegExpStatics* res = obj->as<GlobalObject>().getRegExpStatics(cx); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RegExpStatics* res = GlobalObject::getRegExpStatics(cx, global);
if (!res) if (!res)
return false; return false;

View file

@ -3246,7 +3246,7 @@ static JSObject*
CreateArrayPrototype(JSContext* cx, JSProtoKey key) CreateArrayPrototype(JSContext* cx, JSProtoKey key)
{ {
MOZ_ASSERT(key == JSProto_Array); MOZ_ASSERT(key == JSProto_Array);
RootedObject proto(cx, cx->global()->getOrCreateObjectPrototype(cx)); RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, cx->global()));
if (!proto) if (!proto)
return nullptr; return nullptr;

View file

@ -137,14 +137,14 @@ js::InitBooleanClass(JSContext* cx, HandleObject obj)
{ {
MOZ_ASSERT(obj->isNative()); MOZ_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
Rooted<BooleanObject*> booleanProto(cx, global->createBlankPrototype<BooleanObject>(cx)); Rooted<BooleanObject*> booleanProto(cx, GlobalObject::createBlankPrototype<BooleanObject>(cx, global));
if (!booleanProto) if (!booleanProto)
return nullptr; return nullptr;
booleanProto->setFixedSlot(BooleanObject::PRIMITIVE_VALUE_SLOT, BooleanValue(false)); booleanProto->setFixedSlot(BooleanObject::PRIMITIVE_VALUE_SLOT, BooleanValue(false));
RootedFunction ctor(cx, global->createConstructor(cx, Boolean, cx->names().Boolean, 1)); RootedFunction ctor(cx, GlobalObject::createConstructor(cx, Boolean, cx->names().Boolean, 1));
if (!ctor) if (!ctor)
return nullptr; return nullptr;

View file

@ -3163,7 +3163,7 @@ js::DateConstructor(JSContext* cx, unsigned argc, Value* vp)
static JSObject* static JSObject*
CreateDatePrototype(JSContext* cx, JSProtoKey key) CreateDatePrototype(JSContext* cx, JSProtoKey key)
{ {
return cx->global()->createBlankPrototype(cx, &DateObject::protoClass_); return GlobalObject::createBlankPrototype(cx, cx->global(), &DateObject::protoClass_);
} }
static bool static bool

View file

@ -512,14 +512,17 @@ ErrorObject::createProto(JSContext* cx, JSProtoKey key)
{ {
JSExnType type = ExnTypeFromProtoKey(key); JSExnType type = ExnTypeFromProtoKey(key);
if (type == JSEXN_ERR) if (type == JSEXN_ERR) {
return cx->global()->createBlankPrototype(cx, &ErrorObject::protoClasses[JSEXN_ERR]); return GlobalObject::createBlankPrototype(cx, cx->global(),
&ErrorObject::protoClasses[JSEXN_ERR]);
}
RootedObject protoProto(cx, GlobalObject::getOrCreateErrorPrototype(cx, cx->global())); RootedObject protoProto(cx, GlobalObject::getOrCreateErrorPrototype(cx, cx->global()));
if (!protoProto) if (!protoProto)
return nullptr; return nullptr;
return cx->global()->createBlankPrototypeInheriting(cx, &ErrorObject::protoClasses[type], return GlobalObject::createBlankPrototypeInheriting(cx, cx->global(),
&ErrorObject::protoClasses[type],
protoProto); protoProto);
} }

View file

@ -379,7 +379,7 @@ ResolveInterpretedFunctionPrototype(JSContext* cx, HandleFunction fun, HandleId
if (isStarGenerator) if (isStarGenerator)
objProto = GlobalObject::getOrCreateStarGeneratorObjectPrototype(cx, global); objProto = GlobalObject::getOrCreateStarGeneratorObjectPrototype(cx, global);
else else
objProto = fun->global().getOrCreateObjectPrototype(cx); objProto = GlobalObject::getOrCreateObjectPrototype(cx, global);
if (!objProto) if (!objProto)
return false; return false;

View file

@ -921,7 +921,7 @@ js::CreateItrResultObject(JSContext* cx, HandleValue value, bool done)
// FIXME: We can cache the iterator result object shape somewhere. // FIXME: We can cache the iterator result object shape somewhere.
AssertHeapIsIdle(cx); AssertHeapIsIdle(cx);
RootedObject proto(cx, cx->global()->getOrCreateObjectPrototype(cx)); RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, cx->global()));
if (!proto) if (!proto)
return nullptr; return nullptr;
@ -1497,7 +1497,7 @@ GlobalObject::initIteratorProto(JSContext* cx, Handle<GlobalObject*> global)
if (global->getReservedSlot(ITERATOR_PROTO).isObject()) if (global->getReservedSlot(ITERATOR_PROTO).isObject())
return true; return true;
RootedObject proto(cx, global->createBlankPrototype<PlainObject>(cx)); RootedObject proto(cx, GlobalObject::createBlankPrototype<PlainObject>(cx, global));
if (!proto || !DefinePropertiesAndFunctions(cx, proto, nullptr, iterator_proto_methods)) if (!proto || !DefinePropertiesAndFunctions(cx, proto, nullptr, iterator_proto_methods))
return false; return false;
@ -1516,7 +1516,8 @@ GlobalObject::initArrayIteratorProto(JSContext* cx, Handle<GlobalObject*> global
return false; return false;
const Class* cls = &ArrayIteratorPrototypeClass; const Class* cls = &ArrayIteratorPrototypeClass;
RootedObject proto(cx, global->createBlankPrototypeInheriting(cx, cls, iteratorProto)); RootedObject proto(cx, GlobalObject::createBlankPrototypeInheriting(cx, global, cls,
iteratorProto));
if (!proto || if (!proto ||
!DefinePropertiesAndFunctions(cx, proto, nullptr, array_iterator_methods) || !DefinePropertiesAndFunctions(cx, proto, nullptr, array_iterator_methods) ||
!DefineToStringTag(cx, proto, cx->names().ArrayIterator)) !DefineToStringTag(cx, proto, cx->names().ArrayIterator))
@ -1539,7 +1540,8 @@ GlobalObject::initStringIteratorProto(JSContext* cx, Handle<GlobalObject*> globa
return false; return false;
const Class* cls = &StringIteratorPrototypeClass; const Class* cls = &StringIteratorPrototypeClass;
RootedObject proto(cx, global->createBlankPrototypeInheriting(cx, cls, iteratorProto)); RootedObject proto(cx, GlobalObject::createBlankPrototypeInheriting(cx, global, cls,
iteratorProto));
if (!proto || if (!proto ||
!DefinePropertiesAndFunctions(cx, proto, nullptr, string_iterator_methods) || !DefinePropertiesAndFunctions(cx, proto, nullptr, string_iterator_methods) ||
!DefineToStringTag(cx, proto, cx->names().StringIterator)) !DefineToStringTag(cx, proto, cx->names().StringIterator))
@ -1560,7 +1562,8 @@ js::InitLegacyIteratorClass(JSContext* cx, HandleObject obj)
return &global->getPrototype(JSProto_Iterator).toObject(); return &global->getPrototype(JSProto_Iterator).toObject();
RootedObject iteratorProto(cx); RootedObject iteratorProto(cx);
iteratorProto = global->createBlankPrototype(cx, &PropertyIteratorObject::class_); iteratorProto = GlobalObject::createBlankPrototype(cx, global,
&PropertyIteratorObject::class_);
if (!iteratorProto) if (!iteratorProto)
return nullptr; return nullptr;
@ -1572,7 +1575,7 @@ js::InitLegacyIteratorClass(JSContext* cx, HandleObject obj)
ni->init(nullptr, nullptr, 0 /* flags */, 0, 0); ni->init(nullptr, nullptr, 0 /* flags */, 0, 0);
Rooted<JSFunction*> ctor(cx); Rooted<JSFunction*> ctor(cx);
ctor = global->createConstructor(cx, IteratorConstructor, cx->names().Iterator, 2); ctor = GlobalObject::createConstructor(cx, IteratorConstructor, cx->names().Iterator, 2);
if (!ctor) if (!ctor)
return nullptr; return nullptr;
if (!LinkConstructorAndPrototype(cx, ctor, iteratorProto)) if (!LinkConstructorAndPrototype(cx, ctor, iteratorProto))
@ -1593,7 +1596,8 @@ js::InitStopIterationClass(JSContext* cx, HandleObject obj)
{ {
Handle<GlobalObject*> global = obj.as<GlobalObject>(); Handle<GlobalObject*> global = obj.as<GlobalObject>();
if (!global->getPrototype(JSProto_StopIteration).isObject()) { if (!global->getPrototype(JSProto_StopIteration).isObject()) {
RootedObject proto(cx, global->createBlankPrototype(cx, &StopIterationObject::class_)); RootedObject proto(cx, GlobalObject::createBlankPrototype(cx, global,
&StopIterationObject::class_));
if (!proto || !FreezeObject(cx, proto)) if (!proto || !FreezeObject(cx, proto))
return nullptr; return nullptr;

View file

@ -1417,7 +1417,8 @@ static const JSFunctionSpec math_static_methods[] = {
JSObject* JSObject*
js::InitMathClass(JSContext* cx, HandleObject obj) js::InitMathClass(JSContext* cx, HandleObject obj)
{ {
RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx)); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!proto) if (!proto)
return nullptr; return nullptr;
RootedObject Math(cx, NewObjectWithGivenProto(cx, &MathClass, proto, SingletonObject)); RootedObject Math(cx, NewObjectWithGivenProto(cx, &MathClass, proto, SingletonObject));

View file

@ -1005,15 +1005,16 @@ js::InitNumberClass(JSContext* cx, HandleObject obj)
/* XXX must do at least once per new thread, so do it per JSContext... */ /* XXX must do at least once per new thread, so do it per JSContext... */
FIX_FPU(); FIX_FPU();
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedObject numberProto(cx, global->createBlankPrototype(cx, &NumberObject::class_)); RootedObject numberProto(cx, GlobalObject::createBlankPrototype(cx, global,
&NumberObject::class_));
if (!numberProto) if (!numberProto)
return nullptr; return nullptr;
numberProto->as<NumberObject>().setPrimitiveValue(0); numberProto->as<NumberObject>().setPrimitiveValue(0);
RootedFunction ctor(cx); RootedFunction ctor(cx);
ctor = global->createConstructor(cx, Number, cx->names().Number, 1); ctor = GlobalObject::createConstructor(cx, Number, cx->names().Number, 1);
if (!ctor) if (!ctor)
return nullptr; return nullptr;

View file

@ -1985,7 +1985,8 @@ js::GetObjectFromIncumbentGlobal(JSContext* cx, MutableHandleObject obj)
{ {
AutoCompartment ac(cx, globalObj); AutoCompartment ac(cx, globalObj);
obj.set(globalObj->as<GlobalObject>().getOrCreateObjectPrototype(cx)); Handle<GlobalObject*> global = globalObj.as<GlobalObject>();
obj.set(GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!obj) if (!obj)
return false; return false;
} }
@ -2548,7 +2549,7 @@ js::SetPrototype(JSContext* cx, HandleObject obj, HandleObject proto, JS::Object
// [[Prototype]] chain is always properly immutable, even in the presence // [[Prototype]] chain is always properly immutable, even in the presence
// of lazy standard classes. // of lazy standard classes.
if (obj->is<GlobalObject>()) { if (obj->is<GlobalObject>()) {
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
if (!GlobalObject::ensureConstructor(cx, global, JSProto_Object)) if (!GlobalObject::ensureConstructor(cx, global, JSProto_Object))
return false; return false;
} }

View file

@ -971,9 +971,9 @@ static const JSFunctionSpec json_static_methods[] = {
JSObject* JSObject*
js::InitJSONClass(JSContext* cx, HandleObject obj) js::InitJSONClass(JSContext* cx, HandleObject obj)
{ {
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedObject proto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!proto) if (!proto)
return nullptr; return nullptr;
RootedObject JSON(cx, NewObjectWithGivenProto(cx, &JSONClass, proto, SingletonObject)); RootedObject JSON(cx, NewObjectWithGivenProto(cx, &JSONClass, proto, SingletonObject));

View file

@ -2914,17 +2914,17 @@ js::InitStringClass(JSContext* cx, HandleObject obj)
{ {
MOZ_ASSERT(obj->isNative()); MOZ_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
Rooted<JSString*> empty(cx, cx->runtime()->emptyString); Rooted<JSString*> empty(cx, cx->runtime()->emptyString);
RootedObject proto(cx, global->createBlankPrototype(cx, &StringObject::class_)); RootedObject proto(cx, GlobalObject::createBlankPrototype(cx, global, &StringObject::class_));
if (!proto || !proto->as<StringObject>().init(cx, empty)) if (!proto || !proto->as<StringObject>().init(cx, empty))
return nullptr; return nullptr;
/* Now create the String function. */ /* Now create the String function. */
RootedFunction ctor(cx); RootedFunction ctor(cx);
ctor = global->createConstructor(cx, StringConstructor, cx->names().String, 1, ctor = GlobalObject::createConstructor(cx, StringConstructor, cx->names().String, 1,
AllocKind::FUNCTION, &jit::JitInfo_String); AllocKind::FUNCTION, &jit::JitInfo_String);
if (!ctor) if (!ctor)
return nullptr; return nullptr;

View file

@ -796,9 +796,9 @@ js::InitProxyClass(JSContext* cx, HandleObject obj)
JS_FS_END JS_FS_END
}; };
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedFunction ctor(cx); RootedFunction ctor(cx);
ctor = global->createConstructor(cx, proxy, cx->names().Proxy, 2); ctor = GlobalObject::createConstructor(cx, proxy, cx->names().Proxy, 2);
if (!ctor) if (!ctor)
return nullptr; return nullptr;

View file

@ -214,7 +214,7 @@ ArgumentsObject::createTemplateObject(JSContext* cx, bool mapped)
? &MappedArgumentsObject::class_ ? &MappedArgumentsObject::class_
: &UnmappedArgumentsObject::class_; : &UnmappedArgumentsObject::class_;
RootedObject proto(cx, cx->global()->getOrCreateObjectPrototype(cx)); RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, cx->global()));
if (!proto) if (!proto)
return nullptr; return nullptr;

View file

@ -140,7 +140,7 @@ static const Class ArrayBufferObjectProtoClass = {
static JSObject* static JSObject*
CreateArrayBufferPrototype(JSContext* cx, JSProtoKey key) CreateArrayBufferPrototype(JSContext* cx, JSProtoKey key)
{ {
return cx->global()->createBlankPrototype(cx, &ArrayBufferObjectProtoClass); return GlobalObject::createBlankPrototype(cx, cx->global(), &ArrayBufferObjectProtoClass);
} }
static const ClassOps ArrayBufferObjectClassOps = { static const ClassOps ArrayBufferObjectClassOps = {

View file

@ -7227,8 +7227,8 @@ static const JSFunctionSpec DebuggerSource_methods[] = {
/* static */ NativeObject* /* static */ NativeObject*
DebuggerFrame::initClass(JSContext* cx, HandleObject dbgCtor, HandleObject obj) DebuggerFrame::initClass(JSContext* cx, HandleObject dbgCtor, HandleObject obj)
{ {
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
return InitClass(cx, dbgCtor, objProto, &class_, construct, 0, properties_, return InitClass(cx, dbgCtor, objProto, &class_, construct, 0, properties_,
methods_, nullptr, nullptr); methods_, nullptr, nullptr);
@ -9376,8 +9376,8 @@ const JSFunctionSpec DebuggerObject::methods_[] = {
/* static */ NativeObject* /* static */ NativeObject*
DebuggerObject::initClass(JSContext* cx, HandleObject obj, HandleObject debugCtor) DebuggerObject::initClass(JSContext* cx, HandleObject obj, HandleObject debugCtor)
{ {
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
RootedNativeObject objectProto(cx, InitClass(cx, debugCtor, objProto, &class_, RootedNativeObject objectProto(cx, InitClass(cx, debugCtor, objProto, &class_,
construct, 0, properties_, construct, 0, properties_,
@ -10577,8 +10577,8 @@ const JSFunctionSpec DebuggerEnvironment::methods_[] = {
/* static */ NativeObject* /* static */ NativeObject*
DebuggerEnvironment::initClass(JSContext* cx, HandleObject dbgCtor, HandleObject obj) DebuggerEnvironment::initClass(JSContext* cx, HandleObject dbgCtor, HandleObject obj)
{ {
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
return InitClass(cx, dbgCtor, objProto, &DebuggerEnvironment::class_, construct, 0, return InitClass(cx, dbgCtor, objProto, &DebuggerEnvironment::class_, construct, 0,
properties_, methods_, nullptr, nullptr); properties_, methods_, nullptr, nullptr);
@ -10943,9 +10943,9 @@ JS_DefineDebuggerObject(JSContext* cx, HandleObject obj)
memoryProto(cx); memoryProto(cx);
RootedObject debuggeeWouldRunProto(cx); RootedObject debuggeeWouldRunProto(cx);
RootedValue debuggeeWouldRunCtor(cx); RootedValue debuggeeWouldRunCtor(cx);
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>()); Handle<GlobalObject*> global = obj.as<GlobalObject>();
objProto = global->getOrCreateObjectPrototype(cx); objProto = GlobalObject::getOrCreateObjectPrototype(cx, global);
if (!objProto) if (!objProto)
return false; return false;
debugProto = InitClass(cx, obj, debugProto = InitClass(cx, obj,

View file

@ -256,7 +256,7 @@ static const JSFunctionSpec legacy_generator_methods[] = {
static JSObject* static JSObject*
NewSingletonObjectWithObjectPrototype(JSContext* cx, Handle<GlobalObject*> global) NewSingletonObjectWithObjectPrototype(JSContext* cx, Handle<GlobalObject*> global)
{ {
RootedObject proto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!proto) if (!proto)
return nullptr; return nullptr;
return NewObjectWithGivenProto<PlainObject>(cx, proto, SingletonObject); return NewObjectWithGivenProto<PlainObject>(cx, proto, SingletonObject);
@ -265,7 +265,7 @@ NewSingletonObjectWithObjectPrototype(JSContext* cx, Handle<GlobalObject*> globa
JSObject* JSObject*
js::NewSingletonObjectWithFunctionPrototype(JSContext* cx, Handle<GlobalObject*> global) js::NewSingletonObjectWithFunctionPrototype(JSContext* cx, Handle<GlobalObject*> global)
{ {
RootedObject proto(cx, global->getOrCreateFunctionPrototype(cx)); RootedObject proto(cx, GlobalObject::getOrCreateFunctionPrototype(cx, global));
if (!proto) if (!proto)
return nullptr; return nullptr;
return NewObjectWithGivenProto<PlainObject>(cx, proto, SingletonObject); return NewObjectWithGivenProto<PlainObject>(cx, proto, SingletonObject);
@ -297,9 +297,9 @@ GlobalObject::initStarGenerators(JSContext* cx, Handle<GlobalObject*> global)
if (!iteratorProto) if (!iteratorProto)
return false; return false;
RootedObject genObjectProto(cx, global->createBlankPrototypeInheriting(cx, RootedObject genObjectProto(cx, GlobalObject::createBlankPrototypeInheriting(cx, global,
&PlainObject::class_, &PlainObject::class_,
iteratorProto)); iteratorProto));
if (!genObjectProto) if (!genObjectProto)
return false; return false;
if (!DefinePropertiesAndFunctions(cx, genObjectProto, nullptr, star_generator_methods) || if (!DefinePropertiesAndFunctions(cx, genObjectProto, nullptr, star_generator_methods) ||

View file

@ -337,7 +337,7 @@ GlobalObject::createInternal(JSContext* cx, const Class* clasp)
return global; return global;
} }
GlobalObject* /* static */ GlobalObject*
GlobalObject::new_(JSContext* cx, const Class* clasp, JSPrincipals* principals, GlobalObject::new_(JSContext* cx, const Class* clasp, JSPrincipals* principals,
JS::OnNewGlobalHookOption hookOption, JS::OnNewGlobalHookOption hookOption,
const JS::CompartmentOptions& options) const JS::CompartmentOptions& options)
@ -398,7 +398,7 @@ GlobalObject::emptyGlobalScope() const
GlobalObject::getOrCreateEval(JSContext* cx, Handle<GlobalObject*> global, GlobalObject::getOrCreateEval(JSContext* cx, Handle<GlobalObject*> global,
MutableHandleObject eval) MutableHandleObject eval)
{ {
if (!global->getOrCreateObjectPrototype(cx)) if (!getOrCreateObjectPrototype(cx, global))
return false; return false;
eval.set(&global->getSlot(EVAL).toObject()); eval.set(&global->getSlot(EVAL).toObject());
return true; return true;
@ -573,7 +573,7 @@ GlobalObject::warnOnceAbout(JSContext* cx, HandleObject obj, WarnOnceFlag flag,
return true; return true;
} }
JSFunction* /* static */ JSFunction*
GlobalObject::createConstructor(JSContext* cx, Native ctor, JSAtom* nameArg, unsigned length, GlobalObject::createConstructor(JSContext* cx, Native ctor, JSAtom* nameArg, unsigned length,
gc::AllocKind kind, const JSJitInfo* jitInfo) gc::AllocKind kind, const JSJitInfo* jitInfo)
{ {
@ -601,22 +601,21 @@ CreateBlankProto(JSContext* cx, const Class* clasp, HandleObject proto, HandleOb
return blankProto; return blankProto;
} }
NativeObject* /* static */ NativeObject*
GlobalObject::createBlankPrototype(JSContext* cx, const Class* clasp) GlobalObject::createBlankPrototype(JSContext* cx, Handle<GlobalObject*> global, const Class* clasp)
{ {
Rooted<GlobalObject*> self(cx, this); RootedObject objectProto(cx, getOrCreateObjectPrototype(cx, global));
RootedObject objectProto(cx, getOrCreateObjectPrototype(cx));
if (!objectProto) if (!objectProto)
return nullptr; return nullptr;
return CreateBlankProto(cx, clasp, objectProto, self); return CreateBlankProto(cx, clasp, objectProto, global);
} }
NativeObject* /* static */ NativeObject*
GlobalObject::createBlankPrototypeInheriting(JSContext* cx, const Class* clasp, HandleObject proto) GlobalObject::createBlankPrototypeInheriting(JSContext* cx, Handle<GlobalObject*> global,
const Class* clasp, HandleObject proto)
{ {
Rooted<GlobalObject*> self(cx, this); return CreateBlankProto(cx, clasp, proto, global);
return CreateBlankProto(cx, clasp, proto, self);
} }
bool bool
@ -729,21 +728,20 @@ GlobalObject::hasRegExpStatics() const
return !getSlot(REGEXP_STATICS).isUndefined(); return !getSlot(REGEXP_STATICS).isUndefined();
} }
RegExpStatics* /* static */ RegExpStatics*
GlobalObject::getRegExpStatics(ExclusiveContext* cx) const GlobalObject::getRegExpStatics(ExclusiveContext* cx, Handle<GlobalObject*> global)
{ {
MOZ_ASSERT(cx); MOZ_ASSERT(cx);
Rooted<GlobalObject*> self(cx, const_cast<GlobalObject*>(this));
RegExpStaticsObject* resObj = nullptr; RegExpStaticsObject* resObj = nullptr;
const Value& val = this->getSlot(REGEXP_STATICS); const Value& val = global->getSlot(REGEXP_STATICS);
if (!val.isObject()) { if (!val.isObject()) {
MOZ_ASSERT(val.isUndefined()); MOZ_ASSERT(val.isUndefined());
resObj = RegExpStatics::create(cx, self); resObj = RegExpStatics::create(cx, global);
if (!resObj) if (!resObj)
return nullptr; return nullptr;
self->initSlot(REGEXP_STATICS, ObjectValue(*resObj)); global->initSlot(REGEXP_STATICS, ObjectValue(*resObj));
} else { } else {
resObj = &val.toObject().as<RegExpStaticsObject>(); resObj = &val.toObject().as<RegExpStaticsObject>();
} }
@ -866,7 +864,7 @@ GlobalObject::addIntrinsicValue(JSContext* cx, Handle<GlobalObject*> global,
/* static */ bool /* static */ bool
GlobalObject::ensureModulePrototypesCreated(JSContext *cx, Handle<GlobalObject*> global) GlobalObject::ensureModulePrototypesCreated(JSContext *cx, Handle<GlobalObject*> global)
{ {
return global->getOrCreateObject(cx, MODULE_PROTO, initModuleProto) && return getOrCreateObject(cx, global, MODULE_PROTO, initModuleProto) &&
global->getOrCreateObject(cx, IMPORT_ENTRY_PROTO, initImportEntryProto) && getOrCreateObject(cx, global, IMPORT_ENTRY_PROTO, initImportEntryProto) &&
global->getOrCreateObject(cx, EXPORT_ENTRY_PROTO, initExportEntryProto); getOrCreateObject(cx, global, EXPORT_ENTRY_PROTO, initExportEntryProto);
} }

View file

@ -290,8 +290,8 @@ class GlobalObject : public NativeObject
* Create a constructor function with the specified name and length using * Create a constructor function with the specified name and length using
* ctor, a method which creates objects with the given class. * ctor, a method which creates objects with the given class.
*/ */
JSFunction* static JSFunction*
createConstructor(JSContext* cx, JSNative ctor, JSAtom* name, unsigned length, createConstructor(JSContext* cx, JSNative ctor, JSAtom* name, unsigned length,
gc::AllocKind kind = gc::AllocKind::FUNCTION, gc::AllocKind kind = gc::AllocKind::FUNCTION,
const JSJitInfo* jitInfo = nullptr); const JSJitInfo* jitInfo = nullptr);
@ -303,48 +303,44 @@ class GlobalObject : public NativeObject
* complete the minimal initialization to make the returned object safe to * complete the minimal initialization to make the returned object safe to
* touch. * touch.
*/ */
NativeObject* createBlankPrototype(JSContext* cx, const js::Class* clasp); static NativeObject*
createBlankPrototype(JSContext* cx, Handle<GlobalObject*> global, const js::Class* clasp);
/* /*
* Identical to createBlankPrototype, but uses proto as the [[Prototype]] * Identical to createBlankPrototype, but uses proto as the [[Prototype]]
* of the returned blank prototype. * of the returned blank prototype.
*/ */
NativeObject* createBlankPrototypeInheriting(JSContext* cx, const js::Class* clasp, static NativeObject*
HandleObject proto); createBlankPrototypeInheriting(JSContext* cx, Handle<GlobalObject*> global,
const js::Class* clasp, HandleObject proto);
template <typename T> template <typename T>
T* createBlankPrototype(JSContext* cx) { static T*
NativeObject* res = createBlankPrototype(cx, &T::class_); createBlankPrototype(JSContext* cx, Handle<GlobalObject*> global) {
NativeObject* res = createBlankPrototype(cx, global, &T::class_);
return res ? &res->template as<T>() : nullptr; return res ? &res->template as<T>() : nullptr;
} }
NativeObject* getOrCreateObjectPrototype(JSContext* cx) { static NativeObject*
if (functionObjectClassesInitialized()) getOrCreateObjectPrototype(JSContext* cx, Handle<GlobalObject*> global) {
return &getPrototype(JSProto_Object).toObject().as<NativeObject>(); if (global->functionObjectClassesInitialized())
RootedGlobalObject self(cx, this); return &global->getPrototype(JSProto_Object).toObject().as<NativeObject>();
if (!ensureConstructor(cx, self, JSProto_Object)) if (!ensureConstructor(cx, global, JSProto_Object))
return nullptr; return nullptr;
return &self->getPrototype(JSProto_Object).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_Object).toObject().as<NativeObject>();
} }
static NativeObject* getOrCreateObjectPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
return global->getOrCreateObjectPrototype(cx); getOrCreateFunctionPrototype(JSContext* cx, Handle<GlobalObject*> global) {
} if (global->functionObjectClassesInitialized())
return &global->getPrototype(JSProto_Function).toObject().as<NativeObject>();
NativeObject* getOrCreateFunctionPrototype(JSContext* cx) { if (!ensureConstructor(cx, global, JSProto_Object))
if (functionObjectClassesInitialized())
return &getPrototype(JSProto_Function).toObject().as<NativeObject>();
RootedGlobalObject self(cx, this);
if (!ensureConstructor(cx, self, JSProto_Object))
return nullptr; return nullptr;
return &self->getPrototype(JSProto_Function).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_Function).toObject().as<NativeObject>();
} }
static NativeObject* getOrCreateFunctionPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
return global->getOrCreateFunctionPrototype(cx); getOrCreateArrayPrototype(JSContext* cx, Handle<GlobalObject*> global) {
}
static NativeObject* getOrCreateArrayPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_Array)) if (!ensureConstructor(cx, global, JSProto_Array))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_Array).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_Array).toObject().as<NativeObject>();
@ -356,37 +352,43 @@ class GlobalObject : public NativeObject
return nullptr; return nullptr;
} }
static NativeObject* getOrCreateBooleanPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
getOrCreateBooleanPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_Boolean)) if (!ensureConstructor(cx, global, JSProto_Boolean))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_Boolean).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_Boolean).toObject().as<NativeObject>();
} }
static NativeObject* getOrCreateNumberPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
getOrCreateNumberPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_Number)) if (!ensureConstructor(cx, global, JSProto_Number))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_Number).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_Number).toObject().as<NativeObject>();
} }
static NativeObject* getOrCreateStringPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
getOrCreateStringPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_String)) if (!ensureConstructor(cx, global, JSProto_String))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_String).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_String).toObject().as<NativeObject>();
} }
static NativeObject* getOrCreateSymbolPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
getOrCreateSymbolPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_Symbol)) if (!ensureConstructor(cx, global, JSProto_Symbol))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_Symbol).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_Symbol).toObject().as<NativeObject>();
} }
static NativeObject* getOrCreatePromisePrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
getOrCreatePromisePrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_Promise)) if (!ensureConstructor(cx, global, JSProto_Promise))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_Promise).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_Promise).toObject().as<NativeObject>();
} }
static NativeObject* getOrCreateRegExpPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
getOrCreateRegExpPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_RegExp)) if (!ensureConstructor(cx, global, JSProto_RegExp))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_RegExp).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_RegExp).toObject().as<NativeObject>();
@ -398,28 +400,30 @@ class GlobalObject : public NativeObject
return nullptr; return nullptr;
} }
static NativeObject* getOrCreateSavedFramePrototype(JSContext* cx, static NativeObject*
Handle<GlobalObject*> global) { getOrCreateSavedFramePrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_SavedFrame)) if (!ensureConstructor(cx, global, JSProto_SavedFrame))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_SavedFrame).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_SavedFrame).toObject().as<NativeObject>();
} }
static JSObject* getOrCreateArrayBufferPrototype(JSContext* cx, Handle<GlobalObject*> global) { static JSObject*
getOrCreateArrayBufferPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_ArrayBuffer)) if (!ensureConstructor(cx, global, JSProto_ArrayBuffer))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_ArrayBuffer).toObject(); return &global->getPrototype(JSProto_ArrayBuffer).toObject();
} }
JSObject* getOrCreateSharedArrayBufferPrototype(JSContext* cx, Handle<GlobalObject*> global) { static JSObject*
getOrCreateSharedArrayBufferPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_SharedArrayBuffer)) if (!ensureConstructor(cx, global, JSProto_SharedArrayBuffer))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_SharedArrayBuffer).toObject(); return &global->getPrototype(JSProto_SharedArrayBuffer).toObject();
} }
static JSObject* getOrCreateCustomErrorPrototype(JSContext* cx, static JSObject*
Handle<GlobalObject*> global, getOrCreateCustomErrorPrototype(JSContext* cx, Handle<GlobalObject*> global,
JSExnType exnType) JSExnType exnType)
{ {
JSProtoKey key = GetExceptionProtoKey(exnType); JSProtoKey key = GetExceptionProtoKey(exnType);
if (!ensureConstructor(cx, global, key)) if (!ensureConstructor(cx, global, key))
@ -439,35 +443,41 @@ class GlobalObject : public NativeObject
return getOrCreateCustomErrorPrototype(cx, global, JSEXN_ERR); return getOrCreateCustomErrorPrototype(cx, global, JSEXN_ERR);
} }
static NativeObject* getOrCreateSetPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
getOrCreateSetPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_Set)) if (!ensureConstructor(cx, global, JSProto_Set))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_Set).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_Set).toObject().as<NativeObject>();
} }
static NativeObject* getOrCreateWeakSetPrototype(JSContext* cx, Handle<GlobalObject*> global) { static NativeObject*
getOrCreateWeakSetPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, global, JSProto_WeakSet)) if (!ensureConstructor(cx, global, JSProto_WeakSet))
return nullptr; return nullptr;
return &global->getPrototype(JSProto_WeakSet).toObject().as<NativeObject>(); return &global->getPrototype(JSProto_WeakSet).toObject().as<NativeObject>();
} }
JSObject* getOrCreateIntlObject(JSContext* cx) { static JSObject*
return getOrCreateObject(cx, APPLICATION_SLOTS + JSProto_Intl, initIntlObject); getOrCreateIntlObject(JSContext* cx, Handle<GlobalObject*> global) {
return getOrCreateObject(cx, global, APPLICATION_SLOTS + JSProto_Intl, initIntlObject);
} }
JSObject* getOrCreateTypedObjectModule(JSContext* cx) { static JSObject*
return getOrCreateObject(cx, APPLICATION_SLOTS + JSProto_TypedObject, initTypedObjectModule); getOrCreateTypedObjectModule(JSContext* cx, Handle<GlobalObject*> global) {
return getOrCreateObject(cx, global, APPLICATION_SLOTS + JSProto_TypedObject,
initTypedObjectModule);
} }
JSObject* getOrCreateSimdGlobalObject(JSContext* cx) { static JSObject*
return getOrCreateObject(cx, APPLICATION_SLOTS + JSProto_SIMD, initSimdObject); getOrCreateSimdGlobalObject(JSContext* cx, Handle<GlobalObject*> global) {
return getOrCreateObject(cx, global, APPLICATION_SLOTS + JSProto_SIMD, initSimdObject);
} }
// Get the type descriptor for one of the SIMD types. // Get the type descriptor for one of the SIMD types.
// simdType is one of the JS_SIMDTYPEREPR_* constants. // simdType is one of the JS_SIMDTYPEREPR_* constants.
// Implemented in builtin/SIMD.cpp. // Implemented in builtin/SIMD.cpp.
static SimdTypeDescr* getOrCreateSimdTypeDescr(JSContext* cx, Handle<GlobalObject*> global, static SimdTypeDescr*
SimdType simdType); getOrCreateSimdTypeDescr(JSContext* cx, Handle<GlobalObject*> global, SimdType simdType);
TypedObjectModuleObject& getTypedObjectModule() const; TypedObjectModuleObject& getTypedObjectModule() const;
@ -475,16 +485,19 @@ class GlobalObject : public NativeObject
return &getPrototype(JSProto_Iterator).toObject(); return &getPrototype(JSProto_Iterator).toObject();
} }
JSObject* getOrCreateCollatorPrototype(JSContext* cx) { static JSObject*
return getOrCreateObject(cx, COLLATOR_PROTO, initIntlObject); getOrCreateCollatorPrototype(JSContext* cx, Handle<GlobalObject*> global) {
return getOrCreateObject(cx, global, COLLATOR_PROTO, initIntlObject);
} }
JSObject* getOrCreateNumberFormatPrototype(JSContext* cx) { static JSObject*
return getOrCreateObject(cx, NUMBER_FORMAT_PROTO, initIntlObject); getOrCreateNumberFormatPrototype(JSContext* cx, Handle<GlobalObject*> global) {
return getOrCreateObject(cx, global, NUMBER_FORMAT_PROTO, initIntlObject);
} }
JSObject* getOrCreateDateTimeFormatPrototype(JSContext* cx) { static JSObject*
return getOrCreateObject(cx, DATE_TIME_FORMAT_PROTO, initIntlObject); getOrCreateDateTimeFormatPrototype(JSContext* cx, Handle<GlobalObject*> global) {
return getOrCreateObject(cx, global, DATE_TIME_FORMAT_PROTO, initIntlObject);
} }
static bool ensureModulePrototypesCreated(JSContext *cx, Handle<GlobalObject*> global); static bool ensureModulePrototypesCreated(JSContext *cx, Handle<GlobalObject*> global);
@ -539,88 +552,86 @@ class GlobalObject : public NativeObject
private: private:
typedef bool (*ObjectInitOp)(JSContext* cx, Handle<GlobalObject*> global); typedef bool (*ObjectInitOp)(JSContext* cx, Handle<GlobalObject*> global);
JSObject* getOrCreateObject(JSContext* cx, unsigned slot, ObjectInitOp init) { static JSObject*
Value v = getSlotRef(slot); getOrCreateObject(JSContext* cx, Handle<GlobalObject*> global, unsigned slot,
ObjectInitOp init)
{
Value v = global->getSlotRef(slot);
if (v.isObject()) if (v.isObject())
return &v.toObject(); return &v.toObject();
RootedGlobalObject self(cx, this); if (!init(cx, global))
if (!init(cx, self))
return nullptr; return nullptr;
return &self->getSlot(slot).toObject(); return &global->getSlot(slot).toObject();
} }
public: public:
static NativeObject* getOrCreateIteratorPrototype(JSContext* cx, Handle<GlobalObject*> global) static NativeObject*
{ getOrCreateIteratorPrototype(JSContext* cx, Handle<GlobalObject*> global) {
return MaybeNativeObject(global->getOrCreateObject(cx, ITERATOR_PROTO, initIteratorProto)); return MaybeNativeObject(getOrCreateObject(cx, global, ITERATOR_PROTO, initIteratorProto));
} }
static NativeObject* getOrCreateArrayIteratorPrototype(JSContext* cx, Handle<GlobalObject*> global) static NativeObject*
{ getOrCreateArrayIteratorPrototype(JSContext* cx, Handle<GlobalObject*> global) {
return MaybeNativeObject(global->getOrCreateObject(cx, ARRAY_ITERATOR_PROTO, initArrayIteratorProto)); return MaybeNativeObject(getOrCreateObject(cx, global, ARRAY_ITERATOR_PROTO,
initArrayIteratorProto));
} }
static NativeObject* getOrCreateStringIteratorPrototype(JSContext* cx, static NativeObject*
Handle<GlobalObject*> global) getOrCreateStringIteratorPrototype(JSContext* cx, Handle<GlobalObject*> global) {
{ return MaybeNativeObject(getOrCreateObject(cx, global, STRING_ITERATOR_PROTO,
return MaybeNativeObject(global->getOrCreateObject(cx, STRING_ITERATOR_PROTO, initStringIteratorProto)); initStringIteratorProto));
} }
static NativeObject* getOrCreateLegacyGeneratorObjectPrototype(JSContext* cx, static NativeObject*
Handle<GlobalObject*> global) getOrCreateLegacyGeneratorObjectPrototype(JSContext* cx, Handle<GlobalObject*> global) {
{ return MaybeNativeObject(getOrCreateObject(cx, global, LEGACY_GENERATOR_OBJECT_PROTO,
return MaybeNativeObject(global->getOrCreateObject(cx, LEGACY_GENERATOR_OBJECT_PROTO, initLegacyGeneratorProto));
initLegacyGeneratorProto));
} }
static NativeObject* getOrCreateStarGeneratorObjectPrototype(JSContext* cx, static NativeObject*
Handle<GlobalObject*> global) getOrCreateStarGeneratorObjectPrototype(JSContext* cx, Handle<GlobalObject*> global)
{ {
return MaybeNativeObject(global->getOrCreateObject(cx, STAR_GENERATOR_OBJECT_PROTO, initStarGenerators)); return MaybeNativeObject(getOrCreateObject(cx, global, STAR_GENERATOR_OBJECT_PROTO,
initStarGenerators));
} }
static NativeObject* getOrCreateStarGeneratorFunctionPrototype(JSContext* cx, static NativeObject*
Handle<GlobalObject*> global) getOrCreateStarGeneratorFunctionPrototype(JSContext* cx, Handle<GlobalObject*> global) {
{ return MaybeNativeObject(getOrCreateObject(cx, global, STAR_GENERATOR_FUNCTION_PROTO,
return MaybeNativeObject(global->getOrCreateObject(cx, STAR_GENERATOR_FUNCTION_PROTO, initStarGenerators)); initStarGenerators));
} }
static JSObject* getOrCreateStarGeneratorFunction(JSContext* cx, static JSObject*
Handle<GlobalObject*> global) getOrCreateStarGeneratorFunction(JSContext* cx, Handle<GlobalObject*> global) {
{ return getOrCreateObject(cx, global, STAR_GENERATOR_FUNCTION, initStarGenerators);
return global->getOrCreateObject(cx, STAR_GENERATOR_FUNCTION, initStarGenerators);
} }
static NativeObject* getOrCreateAsyncFunctionPrototype(JSContext* cx, static NativeObject*
Handle<GlobalObject*> global) getOrCreateAsyncFunctionPrototype(JSContext* cx, Handle<GlobalObject*> global) {
{ return MaybeNativeObject(getOrCreateObject(cx, global, ASYNC_FUNCTION_PROTO,
return MaybeNativeObject(global->getOrCreateObject(cx, ASYNC_FUNCTION_PROTO, initAsyncFunction));
initAsyncFunction));
} }
static JSObject* getOrCreateAsyncFunction(JSContext* cx, static JSObject*
Handle<GlobalObject*> global) getOrCreateAsyncFunction(JSContext* cx, Handle<GlobalObject*> global) {
{ return getOrCreateObject(cx, global, ASYNC_FUNCTION, initAsyncFunction);
return global->getOrCreateObject(cx, ASYNC_FUNCTION, initAsyncFunction);
} }
static JSObject* getOrCreateMapIteratorPrototype(JSContext* cx, static JSObject*
Handle<GlobalObject*> global) getOrCreateMapIteratorPrototype(JSContext* cx, Handle<GlobalObject*> global) {
{ return getOrCreateObject(cx, global, MAP_ITERATOR_PROTO, initMapIteratorProto);
return global->getOrCreateObject(cx, MAP_ITERATOR_PROTO, initMapIteratorProto);
} }
static JSObject* getOrCreateSetIteratorPrototype(JSContext* cx, static JSObject*
Handle<GlobalObject*> global) getOrCreateSetIteratorPrototype(JSContext* cx, Handle<GlobalObject*> global) {
{ return getOrCreateObject(cx, global, SET_ITERATOR_PROTO, initSetIteratorProto);
return global->getOrCreateObject(cx, SET_ITERATOR_PROTO, initSetIteratorProto);
} }
JSObject* getOrCreateDataViewPrototype(JSContext* cx) { static JSObject*
RootedGlobalObject self(cx, this); getOrCreateDataViewPrototype(JSContext* cx, Handle<GlobalObject*> global) {
if (!ensureConstructor(cx, self, JSProto_DataView)) if (!ensureConstructor(cx, global, JSProto_DataView))
return nullptr; return nullptr;
return &self->getPrototype(JSProto_DataView).toObject(); return &global->getPrototype(JSProto_DataView).toObject();
} }
static JSFunction* static JSFunction*
@ -678,8 +689,9 @@ class GlobalObject : public NativeObject
return true; return true;
} }
static bool getIntrinsicValue(JSContext* cx, Handle<GlobalObject*> global, static bool
HandlePropertyName name, MutableHandleValue value) getIntrinsicValue(JSContext* cx, Handle<GlobalObject*> global,
HandlePropertyName name, MutableHandleValue value)
{ {
bool exists = false; bool exists = false;
if (!GlobalObject::maybeGetIntrinsicValue(cx, global, name, value, &exists)) if (!GlobalObject::maybeGetIntrinsicValue(cx, global, name, value, &exists))
@ -709,7 +721,8 @@ class GlobalObject : public NativeObject
unsigned nargs, MutableHandleValue funVal); unsigned nargs, MutableHandleValue funVal);
bool hasRegExpStatics() const; bool hasRegExpStatics() const;
RegExpStatics* getRegExpStatics(ExclusiveContext* cx) const; static RegExpStatics* getRegExpStatics(ExclusiveContext* cx,
Handle<GlobalObject*> global);
RegExpStatics* getAlreadyCreatedRegExpStatics() const; RegExpStatics* getAlreadyCreatedRegExpStatics() const;
JSObject* getThrowTypeError() const { JSObject* getThrowTypeError() const {
@ -996,7 +1009,7 @@ GenericCreateConstructor(JSContext* cx, JSProtoKey key)
// Note - We duplicate the trick from ClassName() so that we don't need to // Note - We duplicate the trick from ClassName() so that we don't need to
// include jsatominlines.h here. // include jsatominlines.h here.
PropertyName* name = (&cx->names().Null)[key]; PropertyName* name = (&cx->names().Null)[key];
return cx->global()->createConstructor(cx, ctor, name, length, kind, jitInfo); return GlobalObject::createConstructor(cx, ctor, name, length, kind, jitInfo);
} }
inline JSObject* inline JSObject*
@ -1009,7 +1022,7 @@ GenericCreatePrototype(JSContext* cx, JSProtoKey key)
if (!GlobalObject::ensureConstructor(cx, cx->global(), protoKey)) if (!GlobalObject::ensureConstructor(cx, cx->global(), protoKey))
return nullptr; return nullptr;
RootedObject parentProto(cx, &cx->global()->getPrototype(protoKey).toObject()); RootedObject parentProto(cx, &cx->global()->getPrototype(protoKey).toObject());
return cx->global()->createBlankPrototypeInheriting(cx, clasp, parentProto); return GlobalObject::createBlankPrototypeInheriting(cx, cx->global(), clasp, parentProto);
} }
inline JSProtoKey inline JSProtoKey

View file

@ -199,7 +199,7 @@ RegExpObject::trace(JSTracer* trc, JSObject* obj)
static JSObject* static JSObject*
CreateRegExpPrototype(JSContext* cx, JSProtoKey key) CreateRegExpPrototype(JSContext* cx, JSProtoKey key)
{ {
return cx->global()->createBlankPrototype(cx, &RegExpObject::protoClass_); return GlobalObject::createBlankPrototype(cx, cx->global(), &RegExpObject::protoClass_);
} }
static const ClassOps RegExpObjectClassOps = { static const ClassOps RegExpObjectClassOps = {

View file

@ -366,7 +366,8 @@ static const Class SharedArrayBufferObjectProtoClass = {
static JSObject* static JSObject*
CreateSharedArrayBufferPrototype(JSContext* cx, JSProtoKey key) CreateSharedArrayBufferPrototype(JSContext* cx, JSProtoKey key)
{ {
return cx->global()->createBlankPrototype(cx, &SharedArrayBufferObjectProtoClass); return GlobalObject::createBlankPrototype(cx, cx->global(),
&SharedArrayBufferObjectProtoClass);
} }
static const ClassOps SharedArrayBufferObjectClassOps = { static const ClassOps SharedArrayBufferObjectClassOps = {

View file

@ -361,7 +361,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
return nullptr; return nullptr;
const Class* clasp = TypedArrayObject::protoClassForType(ArrayTypeID()); const Class* clasp = TypedArrayObject::protoClassForType(ArrayTypeID());
return global->createBlankPrototypeInheriting(cx, clasp, typedArrayProto); return GlobalObject::createBlankPrototypeInheriting(cx, global, clasp, typedArrayProto);
} }
static JSObject* static JSObject*
@ -1892,7 +1892,7 @@ DataViewObject::constructWrapped(JSContext* cx, HandleObject bufobj, const CallA
Rooted<GlobalObject*> global(cx, cx->compartment()->maybeGlobal()); Rooted<GlobalObject*> global(cx, cx->compartment()->maybeGlobal());
if (!proto) { if (!proto) {
proto = global->getOrCreateDataViewPrototype(cx); proto = GlobalObject::getOrCreateDataViewPrototype(cx, global);
if (!proto) if (!proto)
return false; return false;
} }
@ -2892,12 +2892,13 @@ DataViewObject::initClass(JSContext* cx)
if (global->isStandardClassResolved(JSProto_DataView)) if (global->isStandardClassResolved(JSProto_DataView))
return true; return true;
RootedNativeObject proto(cx, global->createBlankPrototype(cx, &DataViewObject::protoClass)); RootedNativeObject proto(cx, GlobalObject::createBlankPrototype(cx, global,
&DataViewObject::protoClass));
if (!proto) if (!proto)
return false; return false;
RootedFunction ctor(cx, global->createConstructor(cx, DataViewObject::class_constructor, RootedFunction ctor(cx, GlobalObject::createConstructor(cx, DataViewObject::class_constructor,
cx->names().DataView, 3)); cx->names().DataView, 3));
if (!ctor) if (!ctor)
return false; return false;

View file

@ -2018,7 +2018,7 @@ js::InitWebAssemblyClass(JSContext* cx, HandleObject obj)
Handle<GlobalObject*> global = obj.as<GlobalObject>(); Handle<GlobalObject*> global = obj.as<GlobalObject>();
MOZ_ASSERT(!global->isStandardClassResolved(JSProto_WebAssembly)); MOZ_ASSERT(!global->isStandardClassResolved(JSProto_WebAssembly));
RootedObject proto(cx, global->getOrCreateObjectPrototype(cx)); RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
if (!proto) if (!proto)
return nullptr; return nullptr;