Bug 926902 - Incorrect error locations for errors from scripts importScripts'ed by the frameworker, r=markh.
authorFlorian Quèze <florian@queze.net>
Wed, 16 Oct 2013 00:59:19 +0200
changeset 165686 8c8de10998cb42ff3a7cafb470c5602d040c0e6e
parent 165685 bb7cbe5f16d3719a40c401febcaa96c8207095ae
child 165687 2ac3c7f8b12ccaf9df0345c0ec52bcb9787de055
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs926902
milestone27.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 926902 - Incorrect error locations for errors from scripts importScripts'ed by the frameworker, r=markh.
toolkit/components/social/FrameWorkerContent.js
toolkit/components/social/MessagePortWorker.js
toolkit/components/social/test/browser/relative_import.js
toolkit/components/social/test/browser/worker_relative.js
--- a/toolkit/components/social/FrameWorkerContent.js
+++ b/toolkit/components/social/FrameWorkerContent.js
@@ -132,18 +132,20 @@ FrameWorker.prototype = {
       // interface NavigatorOnLine
       get onLine() workerWindow.navigator.onLine
     };
     sandbox.navigator = navigator;
 
     // Our importScripts function needs to 'eval' the script code from inside
     // a function, but using eval() directly means functions in the script
     // don't end up in the global scope.
-    sandbox._evalInSandbox = function(s) {
-      Cu.evalInSandbox(s, sandbox);
+    sandbox._evalInSandbox = function(s, url) {
+      let baseURI = Services.io.newURI(workerWindow.location.href, null, null);
+      Cu.evalInSandbox(s, sandbox, "1.8",
+                       Services.io.newURI(url, null, baseURI).spec, 1);
     };
 
     // and we delegate ononline and onoffline events to the worker.
     // See http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#workerglobalscope
     workerWindow.addEventListener('offline', function fw_onoffline(event) {
       Cu.evalInSandbox("onoffline();", sandbox);
     }, false);
     workerWindow.addEventListener('online', function fw_ononline(event) {
--- a/toolkit/components/social/MessagePortWorker.js
+++ b/toolkit/components/social/MessagePortWorker.js
@@ -29,17 +29,17 @@ function importScripts() {
   for (var i=0; i < arguments.length; i++) {
     // load the url *synchronously*
     var scriptURL = arguments[i];
     var xhr = new XMLHttpRequest();
     xhr.open('GET', scriptURL, false);
     xhr.onreadystatechange = function(aEvt) {
       if (xhr.readyState == 4) {
         if (xhr.status == 200 || xhr.status == 0) {
-          _evalInSandbox(xhr.responseText);
+          _evalInSandbox(xhr.responseText, scriptURL);
         }
         else {
           throw new Error("Unable to importScripts ["+scriptURL+"], status " + xhr.status)
         }
       }
     };
     xhr.send(null);
   }
--- a/toolkit/components/social/test/browser/relative_import.js
+++ b/toolkit/components/social/test/browser/relative_import.js
@@ -1,6 +1,9 @@
 dump("relative_import file\n");
 
+// Please keep 'causeError' on line 4; we test the error location.
+function causeError() { does_not_exist(); }
+
 testVar = "oh hai";
 function testFunc() {
   return "oh hai";
 }
--- a/toolkit/components/social/test/browser/worker_relative.js
+++ b/toolkit/components/social/test/browser/worker_relative.js
@@ -1,19 +1,32 @@
 // Used to test XHR in the worker.
 onconnect = function(e) {
   let port = e.ports[0];
   let req;
   try {
     importScripts("relative_import.js");
     // the import should have exposed "testVar" and "testFunc" from the module.
-    if (testVar == "oh hai" && testFunc() == "oh hai") {
-      port.postMessage({topic: "done", result: "ok"});
-    } else {
+    if (testVar != "oh hai" || testFunc() != "oh hai") {
       port.postMessage({topic: "done", result: "import worked but global is not available"});
+      return;
     }
-    return;
+
+    // causeError will cause a script error, so that we can check the
+    // error location for importScripts'ed files is correct.
+    try {
+      causeError();
+    } catch(e) {
+      let fileName = e.fileName;
+      if (fileName.startsWith("http") &&
+          fileName.endsWith("/relative_import.js") &&
+          e.lineNumber == 4)
+        port.postMessage({topic: "done", result: "ok"});
+      else
+        port.postMessage({topic: "done", result: "invalid error location: " + fileName + ":" + e.lineNumber});
+      return;
+    }
   } catch(e) {
     port.postMessage({topic: "done", result: "FAILED to importScripts, " + e.toString() });
     return;
   }
   port.postMessage({topic: "done", result: "FAILED to importScripts, no exception" });
 }