void InitGlobalObjectOptions(JS::CompartmentOptions& aOptions, nsIPrincipal* aPrincipal) { bool shouldDiscardSystemSource = ShouldDiscardSystemSource(); bool extraWarningsForSystemJS = ExtraWarningsForSystemJS(); bool isSystem = nsContentUtils::IsSystemPrincipal(aPrincipal); if (isSystem) { // Make sure [SecureContext] APIs are visible: aOptions.creationOptions().setSecureContext(true); } short status = aPrincipal->GetAppStatus(); // Enable the ECMA-402 experimental formatToParts in certified apps. if (status == nsIPrincipal::APP_STATUS_CERTIFIED) { aOptions.creationOptions() .setExperimentalDateTimeFormatFormatToPartsEnabled(true); } if (shouldDiscardSystemSource) { bool discardSource = isSystem || (status == nsIPrincipal::APP_STATUS_PRIVILEGED || status == nsIPrincipal::APP_STATUS_CERTIFIED); aOptions.behaviors().setDiscardSource(discardSource); } if (extraWarningsForSystemJS) { if (isSystem) aOptions.behaviors().extraWarningsOverride().set(true); } }
void InitGlobalObjectOptions(JS::CompartmentOptions& aOptions, nsIPrincipal* aPrincipal) { bool shouldDiscardSystemSource = ShouldDiscardSystemSource(); bool extraWarningsForSystemJS = ExtraWarningsForSystemJS(); bool isSystem = nsContentUtils::IsSystemPrincipal(aPrincipal); if (isSystem) { // Make sure [SecureContext] APIs are visible: aOptions.creationOptions().setSecureContext(true); #if 0 // TODO: Reenable in Bug 1288653 // Enable the ECMA-402 experimental formatToParts in any chrome page aOptions.creationOptions() .setExperimentalDateTimeFormatFormatToPartsEnabled(true); #endif } if (shouldDiscardSystemSource) { bool discardSource = isSystem; aOptions.behaviors().setDiscardSource(discardSource); } if (extraWarningsForSystemJS) { if (isSystem) aOptions.behaviors().extraWarningsOverride().set(true); } }
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; }