зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1689734 - Cleanup lazy-source in nsFrameMessageManager if using ScriptPreloader. r=kmag
For consistency with other uses of the ScriptPreloader, we ensure we use lazy script source when compiling for the cache. This generates full bytecode for the cache but also avoids saving a copy of the source. If the frame script were to call Function.prototype.toString, the existing source-hook would load it in the same way as the JSM loader. In practice, we avoid relying on this in our chrome code. If we will not be writing to the cache, we can instead compile with the JS syntax parser, similar to what we do for JSM loader. Differential Revision: https://phabricator.services.mozilla.com/D103515
This commit is contained in:
Родитель
b97c12efa4
Коммит
a70f9b9fe5
|
@ -1236,8 +1236,17 @@ void nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
|
|||
// message manager per process, treat this script as run-once. Run-once
|
||||
// scripts can be compiled directly for the target global, and will be dropped
|
||||
// from the preloader cache after they're executed and serialized.
|
||||
//
|
||||
// NOTE: This does not affect the JS::CompileOptions. We generate the same
|
||||
// bytecode as though it were run multiple times. This is required for the
|
||||
// batch decoding from ScriptPreloader to work.
|
||||
bool isRunOnce = !aShouldCache || IsProcessScoped();
|
||||
|
||||
// We don't cache data: scripts!
|
||||
nsAutoCString scheme;
|
||||
uri->GetScheme(scheme);
|
||||
bool useScriptPreloader = aShouldCache && !scheme.EqualsLiteral("data");
|
||||
|
||||
// If the script will be reused in this session, compile it in the compilation
|
||||
// scope instead of the current global to avoid keeping the current
|
||||
// compartment alive.
|
||||
|
@ -1251,6 +1260,7 @@ void nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
|
|||
ScriptPreloader::FillCompileOptionsForCachedScript(options);
|
||||
options.setFileAndLine(url.get(), 1);
|
||||
options.setNonSyntacticScope(true);
|
||||
options.setSourceIsLazy(true);
|
||||
|
||||
JS::Rooted<JSScript*> script(cx);
|
||||
script =
|
||||
|
@ -1290,6 +1300,12 @@ void nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
|
|||
return;
|
||||
}
|
||||
|
||||
// If we are not encoding to the ScriptPreloader cache, we can now relax the
|
||||
// compile options and use the JS syntax-parser for lower latency.
|
||||
if (!useScriptPreloader || !ScriptPreloader::GetChildSingleton().Active()) {
|
||||
options.setSourceIsLazy(false);
|
||||
}
|
||||
|
||||
JS::UniqueTwoByteChars srcChars(dataStringBuf);
|
||||
|
||||
JS::SourceText<char16_t> srcBuf;
|
||||
|
@ -1306,10 +1322,7 @@ void nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
|
|||
MOZ_ASSERT(script);
|
||||
aScriptp.set(script);
|
||||
|
||||
nsAutoCString scheme;
|
||||
uri->GetScheme(scheme);
|
||||
// We don't cache data: scripts!
|
||||
if (aShouldCache && !scheme.EqualsLiteral("data")) {
|
||||
if (useScriptPreloader) {
|
||||
ScriptPreloader::GetChildSingleton().NoteScript(url, url, script,
|
||||
isRunOnce);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче