GlobalObject* GlobalObject::new_(JSContext* cx, const Class* clasp, JSPrincipals* principals, JS::OnNewGlobalHookOption hookOption, const JS::CompartmentOptions& options) { MOZ_ASSERT(!cx->isExceptionPending()); MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment())); JSRuntime* rt = cx->runtime(); auto zoneSpecifier = options.creationOptions().zoneSpecifier(); Zone* zone; if (zoneSpecifier == JS::SystemZone) zone = rt->gc.systemZone; else if (zoneSpecifier == JS::FreshZone) zone = nullptr; else zone = static_cast<Zone*>(options.creationOptions().zonePointer()); JSCompartment* compartment = NewCompartment(cx, zone, principals, options); if (!compartment) return nullptr; // Lazily create the system zone. if (!rt->gc.systemZone && zoneSpecifier == JS::SystemZone) { rt->gc.systemZone = compartment->zone(); rt->gc.systemZone->isSystem = true; } Rooted<GlobalObject*> global(cx); { AutoCompartment ac(cx, compartment); global = GlobalObject::createInternal(cx, clasp); if (!global) return nullptr; } if (hookOption == JS::FireOnNewGlobalHook) JS_FireOnNewGlobalObject(cx, global); return global; }