Bug 1319638 - Part 1: Use Function+eval in require() in worker. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Wed, 01 Mar 2017 13:34:45 +0900
changeset 394250 21725697b47bb567ea027e3f91faf333c76e43c8
parent 394249 547321d210ec1914212be67f2c4d77a8047094f2
child 394251 182d11502abef1b63c6225f28d3629a04dfb9514
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1319638
milestone54.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 1319638 - Part 1: Use Function+eval in require() in worker. r=Yoric
toolkit/components/workerloader/require.js
toolkit/components/workerloader/tests/moduleE-throws-during-require.js
toolkit/components/workerloader/tests/moduleG-throws-later.js
--- a/toolkit/components/workerloader/require.js
+++ b/toolkit/components/workerloader/require.js
@@ -129,20 +129,23 @@
         xhr.send();
 
 
         let source = xhr.responseText;
         if (source == "") {
           // There doesn't seem to be a better way to detect that the file couldn't be found
           throw new Error("Could not find module " + path);
         }
+        // Use `Function` to leave this scope, use `eval` to start the line
+        // number from 1 that is observed by `source` and the error message
+        // thrown from the module, and also use `arguments` for accessing
+        // `source` and `uri` to avoid polluting the module's environment.
         let code = new Function("exports", "require", "module",
-          source + "\n//# sourceURL=" + uri + "\n"
-        );
-        code(exports, require, module);
+          `eval(arguments[3] + "\\n//# sourceURL=" + arguments[4] + "\\n")`);
+        code(exports, require, module, source, uri);
       } catch (ex) {
         // Module loading has failed, exports should not be made available
         // after all.
         modules.delete(path);
         throw ex;
       }
 
       Object.freeze(module.exports);
--- a/toolkit/components/workerloader/tests/moduleE-throws-during-require.js
+++ b/toolkit/components/workerloader/tests/moduleE-throws-during-require.js
@@ -1,12 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /* eslint-env commonjs */
 
 // Skip a few lines
-// 5
-// 6
 // 7
 // 8
 // 9
+// 10
+// 11
 throw new Error("Let's see if this error is obtained with the right origin");
--- a/toolkit/components/workerloader/tests/moduleG-throws-later.js
+++ b/toolkit/components/workerloader/tests/moduleG-throws-later.js
@@ -1,14 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /* eslint-env commonjs */
 
 // Skip a few lines
-// 5
-// 6
 // 7
 // 8
 // 9
+// 10
+// 11
 exports.doThrow = function doThrow() {
   Array.prototype.sort.apply("foo"); // This will raise a native TypeError
 };