Commit 2337bc54 authored by Tooru Fujisawa's avatar Tooru Fujisawa
Browse files

Bug 1772299 - Reject modification to globalThis inside system module....

Bug 1772299 - Reject modification to globalThis inside system module. r=Standard8,webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D148116
parent 381a82e5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ The plugin implements the following rules:
   eslint-plugin-mozilla/reject-addtask-only
   eslint-plugin-mozilla/reject-chromeutils-import-params
   eslint-plugin-mozilla/reject-global-this
   eslint-plugin-mozilla/reject-globalThis-modification
   eslint-plugin-mozilla/reject-importGlobalProperties
   eslint-plugin-mozilla/reject-osfile
   eslint-plugin-mozilla/reject-relative-requires
+19 −0
Original line number Diff line number Diff line
reject-globalThis-modification
==============================

Reject any modification to ``globalThis`` inside the system modules.

``globalThis`` is the shared global inside the system modules, and modification
on it is visible from all modules, and it shouldn't be done unless it's really
necessary.

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

.. code-block:: js

    globalThis.foo = 10;
    Object.defineProperty(globalThis, "bar", { value: 20});
    XPCOMUtils.defineLazyModuleGetters(globalThis, {
      Services: "resource://gre/modules/Services.jsm",
    });
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ XPCOMUtils.defineLazyGetter(lazy, "ConsoleAPIStorage", () => {
});

// Import the `Debugger` constructor in the current scope
// eslint-disable-next-line mozilla/reject-globalThis-modification
addDebuggerToGlobal(globalThis);

const CONSOLE_API_LEVEL_MAP = {
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ var EXPORTED_SYMBOLS = ["CoverageCollector"];
const { addDebuggerToGlobal } = ChromeUtils.import(
  "resource://gre/modules/jsdebugger.jsm"
);
// eslint-disable-next-line mozilla/reject-globalThis-modification
addDebuggerToGlobal(globalThis);

/**
+2 −0
Original line number Diff line number Diff line
@@ -1297,6 +1297,8 @@ function certDecoderInitializer(
  return { parse, pemToDER };
}

// This must be removed when all consumer is converted to ES module.
// eslint-disable-next-line mozilla/reject-globalThis-modification
globalThis.certDecoderInitializer = certDecoderInitializer;
/* eslint-disable-next-line no-unused-vars */
var EXPORTED_SYMBOLS = ["certDecoderInitializer"];
Loading