Bug 1368992 - JS bytecode cache: Do not attempt to encode bytecode if the compilation failed. r=mrbkap

This commit is contained in:
Nicolas B. Pierron 2017-06-06 12:04:29 +00:00
parent 148f24bb56
commit 558a57a171
5 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Do not save bytecode on compilation errors</title>
</head>
<body>
<script id="watchme" src="file_js_cache_syntax_error.js"></script>
</body>
</html>

View File

@ -0,0 +1 @@
var // SyntaxError: missing variable name.

View File

@ -760,6 +760,8 @@ support-files =
file_js_cache.js
file_js_cache_save_after_load.html
file_js_cache_save_after_load.js
file_js_cache_syntax_error.html
file_js_cache_syntax_error.js
[test_setInterval_uncatchable_exception.html]
skip-if = debug == false
[test_settimeout_extra_arguments.html]

View File

@ -191,6 +191,23 @@
}, "Save bytecode after the initialization of the page");
promise_test(async function() {
// (see above)
await SpecialPowers.pushPrefEnv({set: [
['dom.script_loader.bytecode_cache.enabled', true],
['dom.expose_test_interfaces', true],
['dom.script_loader.bytecode_cache.strategy', -1]
]});
// The test page loads a script which contains a syntax error, we should
// not attempt to encode any bytecode for it.
var stateMachineResult =
WaitForScriptTagEvent("file_js_cache_syntax_error.html");
assert_equals(await stateMachineResult, "source_exec",
"Check the lack of bytecode encoding");
}, "Do not save bytecode on compilation errors");
done();
</script>
</head>

View File

@ -2132,7 +2132,7 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
}
// Queue the current script load request to later save the bytecode.
if (NS_SUCCEEDED(rv) && encodeBytecode) {
if (script && encodeBytecode) {
aRequest->mScript = script;
HoldJSObjects(aRequest);
TRACE_FOR_TEST(aRequest->mElement, "scriptloader_encode");