Bug 1368992 - JS bytecode cache: Do not attempt to encode bytecode if the compilation failed. r=mrbkap
authorNicolas B. Pierron <nicolas.b.pierron@mozilla.com>
Tue, 06 Jun 2017 12:04:29 +0000
changeset 410687 0148cb8a72728c4e16a58659a97c30aaf9e218a5
parent 410686 42350bacb0bc3aa1f6c5daeb1377af74fb32001c
child 410688 99e99af157c2a7b38f9919fc3647d26bd36c9c1d
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1368992
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1368992 - JS bytecode cache: Do not attempt to encode bytecode if the compilation failed. r=mrbkap
dom/base/test/file_js_cache_syntax_error.html
dom/base/test/file_js_cache_syntax_error.js
dom/base/test/mochitest.ini
dom/base/test/test_script_loader_js_cache.html
dom/script/ScriptLoader.cpp
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_js_cache_syntax_error.html
@@ -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>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_js_cache_syntax_error.js
@@ -0,0 +1,1 @@
+var // SyntaxError: missing variable name.
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -755,16 +755,18 @@ skip-if = toolkit == 'android'
 [test_script_loader_crossorigin_data_url.html]
 [test_script_loader_js_cache.html]
 support-files =
   file_js_cache.html
   file_js_cache_with_sri.html
   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]
 [test_settimeout_inner.html]
 [test_setTimeoutWith0.html]
 [test_setting_opener.html]
 [test_simplecontentpolicy.html]
 skip-if = e10s # Bug 1156489.
--- a/dom/base/test/test_script_loader_js_cache.html
+++ b/dom/base/test/test_script_loader_js_cache.html
@@ -186,15 +186,32 @@
       // should be recorded before the bytecode is stored in the cache.
       var stateMachineResult =
           WaitForScriptTagEvent("file_js_cache_save_after_load.html");
       assert_equals(await stateMachineResult, "bytecode_saved & ping(=3)",
                     "Wait on all scripts to be executed");
 
     }, "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>
 <body>
   <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=900784">Mozilla Bug 900784</a>
 </body>
 </html>
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -2127,17 +2127,17 @@ ScriptLoader::EvaluateScript(ScriptLoadR
               LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest));
               nsAutoString inlineData;
               SourceBufferHolder srcBuf = GetScriptSource(aRequest, inlineData);
               rv = exec.CompileAndExec(options, srcBuf, &script);
             }
           }
 
           // 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");
             MOZ_ASSERT(aRequest->mBytecodeOffset == aRequest->mScriptBytecode.length());
             RegisterForBytecodeEncoding(aRequest);
           } else {
             LOG(("ScriptLoadRequest (%p): Bytecode-cache: disabled (rv = %X, script = %p)",
                  aRequest, unsigned(rv), script.get()));