Bug 1322981 - Correct management of JS exceptions in Worklet, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 14 Dec 2016 15:24:33 +0100
changeset 325821 80b23ce5f23f3d1a45618a92d7e369e26964b651
parent 325820 ed5c93dfd7dd4e1a751a5b99db7ca8fd9c6280ce
child 325822 302107a735500f83471a9ab397d63b755714b1f4
push id84812
push useramarchesini@mozilla.com
push dateWed, 14 Dec 2016 14:24:48 +0000
treeherdermozilla-inbound@80b23ce5f23f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1322981
milestone53.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 1322981 - Correct management of JS exceptions in Worklet, r=smaug
dom/worklet/Worklet.cpp
dom/worklet/tests/file_exception.html
dom/worklet/tests/mochitest.ini
dom/worklet/tests/test_exception.html
dom/worklet/tests/worklet_exception.js
--- a/dom/worklet/Worklet.cpp
+++ b/dom/worklet/Worklet.cpp
@@ -204,16 +204,17 @@ public:
 
     // We only need the setNoScriptRval bit when compiling off-thread here,
     // since otherwise nsJSUtils::EvaluateString will set it up for us.
     compileOptions.setNoScriptRval(true);
 
     JS::Rooted<JS::Value> unused(cx);
     if (!JS::Evaluate(cx, compileOptions, buffer, &unused)) {
       ErrorResult error;
+      error.MightThrowJSException();
       error.StealExceptionFromJSContext(cx);
       RejectPromises(error.StealNSResult());
       return NS_OK;
     }
 
     // All done.
     ResolvePromises();
     return NS_OK;
new file mode 100644
--- /dev/null
+++ b/dom/worklet/tests/file_exception.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for Exceptions in Worklet</title>
+  <script type="application/javascript" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+setupTest();
+
+// This loading should fail
+audioWorklet.import("404.js")
+.then(() => {
+  ok(false, "We should not be called!");
+}, () => {
+  ok(true, "The script thrown but we are still here.");
+})
+
+// This should throw from JS
+.then(() => {
+  return audioWorklet.import("worklet_exception.js")
+})
+.then(() => {
+  ok(false, "We should not be called!");
+}, () => {
+  ok(true, "The script thrown but we are still here.");
+})
+
+.then(() => {
+  SimpleTest.finish();
+});
+
+</script>
+</body>
+</html>
--- a/dom/worklet/tests/mochitest.ini
+++ b/dom/worklet/tests/mochitest.ini
@@ -8,8 +8,10 @@ support-files=file_basic.html
 [test_console.html]
 support-files=file_console.html worklet_console.js
 [test_import_with_cache.html]
 support-files=file_import_with_cache.html server_import_with_cache.sjs
 [test_dump.html]
 support-files=file_dump.html worklet_dump.js
 [test_audioWorklet.html]
 support-files=file_audioWorklet.html worklet_audioWorklet.js
+[test_exception.html]
+support-files=file_exception.html worklet_exception.js
new file mode 100644
--- /dev/null
+++ b/dom/worklet/tests/test_exception.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for Exception in Worklet script</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv(
+  {"set": [["dom.audioWorklet.enabled", true],
+           ["dom.worklet.enabled", true]]},
+  function() { loadTest("file_exception.html"); });
+
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/worklet/tests/worklet_exception.js
@@ -0,0 +1,1 @@
+foobar();