Commit 371b3c1d authored by Tooru Fujisawa's avatar Tooru Fujisawa
Browse files

Bug 1607331 - Part 3: Reject global this usage in JSM. r=Standard8

parent 47585c78
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ const CURRENT_WEBCHANNEL_VERSION = 1;

// Lazily load the require function, when it's needed.
ChromeUtils.defineModuleGetter(
  // eslint-disable-next-line mozilla/reject-global-this
  this,
  "require",
  "resource://devtools/shared/loader/Loader.jsm"
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ The plugin implements the following rules:
   eslint-plugin-mozilla/prefer-formatValues
   eslint-plugin-mozilla/reject-addtask-only
   eslint-plugin-mozilla/reject-chromeutils-import-params
   eslint-plugin-mozilla/reject-global-this
   eslint-plugin-mozilla/reject-importGlobalProperties
   eslint-plugin-mozilla/reject-osfile
   eslint-plugin-mozilla/reject-relative-requires
+29 −0
Original line number Diff line number Diff line
reject-global-this
======================

Rejects global ``this`` usage in JSM files.  The global ``this`` is not
available in ESM, and this is a preparation for the migration.

Examples of incorrect code for this rule:
-----------------------------------------

.. code-block:: js

    this.EXPORTED_SYMBOLS = ["foo"];

    XPCOMUtils.defineLazyModuleGetters(this, {
      AddonManager: "resource://gre/modules/AddonManager.jsm",
    });


Examples of correct code for this rule:
---------------------------------------

.. code-block:: js

    const EXPORTED_SYMBOLS = ["foo"];

    const lazy = {};
    XPCOMUtils.defineLazyModuleGetters(lazy, {
      AddonManager: "resource://gre/modules/AddonManager.jsm",
    });
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@

if (typeof Components != "undefined") {
  // Specify exported symbols for JSM module loader.
  //
  // (bug 1773390)
  // eslint-disable-next-line mozilla/reject-global-this
  this.EXPORTED_SYMBOLS = ["AndroidLog"];
  var { ctypes } = ChromeUtils.import("resource://gre/modules/ctypes.jsm");
}
+4 −0
Original line number Diff line number Diff line
@@ -35,8 +35,10 @@ if (typeof Components != "undefined") {
  // Global definition of |exports|, to keep everybody happy.
  // In non-main thread, |exports| is provided by the module
  // loader.
  // eslint-disable-next-line mozilla/reject-global-this
  this.exports = {};
  ({ Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"));
  // eslint-disable-next-line mozilla/reject-global-this
  this.Services = Services;
  Meta = ChromeUtils.import("resource://gre/modules/PromiseWorker.jsm")
    .BasePromiseWorker.Meta;
@@ -1362,8 +1364,10 @@ Object.defineProperty(exports.OS.Shared, "TEST", {

// /////////////////// Permanent boilerplate
if (typeof Components != "undefined") {
  // eslint-disable-next-line mozilla/reject-global-this
  this.EXPORTED_SYMBOLS = EXPORTED_SYMBOLS;
  for (let symbol of EXPORTED_SYMBOLS) {
    // eslint-disable-next-line mozilla/reject-global-this
    this[symbol] = exports[symbol];
  }
}
Loading