Bug 1170550 - Don't crash when registering a service worker which has a strict mode error; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 02 Jun 2015 10:08:58 -0400
changeset 246862 959c2bd7e15e2fa1f458ef4f13aa1db878bb0f11
parent 246861 780ec82ee92a86e8e3f5d9a81b5a7c0f94feab2a
child 246863 c2939bd290fabbfa7d64af7c2b392bb3cc399310
push id28843
push usercbook@mozilla.com
push dateWed, 03 Jun 2015 11:50:02 +0000
treeherdermozilla-central@6c612d7adbf5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1170550
milestone41.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 1170550 - Don't crash when registering a service worker which has a strict mode error; r=baku
dom/workers/ServiceWorkerManager.cpp
dom/workers/test/serviceworkers/mochitest.ini
dom/workers/test/serviceworkers/strict_mode_error.js
dom/workers/test/serviceworkers/test_strict_mode_error.html
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -785,16 +785,21 @@ public:
     callback->UpdateFailed(aError);
     FailCommon(NS_ERROR_DOM_JS_EXCEPTION);
   }
 
   // Public so our error handling code can continue with a successful worker.
   void
   ContinueInstall()
   {
+    // mRegistration will be null if we have already Fail()ed.
+    if (!mRegistration) {
+      return;
+    }
+
     // Even if we are canceled, ensure integrity of mSetOfScopesBeingUpdated
     // first.
     nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
     MOZ_ASSERT(swm->mSetOfScopesBeingUpdated.Contains(mRegistration->mScope));
     swm->mSetOfScopesBeingUpdated.Remove(mRegistration->mScope);
     // This is effectively the end of Step 4.3 of the [[Update]] algorithm.
     // The invocation of [[Install]] is not part of the atomic block.
 
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -101,16 +101,17 @@ support-files =
   app-protocol/*
   force_refresh_worker.js
   sw_clients/refresher.html
   sw_clients/refresher_compressed.html
   sw_clients/refresher_compressed.html^headers^
   sw_clients/refresher_cached.html
   sw_clients/refresher_cached_compressed.html
   sw_clients/refresher_cached_compressed.html^headers^
+  strict_mode_error.js
 
 [test_unregister.html]
 [test_installation_simple.html]
 [test_fetch_event.html]
 [test_https_fetch.html]
 [test_https_fetch_cloned_response.html]
 [test_https_synth_fetch_from_cached_sw.html]
 [test_match_all.html]
@@ -141,8 +142,9 @@ support-files =
 [test_claim.html]
 [test_periodic_https_update.html]
 [test_sanitize.html]
 [test_sanitize_domain.html]
 [test_service_worker_allowed.html]
 [test_app_protocol.html]
 [test_claim_fetch.html]
 [test_force_refresh.html]
+[test_strict_mode_error.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/strict_mode_error.js
@@ -0,0 +1,4 @@
+function f() {
+  return 1;
+  return 2;
+}
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/test_strict_mode_error.html
@@ -0,0 +1,39 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Bug 1170550 - test registration of service worker scripts with a strict mode error</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test"></pre>
+<script class="testbody" type="text/javascript">
+
+  function runTest() {
+    navigator.serviceWorker
+      .register("strict_mode_error.js", {scope: "strict_mode_error"})
+      .catch(() => {
+        ok(true, "Registration failed as expected");
+        SimpleTest.finish();
+      });
+  }
+
+  SimpleTest.waitForExplicitFinish();
+  onload = function() {
+    SpecialPowers.pushPrefEnv({"set": [
+      ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+      ["dom.serviceWorkers.enabled", true],
+      ["dom.serviceWorkers.testing.enabled", true],
+    ]}, runTest);
+  };
+</script>
+</pre>
+</body>
+</html>