bool InitGlobalObject(JSContext* aJSContext, JS::Handle<JSObject*> aGlobal, uint32_t aFlags) { // Immediately enter the global's compartment, so that everything else we // create ends up there. JSAutoCompartment ac(aJSContext, aGlobal); if (!(aFlags & nsIXPConnect::OMIT_COMPONENTS_OBJECT)) { // XPCCallContext gives us an active request needed to save/restore. if (!CompartmentPrivate::Get(aGlobal)->scope->AttachComponentsObject(aJSContext) || !XPCNativeWrapper::AttachNewConstructorObject(aJSContext, aGlobal)) { return UnexpectedFailure(false); } } if (ShouldDiscardSystemSource()) { nsIPrincipal *prin = GetObjectPrincipal(aGlobal); bool isSystem = nsContentUtils::IsSystemPrincipal(prin); if (!isSystem) { short status = prin->GetAppStatus(); isSystem = status == nsIPrincipal::APP_STATUS_PRIVILEGED || status == nsIPrincipal::APP_STATUS_CERTIFIED; } JS::CompartmentOptionsRef(aGlobal).setDiscardSource(isSystem); } if (ExtraWarningsForSystemJS()) { nsIPrincipal *prin = GetObjectPrincipal(aGlobal); bool isSystem = nsContentUtils::IsSystemPrincipal(prin); if (isSystem) JS::CompartmentOptionsRef(aGlobal).extraWarningsOverride().set(true); } // Stuff coming through this path always ends up as a DOM global. MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL); // Init WebIDL binding constructors wanted on all XPConnect globals. // // XXX Please do not add any additional classes here without the approval of // the XPConnect module owner. if (!PromiseBinding::GetConstructorObject(aJSContext, aGlobal) || !TextDecoderBinding::GetConstructorObject(aJSContext, aGlobal) || !TextEncoderBinding::GetConstructorObject(aJSContext, aGlobal) || !DOMErrorBinding::GetConstructorObject(aJSContext, aGlobal)) { return UnexpectedFailure(false); } if (!(aFlags & nsIXPConnect::DONT_FIRE_ONNEWGLOBALHOOK)) JS_FireOnNewGlobalObject(aJSContext, aGlobal); return true; }
bool InitGlobalObject(JSContext* aJSContext, JS::Handle<JSObject*> aGlobal, uint32_t aFlags) { // Immediately enter the global's compartment so that everything we create // ends up there. JSAutoCompartment ac(aJSContext, aGlobal); // Stuff coming through this path always ends up as a DOM global. MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL); if (!(aFlags & nsIXPConnect::OMIT_COMPONENTS_OBJECT)) { // XPCCallContext gives us an active request needed to save/restore. if (!CompartmentPrivate::Get(aGlobal)->scope->AttachComponentsObject(aJSContext) || !XPCNativeWrapper::AttachNewConstructorObject(aJSContext, aGlobal)) { return UnexpectedFailure(false); } } if (!(aFlags & nsIXPConnect::DONT_FIRE_ONNEWGLOBALHOOK)) JS_FireOnNewGlobalObject(aJSContext, aGlobal); return true; }