summaryrefslogtreecommitdiffstats
path: root/tools/lint/eslint/eslint-plugin-mozilla/lib/environments
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lint/eslint/eslint-plugin-mozilla/lib/environments')
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js118
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-script.js28
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-worker.js25
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/frame-script.js39
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js31
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/privileged.js805
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/process-script.js38
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/remote-page.js40
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/simpletest.js35
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/sjs.js30
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/special-powers-sandbox.js46
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/specific.js31
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/utils.js62
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/xpcshell.js59
14 files changed, 1387 insertions, 0 deletions
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
new file mode 100644
index 0000000000..6b40dedd45
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
@@ -0,0 +1,118 @@
+/**
+ * @fileoverview Defines the environment when in the browser.xhtml window.
+ * Imports many globals from various files.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+// -----------------------------------------------------------------------------
+// Rule Definition
+// -----------------------------------------------------------------------------
+
+var fs = require("fs");
+var helpers = require("../helpers");
+var { getScriptGlobals } = require("./utils");
+
+// When updating EXTRA_SCRIPTS or MAPPINGS, be sure to also update the
+// 'support-files' config in `tools/lint/eslint.yml`.
+
+// These are scripts not loaded from browser.xhtml or global-scripts.inc
+// but via other includes.
+const EXTRA_SCRIPTS = [
+ "browser/base/content/nsContextMenu.js",
+ "browser/components/downloads/content/downloads.js",
+ "browser/components/downloads/content/indicator.js",
+ "toolkit/content/customElements.js",
+ "toolkit/content/editMenuOverlay.js",
+];
+
+const extraDefinitions = [
+ // Via Components.utils, defineModuleGetter, defineLazyModuleGetters or
+ // defineLazyScriptGetter (and map to
+ // single) variable.
+ { name: "XPCOMUtils", writable: false },
+ { name: "Task", writable: false },
+ { name: "windowGlobalChild", writable: false },
+ // structuredClone is a new global that would be defined for the `browser`
+ // environment in ESLint, but only Firefox has implemented it currently and so
+ // it isn't in ESLint's globals yet.
+ // https://developer.mozilla.org/docs/Web/API/structuredClone
+ { name: "structuredClone", writable: false },
+];
+
+// Some files in global-scripts.inc need mapping to specific locations.
+const MAPPINGS = {
+ "printUtils.js": "toolkit/components/printing/content/printUtils.js",
+ "panelUI.js": "browser/components/customizableui/content/panelUI.js",
+ "viewSourceUtils.js":
+ "toolkit/components/viewsource/content/viewSourceUtils.js",
+ "browserPlacesViews.js":
+ "browser/components/places/content/browserPlacesViews.js",
+ "places-tree.js": "browser/components/places/content/places-tree.js",
+ "places-menupopup.js":
+ "browser/components/places/content/places-menupopup.js",
+};
+
+const globalScriptsRegExp = /^\s*Services.scriptloader.loadSubScript\(\"(.*?)\", this\);$/;
+
+function getGlobalScriptIncludes(scriptPath) {
+ let fileData;
+ try {
+ fileData = fs.readFileSync(scriptPath, { encoding: "utf8" });
+ } catch (ex) {
+ // The file isn't present, so this isn't an m-c repository.
+ return null;
+ }
+
+ fileData = fileData.split("\n");
+
+ let result = [];
+
+ for (let line of fileData) {
+ let match = line.match(globalScriptsRegExp);
+ if (match) {
+ let sourceFile = match[1]
+ .replace(
+ "chrome://browser/content/search/",
+ "browser/components/search/content/"
+ )
+ .replace(
+ "chrome://browser/content/screenshots/",
+ "browser/components/screenshots/content/"
+ )
+ .replace("chrome://browser/content/", "browser/base/content/")
+ .replace("chrome://global/content/", "toolkit/content/");
+
+ for (let mapping of Object.getOwnPropertyNames(MAPPINGS)) {
+ if (sourceFile.includes(mapping)) {
+ sourceFile = MAPPINGS[mapping];
+ }
+ }
+
+ result.push(sourceFile);
+ }
+ }
+
+ return result;
+}
+
+function getGlobalScripts() {
+ let results = [];
+ for (let scriptPath of helpers.globalScriptPaths) {
+ results = results.concat(getGlobalScriptIncludes(scriptPath));
+ }
+ return results;
+}
+
+module.exports = getScriptGlobals(
+ "browser-window",
+ getGlobalScripts().concat(EXTRA_SCRIPTS),
+ extraDefinitions,
+ {
+ browserjsScripts: getGlobalScripts().concat(EXTRA_SCRIPTS),
+ }
+);
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-script.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-script.js
new file mode 100644
index 0000000000..9b0ae54a2e
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-script.js
@@ -0,0 +1,28 @@
+/**
+ * @fileoverview Defines the environment for SpecialPowers chrome script.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+var { globals } = require("./special-powers-sandbox");
+var util = require("util");
+
+module.exports = {
+ globals: util._extend(
+ {
+ // testing/specialpowers/content/SpecialPowersParent.sys.mjs
+
+ // SPLoadChromeScript block
+ createWindowlessBrowser: false,
+ sendAsyncMessage: false,
+ addMessageListener: false,
+ removeMessageListener: false,
+ actorParent: false,
+ },
+ globals
+ ),
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-worker.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-worker.js
new file mode 100644
index 0000000000..db5759b26c
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/chrome-worker.js
@@ -0,0 +1,25 @@
+/**
+ * @fileoverview Defines the environment for chrome workers. This differs
+ * from normal workers by the fact that `ctypes` can be accessed
+ * as well.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+var globals = require("globals");
+var util = require("util");
+
+var workerGlobals = util._extend(
+ {
+ ctypes: false,
+ },
+ globals.worker
+);
+
+module.exports = {
+ globals: workerGlobals,
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/frame-script.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/frame-script.js
new file mode 100644
index 0000000000..7ac5c941cf
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/frame-script.js
@@ -0,0 +1,39 @@
+/**
+ * @fileoverview Defines the environment for frame scripts.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ // dom/chrome-webidl/MessageManager.webidl
+
+ // MessageManagerGlobal
+ dump: false,
+ atob: false,
+ btoa: false,
+
+ // MessageListenerManagerMixin
+ addMessageListener: false,
+ removeMessageListener: false,
+ addWeakMessageListener: false,
+ removeWeakMessageListener: false,
+
+ // MessageSenderMixin
+ sendAsyncMessage: false,
+ processMessageManager: false,
+ remoteType: false,
+
+ // SyncMessageSenderMixin
+ sendSyncMessage: false,
+
+ // ContentFrameMessageManager
+ content: false,
+ docShell: false,
+ tabEventTarget: false,
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
new file mode 100644
index 0000000000..1ff73c04d9
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
@@ -0,0 +1,31 @@
+/**
+ * @fileoverview Defines the environment for jsm files.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ // These globals are hard-coded and available in .jsm scopes.
+ // https://searchfox.org/mozilla-central/rev/dcb0cfb66e4ed3b9c7fbef1e80572426ff5f3c3a/js/xpconnect/loader/mozJSModuleLoader.cpp#222-223
+ // Although `debug` is allowed for jsm files, this is non-standard and something
+ // we don't want to allow in mjs files. Hence it is not included here.
+ atob: false,
+ btoa: false,
+ dump: false,
+ // The WebAssembly global is available in most (if not all) contexts where
+ // JS can run. It's definitely available in JSMs. So even if this is not
+ // the perfect place to add it, it's not wrong, and we can move it later.
+ WebAssembly: false,
+ // These are hard-coded and available in .jsm scopes.
+ // See BackstagePass::Resolve.
+ fetch: false,
+ crypto: false,
+ indexedDB: false,
+ structuredClone: false,
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/privileged.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/privileged.js
new file mode 100644
index 0000000000..89162cdb2f
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/privileged.js
@@ -0,0 +1,805 @@
+/**
+ * @fileoverview Defines the environment for privileges JS files.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ // Intl and WebAssembly are available everywhere but are not webIDL definitions.
+ Intl: false,
+ WebAssembly: false,
+ // This list of items is currently obtained manually from the list of
+ // mozilla::dom::constructor::id::ID enumerations in an object directory
+ // generated dom/bindings/RegisterBindings.cpp
+ APZHitResultFlags: false,
+ AbortController: false,
+ AbortSignal: false,
+ AccessibleNode: false,
+ Addon: false,
+ AddonEvent: false,
+ AddonInstall: false,
+ AddonManager: true,
+ AddonManagerPermissions: false,
+ AnalyserNode: false,
+ Animation: false,
+ AnimationEffect: false,
+ AnimationEvent: false,
+ AnimationPlaybackEvent: false,
+ AnimationTimeline: false,
+ AnonymousContent: false,
+ Attr: false,
+ AudioBuffer: false,
+ AudioBufferSourceNode: false,
+ AudioContext: false,
+ AudioDestinationNode: false,
+ AudioListener: false,
+ AudioNode: false,
+ AudioParam: false,
+ AudioParamMap: false,
+ AudioProcessingEvent: false,
+ AudioScheduledSourceNode: false,
+ AudioTrack: false,
+ AudioTrackList: false,
+ AudioWorklet: false,
+ AudioWorkletNode: false,
+ AuthenticatorAssertionResponse: false,
+ AuthenticatorAttestationResponse: false,
+ AuthenticatorResponse: false,
+ BarProp: false,
+ BaseAudioContext: false,
+ BatteryManager: false,
+ BeforeUnloadEvent: false,
+ BiquadFilterNode: false,
+ Blob: false,
+ BlobEvent: false,
+ BoxObject: false,
+ BroadcastChannel: false,
+ BrowsingContext: false,
+ ByteLengthQueuingStrategy: false,
+ CanonicalBrowsingContext: false,
+ CDATASection: false,
+ CSS: false,
+ CSS2Properties: false,
+ CSSAnimation: false,
+ CSSConditionRule: false,
+ CSSCounterStyleRule: false,
+ CSSFontFaceRule: false,
+ CSSFontFeatureValuesRule: false,
+ CSSGroupingRule: false,
+ CSSImportRule: false,
+ CSSKeyframeRule: false,
+ CSSKeyframesRule: false,
+ CSSMediaRule: false,
+ CSSMozDocumentRule: false,
+ CSSNamespaceRule: false,
+ CSSPageRule: false,
+ CSSPseudoElement: false,
+ CSSRule: false,
+ CSSRuleList: false,
+ CSSStyleDeclaration: false,
+ CSSStyleRule: false,
+ CSSStyleSheet: false,
+ CSSSupportsRule: false,
+ CSSTransition: false,
+ Cache: false,
+ CacheStorage: false,
+ CanvasCaptureMediaStream: false,
+ CanvasGradient: false,
+ CanvasPattern: false,
+ CanvasRenderingContext2D: false,
+ CaretPosition: false,
+ CaretStateChangedEvent: false,
+ ChannelMergerNode: false,
+ ChannelSplitterNode: false,
+ ChannelWrapper: false,
+ CharacterData: false,
+ CheckerboardReportService: false,
+ ChildProcessMessageManager: false,
+ ChildSHistory: false,
+ ChromeMessageBroadcaster: false,
+ ChromeMessageSender: false,
+ ChromeNodeList: false,
+ ChromeUtils: false,
+ ChromeWorker: false,
+ Clipboard: false,
+ ClipboardEvent: false,
+ ClonedErrorHolder: false,
+ CloseEvent: false,
+ CommandEvent: false,
+ Comment: false,
+ CompositionEvent: false,
+ ConsoleInstance: false,
+ ConstantSourceNode: false,
+ ContentFrameMessageManager: false,
+ ContentProcessMessageManager: false,
+ ConvolverNode: false,
+ CountQueuingStrategy: false,
+ CreateOfferRequest: false,
+ Credential: false,
+ CredentialsContainer: false,
+ Crypto: false,
+ CryptoKey: false,
+ CustomElementRegistry: false,
+ CustomEvent: false,
+ DOMError: false,
+ DOMException: false,
+ DOMImplementation: false,
+ DOMLocalization: false,
+ DOMMatrix: false,
+ DOMMatrixReadOnly: false,
+ DOMParser: false,
+ DOMPoint: false,
+ DOMPointReadOnly: false,
+ DOMQuad: false,
+ DOMRect: false,
+ DOMRectList: false,
+ DOMRectReadOnly: false,
+ DOMRequest: false,
+ DOMStringList: false,
+ DOMStringMap: false,
+ DOMTokenList: false,
+ DataTransfer: false,
+ DataTransferItem: false,
+ DataTransferItemList: false,
+ DebuggerNotificationObserver: false,
+ DelayNode: false,
+ DeprecationReportBody: false,
+ DeviceLightEvent: false,
+ DeviceMotionEvent: false,
+ DeviceOrientationEvent: false,
+ DeviceProximityEvent: false,
+ Directory: false,
+ Document: false,
+ DocumentFragment: false,
+ DocumentTimeline: false,
+ DocumentType: false,
+ DominatorTree: false,
+ DragEvent: false,
+ DynamicsCompressorNode: false,
+ Element: false,
+ ErrorEvent: false,
+ Event: false,
+ EventSource: false,
+ EventTarget: false,
+ FeaturePolicyViolationReportBody: false,
+ FetchObserver: false,
+ File: false,
+ FileList: false,
+ FileReader: false,
+ FileSystem: false,
+ FileSystemDirectoryEntry: false,
+ FileSystemDirectoryReader: false,
+ FileSystemEntry: false,
+ FileSystemFileEntry: false,
+ Flex: false,
+ FlexItemValues: false,
+ FlexLineValues: false,
+ FluentBundle: false,
+ FluentResource: false,
+ FocusEvent: false,
+ FontFace: false,
+ FontFaceSet: false,
+ FontFaceSetLoadEvent: false,
+ FormData: false,
+ FrameCrashedEvent: false,
+ FrameLoader: false,
+ GainNode: false,
+ Gamepad: false,
+ GamepadAxisMoveEvent: false,
+ GamepadButton: false,
+ GamepadButtonEvent: false,
+ GamepadEvent: false,
+ GamepadHapticActuator: false,
+ GamepadPose: false,
+ GamepadServiceTest: false,
+ Glean: false,
+ GleanPings: false,
+ Grid: false,
+ GridArea: false,
+ GridDimension: false,
+ GridLine: false,
+ GridLines: false,
+ GridTrack: false,
+ GridTracks: false,
+ HTMLAllCollection: false,
+ HTMLAnchorElement: false,
+ HTMLAreaElement: false,
+ HTMLAudioElement: false,
+ Audio: false,
+ HTMLBRElement: false,
+ HTMLBaseElement: false,
+ HTMLBodyElement: false,
+ HTMLButtonElement: false,
+ HTMLCanvasElement: false,
+ HTMLCollection: false,
+ HTMLDListElement: false,
+ HTMLDataElement: false,
+ HTMLDataListElement: false,
+ HTMLDetailsElement: false,
+ HTMLDialogElement: false,
+ HTMLDirectoryElement: false,
+ HTMLDivElement: false,
+ HTMLDocument: false,
+ HTMLElement: false,
+ HTMLEmbedElement: false,
+ HTMLFieldSetElement: false,
+ HTMLFontElement: false,
+ HTMLFormControlsCollection: false,
+ HTMLFormElement: false,
+ HTMLFrameElement: false,
+ HTMLFrameSetElement: false,
+ HTMLHRElement: false,
+ HTMLHeadElement: false,
+ HTMLHeadingElement: false,
+ HTMLHtmlElement: false,
+ HTMLIFrameElement: false,
+ HTMLImageElement: false,
+ Image: false,
+ HTMLInputElement: false,
+ HTMLLIElement: false,
+ HTMLLabelElement: false,
+ HTMLLegendElement: false,
+ HTMLLinkElement: false,
+ HTMLMapElement: false,
+ HTMLMarqueeElement: false,
+ HTMLMediaElement: false,
+ HTMLMenuElement: false,
+ HTMLMenuItemElement: false,
+ HTMLMetaElement: false,
+ HTMLMeterElement: false,
+ HTMLModElement: false,
+ HTMLOListElement: false,
+ HTMLObjectElement: false,
+ HTMLOptGroupElement: false,
+ HTMLOptionElement: false,
+ Option: false,
+ HTMLOptionsCollection: false,
+ HTMLOutputElement: false,
+ HTMLParagraphElement: false,
+ HTMLParamElement: false,
+ HTMLPictureElement: false,
+ HTMLPreElement: false,
+ HTMLProgressElement: false,
+ HTMLQuoteElement: false,
+ HTMLScriptElement: false,
+ HTMLSelectElement: false,
+ HTMLSlotElement: false,
+ HTMLSourceElement: false,
+ HTMLSpanElement: false,
+ HTMLStyleElement: false,
+ HTMLTableCaptionElement: false,
+ HTMLTableCellElement: false,
+ HTMLTableColElement: false,
+ HTMLTableElement: false,
+ HTMLTableRowElement: false,
+ HTMLTableSectionElement: false,
+ HTMLTemplateElement: false,
+ HTMLTextAreaElement: false,
+ HTMLTimeElement: false,
+ HTMLTitleElement: false,
+ HTMLTrackElement: false,
+ HTMLUListElement: false,
+ HTMLUnknownElement: false,
+ HTMLVideoElement: false,
+ HashChangeEvent: false,
+ Headers: false,
+ HeapSnapshot: false,
+ History: false,
+ IDBCursor: false,
+ IDBCursorWithValue: false,
+ IDBDatabase: false,
+ IDBFactory: false,
+ IDBFileHandle: false,
+ IDBFileRequest: false,
+ IDBIndex: false,
+ IDBKeyRange: false,
+ IDBLocaleAwareKeyRange: false,
+ IDBMutableFile: false,
+ IDBObjectStore: false,
+ IDBOpenDBRequest: false,
+ IDBRequest: false,
+ IDBTransaction: false,
+ IDBVersionChangeEvent: false,
+ IIRFilterNode: false,
+ IdleDeadline: false,
+ ImageBitmap: false,
+ ImageBitmapRenderingContext: false,
+ ImageCapture: false,
+ ImageCaptureErrorEvent: false,
+ ImageData: false,
+ ImageDocument: false,
+ InputEvent: false,
+ InspectorFontFace: false,
+ InspectorUtils: false,
+ InstallTriggerImpl: false,
+ IntersectionObserver: false,
+ IntersectionObserverEntry: false,
+ IOUtils: false,
+ JSProcessActorChild: false,
+ JSProcessActorParent: false,
+ JSWindowActorChild: false,
+ JSWindowActorParent: false,
+ KeyEvent: false,
+ KeyboardEvent: false,
+ KeyframeEffect: false,
+ L10nFileSource: false,
+ L10nRegistry: false,
+ Localization: false,
+ Location: false,
+ MIDIAccess: false,
+ MIDIConnectionEvent: false,
+ MIDIInput: false,
+ MIDIInputMap: false,
+ MIDIMessageEvent: false,
+ MIDIOutput: false,
+ MIDIOutputMap: false,
+ MIDIPort: false,
+ MatchGlob: false,
+ MatchPattern: false,
+ MatchPatternSet: false,
+ MediaCapabilities: false,
+ MediaCapabilitiesInfo: false,
+ MediaControlService: false,
+ MediaDeviceInfo: false,
+ MediaDevices: false,
+ MediaElementAudioSourceNode: false,
+ MediaEncryptedEvent: false,
+ MediaError: false,
+ MediaKeyError: false,
+ MediaKeyMessageEvent: false,
+ MediaKeySession: false,
+ MediaKeyStatusMap: false,
+ MediaKeySystemAccess: false,
+ MediaKeys: false,
+ MediaList: false,
+ MediaQueryList: false,
+ MediaQueryListEvent: false,
+ MediaRecorder: false,
+ MediaRecorderErrorEvent: false,
+ MediaSource: false,
+ MediaStream: false,
+ MediaStreamAudioDestinationNode: false,
+ MediaStreamAudioSourceNode: false,
+ MediaStreamEvent: false,
+ MediaStreamTrack: false,
+ MediaStreamTrackEvent: false,
+ MerchantValidationEvent: false,
+ MessageBroadcaster: false,
+ MessageChannel: false,
+ MessageEvent: false,
+ MessageListenerManager: false,
+ MessagePort: false,
+ MessageSender: false,
+ MimeType: false,
+ MimeTypeArray: false,
+ MouseEvent: false,
+ MouseScrollEvent: false,
+ MozCanvasPrintState: false,
+ MozDocumentMatcher: false,
+ MozDocumentObserver: false,
+ MozQueryInterface: false,
+ MozSharedMap: false,
+ MozSharedMapChangeEvent: false,
+ MozStorageAsyncStatementParams: false,
+ MozStorageStatementParams: false,
+ MozStorageStatementRow: false,
+ MozWritableSharedMap: false,
+ MutationEvent: false,
+ MutationObserver: false,
+ MutationRecord: false,
+ NamedNodeMap: false,
+ Navigator: false,
+ NetworkInformation: false,
+ Node: false,
+ NodeFilter: false,
+ NodeIterator: false,
+ NodeList: false,
+ Notification: false,
+ NotifyPaintEvent: false,
+ OfflineAudioCompletionEvent: false,
+ OfflineAudioContext: false,
+ OfflineResourceList: false,
+ OffscreenCanvas: false,
+ OscillatorNode: false,
+ PageTransitionEvent: false,
+ PaintRequest: false,
+ PaintRequestList: false,
+ PannerNode: false,
+ ParentProcessMessageManager: false,
+ Path2D: false,
+ PathUtils: false,
+ PaymentAddress: false,
+ PaymentMethodChangeEvent: false,
+ PaymentRequest: false,
+ PaymentRequestUpdateEvent: false,
+ PaymentResponse: false,
+ PeerConnectionImpl: false,
+ PeerConnectionObserver: false,
+ Performance: false,
+ PerformanceEntry: false,
+ PerformanceEntryEvent: false,
+ PerformanceMark: false,
+ PerformanceMeasure: false,
+ PerformanceNavigation: false,
+ PerformanceNavigationTiming: false,
+ PerformanceObserver: false,
+ PerformanceObserverEntryList: false,
+ PerformanceResourceTiming: false,
+ PerformanceServerTiming: false,
+ PerformanceTiming: false,
+ PeriodicWave: false,
+ PermissionStatus: false,
+ Permissions: false,
+ PlacesBookmark: false,
+ PlacesBookmarkAddition: false,
+ PlacesBookmarkGuid: false,
+ PlacesBookmarkMoved: false,
+ PlacesBookmarkRemoved: false,
+ PlacesBookmarkTags: false,
+ PlacesBookmarkTime: false,
+ PlacesBookmarkTitle: false,
+ PlacesBookmarkUrl: false,
+ PlacesEvent: false,
+ PlacesHistoryCleared: false,
+ PlacesObservers: false,
+ PlacesPurgeCaches: false,
+ PlacesRanking: false,
+ PlacesVisit: false,
+ PlacesVisitRemoved: false,
+ PlacesVisitTitle: false,
+ PlacesWeakCallbackWrapper: false,
+ Plugin: false,
+ PluginArray: false,
+ PluginCrashedEvent: false,
+ PointerEvent: false,
+ PopStateEvent: false,
+ PopupBlockedEvent: false,
+ PrecompiledScript: false,
+ Presentation: false,
+ PresentationAvailability: false,
+ PresentationConnection: false,
+ PresentationConnectionAvailableEvent: false,
+ PresentationConnectionCloseEvent: false,
+ PresentationConnectionList: false,
+ PresentationReceiver: false,
+ PresentationRequest: false,
+ PrioEncoder: false,
+ ProcessMessageManager: false,
+ ProcessingInstruction: false,
+ ProgressEvent: false,
+ PromiseDebugging: false,
+ PromiseRejectionEvent: false,
+ PublicKeyCredential: false,
+ PushManager: false,
+ PushManagerImpl: false,
+ PushSubscription: false,
+ PushSubscriptionOptions: false,
+ RTCCertificate: false,
+ RTCDTMFSender: false,
+ RTCDTMFToneChangeEvent: false,
+ RTCDataChannel: false,
+ RTCDataChannelEvent: false,
+ RTCIceCandidate: false,
+ RTCPeerConnection: false,
+ RTCPeerConnectionIceEvent: false,
+ RTCPeerConnectionStatic: false,
+ RTCRtpReceiver: false,
+ RTCRtpSender: false,
+ RTCRtpTransceiver: false,
+ RTCSessionDescription: false,
+ RTCStatsReport: false,
+ RTCTrackEvent: false,
+ RadioNodeList: false,
+ Range: false,
+ ReadableStreamBYOBReader: false,
+ ReadableStreamBYOBRequest: false,
+ ReadableByteStreamController: false,
+ ReadableStream: false,
+ ReadableStreamDefaultController: false,
+ ReadableStreamDefaultReader: false,
+ Report: false,
+ ReportBody: false,
+ ReportingObserver: false,
+ Request: false,
+ Response: false,
+ SessionStoreUtils: false,
+ SVGAElement: false,
+ SVGAngle: false,
+ SVGAnimateElement: false,
+ SVGAnimateMotionElement: false,
+ SVGAnimateTransformElement: false,
+ SVGAnimatedAngle: false,
+ SVGAnimatedBoolean: false,
+ SVGAnimatedEnumeration: false,
+ SVGAnimatedInteger: false,
+ SVGAnimatedLength: false,
+ SVGAnimatedLengthList: false,
+ SVGAnimatedNumber: false,
+ SVGAnimatedNumberList: false,
+ SVGAnimatedPreserveAspectRatio: false,
+ SVGAnimatedRect: false,
+ SVGAnimatedString: false,
+ SVGAnimatedTransformList: false,
+ SVGAnimationElement: false,
+ SVGCircleElement: false,
+ SVGClipPathElement: false,
+ SVGComponentTransferFunctionElement: false,
+ SVGDefsElement: false,
+ SVGDescElement: false,
+ SVGElement: false,
+ SVGEllipseElement: false,
+ SVGFEBlendElement: false,
+ SVGFEColorMatrixElement: false,
+ SVGFEComponentTransferElement: false,
+ SVGFECompositeElement: false,
+ SVGFEConvolveMatrixElement: false,
+ SVGFEDiffuseLightingElement: false,
+ SVGFEDisplacementMapElement: false,
+ SVGFEDistantLightElement: false,
+ SVGFEDropShadowElement: false,
+ SVGFEFloodElement: false,
+ SVGFEFuncAElement: false,
+ SVGFEFuncBElement: false,
+ SVGFEFuncGElement: false,
+ SVGFEFuncRElement: false,
+ SVGFEGaussianBlurElement: false,
+ SVGFEImageElement: false,
+ SVGFEMergeElement: false,
+ SVGFEMergeNodeElement: false,
+ SVGFEMorphologyElement: false,
+ SVGFEOffsetElement: false,
+ SVGFEPointLightElement: false,
+ SVGFESpecularLightingElement: false,
+ SVGFESpotLightElement: false,
+ SVGFETileElement: false,
+ SVGFETurbulenceElement: false,
+ SVGFilterElement: false,
+ SVGForeignObjectElement: false,
+ SVGGElement: false,
+ SVGGeometryElement: false,
+ SVGGradientElement: false,
+ SVGGraphicsElement: false,
+ SVGImageElement: false,
+ SVGLength: false,
+ SVGLengthList: false,
+ SVGLineElement: false,
+ SVGLinearGradientElement: false,
+ SVGMPathElement: false,
+ SVGMarkerElement: false,
+ SVGMaskElement: false,
+ SVGMatrix: false,
+ SVGMetadataElement: false,
+ SVGNumber: false,
+ SVGNumberList: false,
+ SVGPathElement: false,
+ SVGPathSegList: false,
+ SVGPatternElement: false,
+ SVGPoint: false,
+ SVGPointList: false,
+ SVGPolygonElement: false,
+ SVGPolylineElement: false,
+ SVGPreserveAspectRatio: false,
+ SVGRadialGradientElement: false,
+ SVGRect: false,
+ SVGRectElement: false,
+ SVGSVGElement: false,
+ SVGScriptElement: false,
+ SVGSetElement: false,
+ SVGStopElement: false,
+ SVGStringList: false,
+ SVGStyleElement: false,
+ SVGSwitchElement: false,
+ SVGSymbolElement: false,
+ SVGTSpanElement: false,
+ SVGTextContentElement: false,
+ SVGTextElement: false,
+ SVGTextPathElement: false,
+ SVGTextPositioningElement: false,
+ SVGTitleElement: false,
+ SVGTransform: false,
+ SVGTransformList: false,
+ SVGUnitTypes: false,
+ SVGUseElement: false,
+ SVGViewElement: false,
+ SVGZoomAndPan: false,
+ Screen: false,
+ ScreenLuminance: false,
+ ScreenOrientation: false,
+ ScriptProcessorNode: false,
+ ScrollAreaEvent: false,
+ ScrollViewChangeEvent: false,
+ SecurityPolicyViolationEvent: false,
+ Selection: false,
+ ServiceWorker: false,
+ ServiceWorkerContainer: false,
+ ServiceWorkerRegistration: false,
+ ShadowRoot: false,
+ SharedWorker: false,
+ SimpleGestureEvent: false,
+ SourceBuffer: false,
+ SourceBufferList: false,
+ SpeechGrammar: false,
+ SpeechGrammarList: false,
+ SpeechRecognition: false,
+ SpeechRecognitionAlternative: false,
+ SpeechRecognitionError: false,
+ SpeechRecognitionEvent: false,
+ SpeechRecognitionResult: false,
+ SpeechRecognitionResultList: false,
+ SpeechSynthesis: false,
+ SpeechSynthesisErrorEvent: false,
+ SpeechSynthesisEvent: false,
+ SpeechSynthesisUtterance: false,
+ SpeechSynthesisVoice: false,
+ StereoPannerNode: false,
+ Storage: false,
+ StorageEvent: false,
+ StorageManager: false,
+ StreamFilter: false,
+ StreamFilterDataEvent: false,
+ StructuredCloneHolder: false,
+ StructuredCloneTester: false,
+ StyleSheet: false,
+ StyleSheetApplicableStateChangeEvent: false,
+ StyleSheetList: false,
+ SubtleCrypto: false,
+ SyncMessageSender: false,
+ TCPServerSocket: false,
+ TCPServerSocketEvent: false,
+ TCPSocket: false,
+ TCPSocketErrorEvent: false,
+ TCPSocketEvent: false,
+ TelemetryStopwatch: false,
+ TestingDeprecatedInterface: false,
+ Text: false,
+ TextClause: false,
+ TextDecoder: false,
+ TextEncoder: false,
+ TextMetrics: false,
+ TextTrack: false,
+ TextTrackCue: false,
+ TextTrackCueList: false,
+ TextTrackList: false,
+ TimeEvent: false,
+ TimeRanges: false,
+ Touch: false,
+ TouchEvent: false,
+ TouchList: false,
+ TrackEvent: false,
+ TransceiverImpl: false,
+ TransformStream: false,
+ TransformStreamDefaultController: false,
+ TransitionEvent: false,
+ TreeColumn: false,
+ TreeColumns: false,
+ TreeContentView: false,
+ TreeWalker: false,
+ U2F: false,
+ UDPMessageEvent: false,
+ UDPSocket: false,
+ UIEvent: false,
+ URL: false,
+ URLSearchParams: false,
+ UserInteraction: false,
+ UserProximityEvent: false,
+ VRDisplay: false,
+ VRDisplayCapabilities: false,
+ VRDisplayEvent: false,
+ VREyeParameters: false,
+ VRFieldOfView: false,
+ VRFrameData: false,
+ VRMockController: false,
+ VRMockDisplay: false,
+ VRPose: false,
+ VRServiceTest: false,
+ VRStageParameters: false,
+ VRSubmitFrameResult: false,
+ VTTCue: false,
+ VTTRegion: false,
+ ValidityState: false,
+ VideoPlaybackQuality: false,
+ VideoTrack: false,
+ VideoTrackList: false,
+ VisualViewport: false,
+ WaveShaperNode: false,
+ WebExtensionContentScript: false,
+ WebExtensionPolicy: false,
+ WebGL2RenderingContext: false,
+ WebGLActiveInfo: false,
+ WebGLBuffer: false,
+ WebGLContextEvent: false,
+ WebGLFramebuffer: false,
+ WebGLProgram: false,
+ WebGLQuery: false,
+ WebGLRenderbuffer: false,
+ WebGLRenderingContext: false,
+ WebGLSampler: false,
+ WebGLShader: false,
+ WebGLShaderPrecisionFormat: false,
+ WebGLSync: false,
+ WebGLTexture: false,
+ WebGLTransformFeedback: false,
+ WebGLUniformLocation: false,
+ WebGLVertexArrayObject: false,
+ WebGPU: false,
+ WebGPUAdapter: false,
+ WebGPUAttachmentState: false,
+ WebGPUBindGroup: false,
+ WebGPUBindGroupLayout: false,
+ WebGPUBindingType: false,
+ WebGPUBlendFactor: false,
+ WebGPUBlendOperation: false,
+ WebGPUBlendState: false,
+ WebGPUBuffer: false,
+ WebGPUBufferUsage: false,
+ WebGPUColorWriteBits: false,
+ WebGPUCommandBuffer: false,
+ WebGPUCommandEncoder: false,
+ WebGPUCompareFunction: false,
+ WebGPUComputePipeline: false,
+ WebGPUDepthStencilState: false,
+ WebGPUDevice: false,
+ WebGPUFence: false,
+ WebGPUFilterMode: false,
+ WebGPUIndexFormat: false,
+ WebGPUInputState: false,
+ WebGPUInputStepMode: false,
+ WebGPULoadOp: false,
+ WebGPULogEntry: false,
+ WebGPUPipelineLayout: false,
+ WebGPUPrimitiveTopology: false,
+ WebGPUQueue: false,
+ WebGPURenderPipeline: false,
+ WebGPUSampler: false,
+ WebGPUShaderModule: false,
+ WebGPUShaderStage: false,
+ WebGPUShaderStageBit: false,
+ WebGPUStencilOperation: false,
+ WebGPUStoreOp: false,
+ WebGPUSwapChain: false,
+ WebGPUTexture: false,
+ WebGPUTextureDimension: false,
+ WebGPUTextureFormat: false,
+ WebGPUTextureUsage: false,
+ WebGPUTextureView: false,
+ WebGPUVertexFormat: false,
+ WebKitCSSMatrix: false,
+ WebSocket: false,
+ WebrtcGlobalInformation: false,
+ WheelEvent: false,
+ Window: false,
+ WindowGlobalChild: false,
+ WindowGlobalParent: false,
+ WindowRoot: false,
+ Worker: false,
+ Worklet: false,
+ WritableStream: false,
+ WritableStreamDefaultController: false,
+ WritableStreamDefaultWriter: false,
+ XMLDocument: false,
+ XMLHttpRequest: false,
+ XMLHttpRequestEventTarget: false,
+ XMLHttpRequestUpload: false,
+ XMLSerializer: false,
+ XPathEvaluator: false,
+ XPathExpression: false,
+ XPathResult: false,
+ XSLTProcessor: false,
+ XULCommandEvent: false,
+ XULElement: false,
+ XULFrameElement: false,
+ XULMenuElement: false,
+ XULPopupElement: false,
+ XULScrollElement: false,
+ XULTextElement: false,
+ console: false,
+ mozRTCIceCandidate: false,
+ mozRTCPeerConnection: false,
+ mozRTCSessionDescription: false,
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/process-script.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/process-script.js
new file mode 100644
index 0000000000..f329a6650b
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/process-script.js
@@ -0,0 +1,38 @@
+/**
+ * @fileoverview Defines the environment for process scripts.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ // dom/chrome-webidl/MessageManager.webidl
+
+ // MessageManagerGlobal
+ dump: false,
+ atob: false,
+ btoa: false,
+
+ // MessageListenerManagerMixin
+ addMessageListener: false,
+ removeMessageListener: false,
+ addWeakMessageListener: false,
+ removeWeakMessageListener: false,
+
+ // MessageSenderMixin
+ sendAsyncMessage: false,
+ processMessageManager: false,
+ remoteType: false,
+
+ // SyncMessageSenderMixin
+ sendSyncMessage: false,
+
+ // ContentProcessMessageManager
+ initialProcessData: false,
+ sharedData: false,
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/remote-page.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/remote-page.js
new file mode 100644
index 0000000000..0adebe90bc
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/remote-page.js
@@ -0,0 +1,40 @@
+/**
+ * @fileoverview Defines the environment for remote page.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ atob: false,
+ btoa: false,
+ RPMAddTRRExcludedDomain: false,
+ RPMGetAppBuildID: false,
+ RPMGetInnerMostURI: false,
+ RPMGetIntPref: false,
+ RPMGetStringPref: false,
+ RPMGetBoolPref: false,
+ RPMSetBoolPref: false,
+ RPMGetFormatURLPref: false,
+ RPMIsTRROnlyFailure: false,
+ RPMShowTRROnlyFailureError: false,
+ RPMIsWindowPrivate: false,
+ RPMSendAsyncMessage: false,
+ RPMSendQuery: false,
+ RPMAddMessageListener: false,
+ RPMRecordTelemetryEvent: false,
+ RPMCheckAlternateHostAvailable: false,
+ RPMAddToHistogram: false,
+ RPMRemoveMessageListener: false,
+ RPMGetHttpResponseHeader: false,
+ RPMTryPingSecureWWWLink: false,
+ RPMOpenSecureWWWLink: false,
+ RPMOpenPreferences: false,
+ RPMGetTRRSkipReason: false,
+ RPMGetTRRDomain: false,
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/simpletest.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/simpletest.js
new file mode 100644
index 0000000000..2f5dd5c33e
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/simpletest.js
@@ -0,0 +1,35 @@
+/**
+ * @fileoverview Defines the environment for scripts that use the SimpleTest
+ * mochitest harness. Imports the globals from the relevant files.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+// -----------------------------------------------------------------------------
+// Rule Definition
+// -----------------------------------------------------------------------------
+
+var path = require("path");
+var { getScriptGlobals } = require("./utils");
+
+// When updating this list, be sure to also update the 'support-files' config
+// in `tools/lint/eslint.yml`.
+const simpleTestFiles = [
+ "AccessibilityUtils.js",
+ "ExtensionTestUtils.js",
+ "EventUtils.js",
+ "MockObjects.js",
+ "SimpleTest.js",
+ "WindowSnapshot.js",
+ "paint_listener.js",
+];
+const simpleTestPath = "testing/mochitest/tests/SimpleTest";
+
+module.exports = getScriptGlobals(
+ "simpletest",
+ simpleTestFiles.map(file => path.join(simpleTestPath, file))
+);
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/sjs.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/sjs.js
new file mode 100644
index 0000000000..995c3173d2
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/sjs.js
@@ -0,0 +1,30 @@
+/**
+ * @fileoverview Defines the environment for sjs files.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ // All these variables are hard-coded to be available for sjs scopes only.
+ // https://searchfox.org/mozilla-central/rev/26a1b0fce12e6dd495a954c542bb1e7bd6e0d548/netwerk/test/httpserver/httpd.js#2879
+ atob: false,
+ btoa: false,
+ ChromeUtils: false,
+ dump: false,
+ getState: false,
+ setState: false,
+ getSharedState: false,
+ setSharedState: false,
+ getObjectState: false,
+ setObjectState: false,
+ registerPathHandler: false,
+ Services: false,
+ // importScripts is also available.
+ importScripts: false,
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/special-powers-sandbox.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/special-powers-sandbox.js
new file mode 100644
index 0000000000..5a28c91883
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/special-powers-sandbox.js
@@ -0,0 +1,46 @@
+/**
+ * @fileoverview Defines the environment for SpecialPowers sandbox.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ // wantComponents defaults to true,
+ Components: false,
+ Ci: false,
+ Cr: false,
+ Cc: false,
+ Cu: false,
+ Services: false,
+
+ // testing/specialpowers/content/SpecialPowersSandbox.sys.mjs
+
+ // SANDBOX_GLOBALS
+ Blob: false,
+ ChromeUtils: false,
+ FileReader: false,
+ TextDecoder: false,
+ TextEncoder: false,
+ URL: false,
+
+ // EXTRA_IMPORTS
+ EventUtils: false,
+
+ // SpecialPowersSandbox constructor
+ assert: false,
+ Assert: false,
+ BrowsingContext: false,
+ InspectorUtils: false,
+ ok: false,
+ is: false,
+ isnot: false,
+ todo: false,
+ todo_is: false,
+ info: false,
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/specific.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/specific.js
new file mode 100644
index 0000000000..23ebcb5bb1
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/specific.js
@@ -0,0 +1,31 @@
+/**
+ * @fileoverview Defines the environment for the Firefox browser. Allows global
+ * variables which are non-standard and specific to Firefox.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ Cc: false,
+ ChromeUtils: false,
+ Ci: false,
+ Components: false,
+ Cr: false,
+ Cu: false,
+ Debugger: false,
+ InstallTrigger: false,
+ // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/InternalError
+ InternalError: true,
+ Services: false,
+ // https://developer.mozilla.org/docs/Web/API/Window/dump
+ dump: true,
+ openDialog: false,
+ // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/uneval
+ uneval: false,
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/utils.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/utils.js
new file mode 100644
index 0000000000..aeda690ba5
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/utils.js
@@ -0,0 +1,62 @@
+/**
+ * @fileoverview Provides utilities for setting up environments.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+var path = require("path");
+var helpers = require("../helpers");
+var globals = require("../globals");
+
+/**
+ * Obtains the globals for a list of files.
+ *
+ * @param {Array.<String>} files
+ * The array of files to get globals for. The paths are relative to the topsrcdir.
+ * @returns {Object}
+ * Returns an object with keys of the global names and values of if they are
+ * writable or not.
+ */
+function getGlobalsForScripts(environmentName, files, extraDefinitions) {
+ let fileGlobals = extraDefinitions;
+ const root = helpers.rootDir;
+ for (const file of files) {
+ const fileName = path.join(root, file);
+ try {
+ fileGlobals = fileGlobals.concat(globals.getGlobalsForFile(fileName));
+ } catch (e) {
+ console.error(`Could not load globals from file ${fileName}: ${e}`);
+ console.error(
+ `You may need to update the mappings for the ${environmentName} environment`
+ );
+ throw new Error(`Could not load globals from file ${fileName}: ${e}`);
+ }
+ }
+
+ var globalObjects = {};
+ for (let global of fileGlobals) {
+ globalObjects[global.name] = global.writable;
+ }
+ return globalObjects;
+}
+
+module.exports = {
+ getScriptGlobals(
+ environmentName,
+ files,
+ extraDefinitions = [],
+ extraEnv = {}
+ ) {
+ if (helpers.isMozillaCentralBased()) {
+ return {
+ globals: getGlobalsForScripts(environmentName, files, extraDefinitions),
+ ...extraEnv,
+ };
+ }
+ return helpers.getSavedEnvironmentItems(environmentName);
+ },
+};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/xpcshell.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/xpcshell.js
new file mode 100644
index 0000000000..408bc2e277
--- /dev/null
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/xpcshell.js
@@ -0,0 +1,59 @@
+/**
+ * @fileoverview Defines the environment for xpcshell test files.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
+
+var { getScriptGlobals } = require("./utils");
+
+const extraGlobals = [
+ // Defined in XPCShellImpl.cpp
+ "print",
+ "readline",
+ "load",
+ "quit",
+ "dumpXPC",
+ "dump",
+ "gc",
+ "gczeal",
+ "options",
+ "sendCommand",
+ "atob",
+ "btoa",
+ "setInterruptCallback",
+ "simulateNoScriptActivity",
+ "registerXPCTestComponents",
+
+ // Assert.sys.mjs globals.
+ "setReporter",
+ "report",
+ "ok",
+ "equal",
+ "notEqual",
+ "deepEqual",
+ "notDeepEqual",
+ "strictEqual",
+ "notStrictEqual",
+ "throws",
+ "rejects",
+ "greater",
+ "greaterOrEqual",
+ "less",
+ "lessOrEqual",
+ // TestingFunctions.cpp globals
+ "allocationMarker",
+ "byteSize",
+ "saveStack",
+];
+
+module.exports = getScriptGlobals(
+ "xpcshell",
+ ["testing/xpcshell/head.js"],
+ extraGlobals.map(g => {
+ return { name: g, writable: false };
+ })
+);