Bug 1349989: Correctly handle errors for OMT-compiled scripts. r?shu draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 23 Mar 2017 22:13:07 -0700
changeset 504302 8845613f92c427957ae268a71ebeaacfb71b92d3
parent 504301 f2eebe34cd1aa205570f0ff30734c3f0a8cab705
child 550625 817db2f8179effc008dd0f9d0d33b96aee61d0ac
push id50772
push usermaglione.k@gmail.com
push dateFri, 24 Mar 2017 05:32:31 +0000
reviewersshu
bugs1349989
milestone55.0a1
Bug 1349989: Correctly handle errors for OMT-compiled scripts. r?shu MozReview-Commit-ID: 3FpoUmu9ijI
js/xpconnect/loader/ChromeScriptLoader.cpp
js/xpconnect/tests/unit/test_compileScript.js
--- a/js/xpconnect/loader/ChromeScriptLoader.cpp
+++ b/js/xpconnect/loader/ChromeScriptLoader.cpp
@@ -164,18 +164,21 @@ AsyncScriptCompiler::Run()
 
     return NS_OK;
 }
 
 void
 AsyncScriptCompiler::FinishCompile(JSContext* aCx)
 {
     Rooted<JSScript*> script(aCx, JS::FinishOffThreadScript(aCx, mToken));
-
-    Finish(aCx, script);
+    if (script) {
+        Finish(aCx, script);
+    } else {
+        Reject(aCx);
+    }
 }
 
 
 void
 AsyncScriptCompiler::Finish(JSContext* aCx, Handle<JSScript*> aScript)
 {
     RefPtr<PrecompiledScript> result = new PrecompiledScript(mGlobalObject, aScript, mOptions);
 
--- a/js/xpconnect/tests/unit/test_compileScript.js
+++ b/js/xpconnect/tests/unit/test_compileScript.js
@@ -48,8 +48,25 @@ add_task(function*() {
   equal(sandbox2.bar, null);
 
   obj = script2.executeInGlobal(sandbox2);
   equal(obj, undefined, "No-return script has no return value");
 
   equal(Cu.getObjectPrincipal(sandbox2.bar).origin, "http://example.org", "Object value origin is correct");
   equal(sandbox2.bar.foo, "\u00ae", "Object value has the correct charset");
 });
+
+add_task(function* test_syntaxError() {
+  // Generate an artificially large script to force off-main-thread
+  // compilation.
+  let scriptUrl = `data:,${";".repeat(1024 * 1024)}(`;
+
+  yield Assert.rejects(
+    ChromeUtils.compileScript(scriptUrl),
+    /SyntaxError: expected expression, got end of script/);
+
+  // Generate a small script to force main thread compilation.
+  scriptUrl = `data:,;(`;
+
+  yield Assert.rejects(
+    ChromeUtils.compileScript(scriptUrl),
+    /SyntaxError: expected expression, got end of script/);
+});