None draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 25 Nov 2019 19:36:34 +0000
changeset 2496018 0e015715b0abf9ab6f0e529012b27c57da69a86d
parent 2496017 8e1a78600b41711af9af87944985fbab5848123b
child 2496019 7df9e6addf62354e63606f2685d1e60f06bede71
push id455265
push userreviewbot
push dateMon, 25 Nov 2019 19:36:52 +0000
treeherdertry@7df9e6addf62 [default view] [failures only]
milestone72.0a1
None Differential Diff: PHID-DIFF-heu4la44xsoe4g3o7m4r
testing/specialpowers/content/SpecialPowersSandbox.jsm
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js
--- a/testing/specialpowers/content/SpecialPowersSandbox.jsm
+++ b/testing/specialpowers/content/SpecialPowersSandbox.jsm
@@ -13,23 +13,30 @@
 var EXPORTED_SYMBOLS = ["SpecialPowersSandbox"];
 
 ChromeUtils.defineModuleGetter(
   this,
   "Assert",
   "resource://testing-common/Assert.jsm"
 );
 
+// Note: When updating the set of globals exposed to sandboxes by
+// default, please also update the ESLint plugin rule defined in
+// import-content-task-globals.js.
 const SANDBOX_GLOBALS = [
   "Blob",
   "ChromeUtils",
   "TextDecoder",
   "TextEncoder",
   "URL",
 ];
+const EXTRA_IMPORTS = {
+  EventUtils: "resource://specialpowers/SpecialPowersEventUtils.jsm",
+  Services: "resource://gre/modules/Services.jsm",
+};
 
 let expectFail = false;
 function expectingFail(fn) {
   try {
     expectFail = true;
     fn();
   } finally {
     expectFail = false;
@@ -57,24 +64,26 @@ class SpecialPowersSandbox {
           return this.Assert;
         },
         enumerable: true,
         configurable: true,
       });
     }
 
     let imports = {
-      EventUtils: "resource://specialpowers/SpecialPowersEventUtils.jsm",
-      Services: "resource://gre/modules/Services.jsm",
+      ...EXTRA_IMPORTS,
       ...opts.imports,
     };
     for (let [symbol, url] of Object.entries(imports)) {
       ChromeUtils.defineModuleGetter(this.sandbox, symbol, url);
     }
 
+    // Note: When updating the set of globals exposed to sandboxes by
+    // default, please also update the ESLint plugin rule defined in
+    // import-content-task-globals.js.
     Object.assign(this.sandbox, {
       BrowsingContext,
       ok: (...args) => {
         this.Assert.ok(...args);
       },
       is: (...args) => {
         this.Assert.equal(...args);
       },
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js
@@ -31,10 +31,43 @@ module.exports = function(context) {
       for (let global in frameScriptEnv.globals) {
         helpers.addVarToScope(
           global,
           context.getScope(),
           frameScriptEnv.globals[global]
         );
       }
     },
+    "CallExpression[callee.object.name='SpecialPowers'][callee.property.name='spawn']": function(
+      node
+    ) {
+      // The global environment of SpecialPowers.spawn tasks is
+      // controlled by the Sandbox environment created by
+      // SpecialPowersSandbox.jsm. This list should be kept in sync with
+      // that module.
+      let globals = [
+        "Assert",
+        "Blob",
+        "BrowsingContext",
+        "ChromeUtils",
+        "ContentTaskUtils",
+        "EventUtils",
+        "Services",
+        "SpecialPowers",
+        "TextDecoder",
+        "TextEncoder",
+        "URL",
+        "assert",
+        "content",
+        "docShell",
+        "info",
+        "is",
+        "isnot",
+        "ok",
+        "todo",
+        "todo_is",
+      ];
+      for (let global of globals) {
+        helpers.addVarToScope(global, context.getScope(), false);
+      }
+    },
   };
 };