Bug 1249673. Muted errors should be turned into NetworkError DOMExceptions when returning from importScripts on workers, instead of becoming NS_ERROR_FAILURE. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 24 Feb 2016 10:38:31 -0500
changeset 285337 ee07c6a974bccea9ccf6b3bdcf4874b79308b188
parent 285336 af4680dcbeb15fa3787454e17f7af24c7feaecda
child 285338 b3d204d5c6b730c12d5d63c6b29815b7a35f4e81
push id72326
push userbzbarsky@mozilla.com
push dateWed, 24 Feb 2016 15:38:49 +0000
treeherdermozilla-inbound@ee07c6a974bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1249673
milestone47.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 1249673. Muted errors should be turned into NetworkError DOMExceptions when returning from importScripts on workers, instead of becoming NS_ERROR_FAILURE. r=baku
dom/workers/ScriptLoader.cpp
dom/workers/test/importScripts_3rdParty_worker.js
--- a/dom/workers/ScriptLoader.cpp
+++ b/dom/workers/ScriptLoader.cpp
@@ -1874,29 +1874,28 @@ ScriptExecutorRunnable::ShutdownScriptLo
   }
 
   if (!aResult) {
     // At this point there are two possibilities:
     //
     // 1) mScriptLoader.mRv.Failed().  In that case we just want to leave it
     //    as-is, except if it has a JS exception and we need to mute JS
     //    exceptions.  In that case, we log the exception without firing any
-    //    events and then replace it on the ErrorResult with a generic
-    //    NS_ERROR_FAILURE for lack of anything better.  XXXbz: This should
-    //    throw a NetworkError per spec updates.  See bug 1249673.
+    //    events and then replace it on the ErrorResult with a NetworkError,
+    //    per spec.
     //
     // 2) mScriptLoader.mRv succeeded.  As far as I can tell, this can only
     //    happen when loading the main worker script and
     //    GetOrCreateGlobalScope() fails or if ScriptExecutorRunnable::Cancel
     //    got called.  Does it matter what we throw in this case?  I'm not
     //    sure...
     if (mScriptLoader.mRv.Failed()) {
       if (aMutedError && mScriptLoader.mRv.IsJSException()) {
         LogExceptionToConsole(aCx, aWorkerPrivate);
-        mScriptLoader.mRv.Throw(NS_ERROR_FAILURE);
+        mScriptLoader.mRv.Throw(NS_ERROR_DOM_NETWORK_ERR);
       }
     } else {
       mScriptLoader.mRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     }
   }
 
   aWorkerPrivate->RemoveFeature(aCx, &mScriptLoader);
   aWorkerPrivate->StopSyncLoop(mSyncLoopTarget, aResult);
--- a/dom/workers/test/importScripts_3rdParty_worker.js
+++ b/dom/workers/test/importScripts_3rdParty_worker.js
@@ -24,44 +24,48 @@ onmessage = function(a) {
 
   // This is cross-origin URL.
   var crossOriginURL = new URL(a.data.url);
   crossOriginURL.host = 'example.com';
   crossOriginURL.port = 80;
   var fileName2 = 42;
 
   if (a.data.test == 'none') {
-    importScripts([crossOriginURL.href]);
+    importScripts(crossOriginURL.href);
     return;
   }
 
   try {
-    importScripts([sameOriginURL.href]);
+    importScripts(sameOriginURL.href);
   } catch(e) {
     if (!(e instanceof SyntaxError)) {
       postMessage({ result: false });
       return;
     }
 
     fileName1 = e.fileName;
   }
 
   if (fileName1 != sameOriginURL.href || !fileName1) {
     postMessage({ result: false });
     return;
   }
 
   if (a.data.test == 'try') {
+    var exception;
     try {
-      importScripts([crossOriginURL.href]);
+      importScripts(crossOriginURL.href);
     } catch(e) {
       fileName2 = e.filename;
+      exception = e;
     }
 
-    postMessage({ result: fileName2 == workerURL });
+    postMessage({ result: fileName2 == workerURL &&
+                          exception.name == "NetworkError" &&
+                          exception.code == DOMException.NETWORK_ERR });
     return;
   }
 
   if (a.data.test == 'eventListener') {
     addEventListener("error", function(event) {
       event.preventDefault();
       postMessage({result: event instanceof ErrorEvent &&
                            event.filename == workerURL });
@@ -69,10 +73,10 @@ onmessage = function(a) {
   }
 
   if (a.data.test == 'onerror') {
     onerror = function(...args) {
       postMessage({result: args[1] == workerURL });
     }
   }
 
-  importScripts([crossOriginURL.href]);
+  importScripts(crossOriginURL.href);
 }