Bug 990353 - Flag for discarding where appropriate. r=bent

This commit is contained in:
Bobby Holley 2014-04-18 23:46:27 -07:00
Родитель db5dd8dd81
Коммит 861c2a9611
4 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -748,7 +748,8 @@ nsXULPDGlobalObject::GetCompilationGlobal()
AutoSafeJSContext cx;
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setInvisibleToDebugger(true);
.setInvisibleToDebugger(true)
.setDiscardSource(xpc::ShouldDiscardSystemSource());
mJSObject = JS_NewGlobalObject(cx, &gSharedGlobalClass,
nsJSPrincipals::get(GetPrincipal()),
JS::DontFireOnNewGlobalHook, options);

Просмотреть файл

@ -699,6 +699,20 @@ ScriptExecutorRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
NS_ASSERTION(global, "Must have a global by now!");
// Determine whether we want to be discarding source on this global to save
// memory. It would make more sense to do this when we create the global, but
// the information behind UsesSystemPrincipal() et al isn't finalized until
// the call to SetPrincipal during the first script load. After that, however,
// it never changes. So we can just idempotently set the bits here.
//
// Note that we read a pref that is cached on the main thread. This is benignly
// racey.
if (xpc::ShouldDiscardSystemSource()) {
bool discard = aWorkerPrivate->UsesSystemPrincipal() ||
aWorkerPrivate->IsInPrivilegedApp();
JS::CompartmentOptionsRef(global).setDiscardSource(discard);
}
for (uint32_t index = mFirstIndex; index <= mLastIndex; index++) {
ScriptLoadInfo& loadInfo = loadInfos.ElementAt(index);

Просмотреть файл

@ -168,7 +168,8 @@ nsXBLDocGlobalObject::GetCompilationGlobal()
AutoSafeJSContext cx;
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setInvisibleToDebugger(true);
.setInvisibleToDebugger(true)
.setDiscardSource(xpc::ShouldDiscardSystemSource());
mJSObject = JS_NewGlobalObject(cx, &gSharedGlobalClass,
nsJSPrincipals::get(GetPrincipal()),
JS::DontFireOnNewGlobalHook,

Просмотреть файл

@ -414,6 +414,17 @@ InitGlobalObject(JSContext* aJSContext, JS::Handle<JSObject*> aGlobal, uint32_t
}
}
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);
}
// Stuff coming through this path always ends up as a DOM global.
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL);