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

This commit is contained in:
Bobby Holley 2014-04-22 14:08:28 -07:00
Родитель 2a54864f28
Коммит e1d5378ac6
3 изменённых файлов: 26 добавлений и 0 удалений

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

@ -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);

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

@ -3510,6 +3510,7 @@ XPCJSRuntime::GetCompilationScope()
NS_ENSURE_SUCCESS(rv, nullptr);
mCompilationScope = js::UncheckedUnwrap(&v.toObject());
CompartmentOptionsRef(mCompilationScope).setDiscardSource(ShouldDiscardSystemSource());
}
return mCompilationScope;
}

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

@ -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);