Bug 1792341 - Migrate most of the rest of toolkit/modules/ to be system ES modules. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D158451
This commit is contained in:
Mark Banner 2022-10-18 11:21:25 +00:00
parent 7efc67a52a
commit 69a9e3e717
22 changed files with 75 additions and 121 deletions

View file

@ -221,7 +221,7 @@ toolkit/components/translation/cld2/
# Uses preprocessing # Uses preprocessing
toolkit/mozapps/update/tests/data/xpcshellConstantsPP.js toolkit/mozapps/update/tests/data/xpcshellConstantsPP.js
toolkit/modules/AppConstants.jsm toolkit/modules/AppConstants.sys.mjs
# Tests of ESLint command. # Tests of ESLint command.
tools/lint/test/files tools/lint/test/files

View file

@ -30,8 +30,8 @@ const startupPhases = {
modules: new Set([ modules: new Set([
"resource:///modules/BrowserGlue.jsm", "resource:///modules/BrowserGlue.jsm",
"resource:///modules/StartupRecorder.jsm", "resource:///modules/StartupRecorder.jsm",
"resource://gre/modules/AppConstants.jsm", "resource://gre/modules/AppConstants.sys.mjs",
"resource://gre/modules/ActorManagerParent.jsm", "resource://gre/modules/ActorManagerParent.sys.mjs",
"resource://gre/modules/CustomElementsListener.jsm", "resource://gre/modules/CustomElementsListener.jsm",
"resource://gre/modules/MainProcessSingleton.jsm", "resource://gre/modules/MainProcessSingleton.jsm",
"resource://gre/modules/XPCOMUtils.sys.mjs", "resource://gre/modules/XPCOMUtils.sys.mjs",
@ -63,7 +63,7 @@ const startupPhases = {
"resource://gre/modules/NewTabUtils.sys.mjs", "resource://gre/modules/NewTabUtils.sys.mjs",
"resource://gre/modules/PageThumbs.jsm", "resource://gre/modules/PageThumbs.jsm",
"resource://gre/modules/PlacesUtils.sys.mjs", "resource://gre/modules/PlacesUtils.sys.mjs",
"resource://gre/modules/Preferences.jsm", "resource://gre/modules/Preferences.sys.mjs",
"resource://gre/modules/SearchService.sys.mjs", "resource://gre/modules/SearchService.sys.mjs",
"resource://gre/modules/Sqlite.sys.mjs", "resource://gre/modules/Sqlite.sys.mjs",
]), ]),

View file

@ -23,9 +23,9 @@ const known_scripts = {
"chrome://mochikit/content/ShutdownLeaksCollector.jsm", "chrome://mochikit/content/ShutdownLeaksCollector.jsm",
// General utilities // General utilities
"resource://gre/modules/AppConstants.jsm", "resource://gre/modules/AppConstants.sys.mjs",
"resource://gre/modules/DeferredTask.jsm", "resource://gre/modules/DeferredTask.sys.mjs",
"resource://gre/modules/Timer.jsm", "resource://gre/modules/Timer.sys.mjs",
"resource://gre/modules/XPCOMUtils.sys.mjs", "resource://gre/modules/XPCOMUtils.sys.mjs",
// Logging related // Logging related

View file

@ -37,8 +37,8 @@ const known_scripts = {
actorModuleURI, actorModuleURI,
// General utilities // General utilities
"resource://gre/modules/AppConstants.jsm", "resource://gre/modules/AppConstants.sys.mjs",
"resource://gre/modules/DeferredTask.jsm", "resource://gre/modules/DeferredTask.sys.mjs",
"resource://gre/modules/XPCOMUtils.sys.mjs", "resource://gre/modules/XPCOMUtils.sys.mjs",
// Logging related // Logging related

View file

@ -74,7 +74,7 @@ prefs.observe("foo", aCallback);
prefs.ignore("foo", aCallback); prefs.ignore("foo", aCallback);
``` ```
See [toolkit/modules/Preferences.jsm](https://searchfox.mozilla.org/mozilla-central/source/toolkit/modules/Preferences.jsm) See :searchfox:`toolkit/modules/Preferences.sys.mjs <source/toolkit/modules/Preferences.sys.mjs>`
for more information about what methods are available. for more information about what methods are available.
## Discovery Stream Preferences ## Discovery Stream Preferences

View file

@ -22,7 +22,7 @@ declare namespace MockedExports {
*/ */
interface KnownModules { interface KnownModules {
Services: typeof import("Services"); Services: typeof import("Services");
"resource://gre/modules/AppConstants.jsm": typeof import("resource://gre/modules/AppConstants.jsm"); "resource://gre/modules/AppConstants.sys.mjs": typeof import("resource://gre/modules/AppConstants.sys.mjs");
"resource:///modules/CustomizableUI.jsm": typeof import("resource:///modules/CustomizableUI.jsm"); "resource:///modules/CustomizableUI.jsm": typeof import("resource:///modules/CustomizableUI.jsm");
"resource:///modules/CustomizableWidgets.jsm": typeof import("resource:///modules/CustomizableWidgets.jsm"); "resource:///modules/CustomizableWidgets.jsm": typeof import("resource:///modules/CustomizableWidgets.jsm");
"resource://devtools/shared/loader/Loader.sys.mjs": typeof import("resource://devtools/shared/loader/Loader.sys.mjs"); "resource://devtools/shared/loader/Loader.sys.mjs": typeof import("resource://devtools/shared/loader/Loader.sys.mjs");
@ -200,7 +200,7 @@ declare namespace MockedExports {
decorate: (target: object) => void; decorate: (target: object) => void;
}; };
const AppConstantsJSM: { const AppConstantsSYSMJS: {
AppConstants: { AppConstants: {
platform: string; platform: string;
}; };
@ -334,8 +334,8 @@ declare module "ChromeUtils" {
export = ChromeUtils; export = ChromeUtils;
} }
declare module "resource://gre/modules/AppConstants.jsm" { declare module "resource://gre/modules/AppConstants.sys.mjs" {
export = MockedExports.AppConstantsJSM; export = MockedExports.AppConstantsSYSMJS;
} }
declare module "resource://gre/modules/WebChannel.jsm" { declare module "resource://gre/modules/WebChannel.jsm" {

View file

@ -271,7 +271,7 @@ Message Manager Actors
While the JSWindowActor mechanism was being designed and developed, large sections of our framescripts were converted to an "actor style" pattern to make eventual porting to JSWindowActors easier. These Actors use the Message Manager under the hood, but made it much easier to shrink our framescripts, and also allowed us to gain significant memory savings by having the actors be lazily instantiated. While the JSWindowActor mechanism was being designed and developed, large sections of our framescripts were converted to an "actor style" pattern to make eventual porting to JSWindowActors easier. These Actors use the Message Manager under the hood, but made it much easier to shrink our framescripts, and also allowed us to gain significant memory savings by having the actors be lazily instantiated.
You can find the list of Message Manager Actors (or "Legacy Actors") in `BrowserGlue.jsm <https://searchfox.org/mozilla-central/source/browser/components/BrowserGlue.jsm>`_ and `ActorManagerParent.jsm <https://searchfox.org/mozilla-central/source/toolkit/modules/ActorManagerParent.jsm>`_, in the ``LEGACY_ACTORS`` lists. You can find the list of Message Manager Actors (or "Legacy Actors") in :searchfox:`BrowserGlue.jsm <browser/components/BrowserGlue.jsm>` and :searchfox:`ActorManagerParent.sys.mjs <toolkit/modules/ActorManagerParent.sys.mjs>`, in the ``LEGACY_ACTORS`` lists.
.. note:: .. note::
The split in Message Manager Actors defined between ``BrowserGlue`` and ``ActorManagerParent`` is mainly to keep Firefox Desktop specific Actors separate from Actors that can (in theory) be instantiated for non-Desktop browsers (like Fennec and GeckoView-based browsers). Firefox Desktop-specific Actors should be registered in ``BrowserGlue``. Shared "toolkit" Actors should go into ``ActorManagerParent``. The split in Message Manager Actors defined between ``BrowserGlue`` and ``ActorManagerParent`` is mainly to keep Firefox Desktop specific Actors separate from Actors that can (in theory) be instantiated for non-Desktop browsers (like Fennec and GeckoView-based browsers). Firefox Desktop-specific Actors should be registered in ``BrowserGlue``. Shared "toolkit" Actors should go into ``ActorManagerParent``.

View file

@ -185,7 +185,7 @@ def get_embedded_version(version, buildid):
return version return version
def get_appconstants_jsm_values(finder, *args): def get_appconstants_sys_mjs_values(finder, *args):
r"""Extract values, such as the display version like `MOZ_APP_VERSION_DISPLAY: r"""Extract values, such as the display version like `MOZ_APP_VERSION_DISPLAY:
"...";`, from the omnijar. This allows to determine the beta number, like "...";`, from the omnijar. This allows to determine the beta number, like
`X.YbW`, where the regular beta version is only `X.Y`. Takes a list of `X.YbW`, where the regular beta version is only `X.Y`. Takes a list of
@ -194,7 +194,7 @@ def get_appconstants_jsm_values(finder, *args):
""" """
lines = defaultdict(list) lines = defaultdict(list)
for _, f in finder.find("**/modules/AppConstants.jsm"): for _, f in finder.find("**/modules/AppConstants.sys.mjs"):
for line in f.open().read().decode("utf-8").splitlines(): for line in f.open().read().decode("utf-8").splitlines():
for arg in args: for arg in args:
if arg in line: if arg in line:
@ -365,12 +365,12 @@ def repackage_msix(
second = next(values) second = next(values)
vendor = vendor or second vendor = vendor or second
# For `AppConstants.jsm` and `brand.properties`, which are in the omnijar in packaged builds. # For `AppConstants.sys.mjs` and `brand.properties`, which are in the omnijar in packaged
# The nested langpack XPI files can't be read by `mozjar.py`. # builds. The nested langpack XPI files can't be read by `mozjar.py`.
unpack_finder = UnpackFinder(finder, unpack_xpi=False) unpack_finder = UnpackFinder(finder, unpack_xpi=False)
if not version: if not version:
values = get_appconstants_jsm_values( values = get_appconstants_sys_mjs_values(
unpack_finder, "MOZ_APP_VERSION_DISPLAY", "MOZ_BUILDID" unpack_finder, "MOZ_APP_VERSION_DISPLAY", "MOZ_BUILDID"
) )
display_version = next(values) display_version = next(values)
@ -384,8 +384,8 @@ def repackage_msix(
"display_version": display_version, "display_version": display_version,
"buildid": buildid, "buildid": buildid,
}, },
"AppConstants.jsm display version is '{display_version}' and build ID is '{buildid}':" "AppConstants.sys.mjs display version is '{display_version}' and build ID is"
+ " embedded version will be '{version}'", + " '{buildid}': embedded version will be '{version}'",
) )
# TODO: Bug 1721922: localize this description via Fluent. # TODO: Bug 1721922: localize this description via Fluent.

View file

@ -32,7 +32,7 @@ const backgroundtaskPhases = {
"resource://gre/modules/AppConstants.jsm", "resource://gre/modules/AppConstants.jsm",
"resource://gre/modules/AsyncShutdown.jsm", "resource://gre/modules/AsyncShutdown.jsm",
"resource://gre/modules/BackgroundTasksManager.sys.mjs", "resource://gre/modules/BackgroundTasksManager.sys.mjs",
"resource://gre/modules/Console.jsm", "resource://gre/modules/Console.sys.mjs",
"resource://gre/modules/EnterprisePolicies.sys.mjs", "resource://gre/modules/EnterprisePolicies.sys.mjs",
"resource://gre/modules/EnterprisePoliciesParent.sys.mjs", "resource://gre/modules/EnterprisePoliciesParent.sys.mjs",
"resource://gre/modules/PromiseUtils.sys.mjs", "resource://gre/modules/PromiseUtils.sys.mjs",
@ -123,7 +123,7 @@ const backgroundtaskPhases = {
"resource:///modules/backgroundtasks/BackgroundTask_wait.sys.mjs", "resource:///modules/backgroundtasks/BackgroundTask_wait.sys.mjs",
"resource://gre/modules/ConsoleAPIStorage.jsm", "resource://gre/modules/ConsoleAPIStorage.jsm",
"resource://gre/modules/Timer.jsm", "resource://gre/modules/Timer.sys.mjs",
// We have a profile marker for this, even though it failed to load! // We have a profile marker for this, even though it failed to load!
"resource://gre/modules/backgroundtasks/BackgroundTask_wait.sys.mjs", "resource://gre/modules/backgroundtasks/BackgroundTask_wait.sys.mjs",

View file

@ -2,21 +2,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public /* 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, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/** /**
* This module handles JavaScript-implemented JSWindowActors, registered through DOM IPC * This module handles JavaScript-implemented JSWindowActors, registered through DOM IPC
* infrastructure, and are fission-compatible. * infrastructure, and are fission-compatible.
*/ */
var EXPORTED_SYMBOLS = ["ActorManagerParent"]; import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
/** /**
* Fission-compatible JSProcess implementations. * Fission-compatible JSProcess implementations.
@ -569,7 +562,7 @@ if (AppConstants.platform != "android") {
}; };
} }
var ActorManagerParent = { export var ActorManagerParent = {
_addActors(actors, kind) { _addActors(actors, kind) {
let register, unregister; let register, unregister;
switch (kind) { switch (kind) {

View file

@ -5,15 +5,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const lazy = {}; const lazy = {};
ChromeUtils.defineModuleGetter(lazy, "AddonManager", "resource://gre/modules/AddonManager.jsm"); ChromeUtils.defineModuleGetter(lazy, "AddonManager", "resource://gre/modules/AddonManager.jsm");
var EXPORTED_SYMBOLS = ["AppConstants"];
// Immutable for export. // Immutable for export.
var AppConstants = Object.freeze({ export var AppConstants = Object.freeze({
// See this wiki page for more details about channel specific build // See this wiki page for more details about channel specific build
// defines: https://wiki.mozilla.org/Platform/Channel-specific_build_defines // defines: https://wiki.mozilla.org/Platform/Channel-specific_build_defines
NIGHTLY_BUILD: NIGHTLY_BUILD:

View file

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/** /**
* Define a 'console' API to roughly match the implementation provided by * Define a 'console' API to roughly match the implementation provided by
* Firebug. * Firebug.
@ -20,8 +18,6 @@
* implementation isn't always required (or even well defined) * implementation isn't always required (or even well defined)
*/ */
var EXPORTED_SYMBOLS = ["console", "ConsoleAPI"];
var gTimerRegistry = new Map(); var gTimerRegistry = new Map();
/** /**
@ -610,7 +606,7 @@ function sendConsoleAPIMessage(aConsole, aLevel, aFrame, aArgs, aOptions = {}) {
* @return {object} * @return {object}
* A console API instance object * A console API instance object
*/ */
function ConsoleAPI(aConsoleOptions = {}) { export function ConsoleAPI(aConsoleOptions = {}) {
// Normalize console options to set default values // Normalize console options to set default values
// in order to avoid runtime checks on each console method call. // in order to avoid runtime checks on each console method call.
this.dump = aConsoleOptions.dump || dump; this.dump = aConsoleOptions.dump || dump;
@ -756,4 +752,4 @@ ConsoleAPI.prototype = {
}, },
}; };
var console = new ConsoleAPI(); export var console = new ConsoleAPI();

View file

@ -14,11 +14,7 @@
* between processes during runtime. * between processes during runtime.
*/ */
var EXPORTED_SYMBOLS = ["ContentDOMReference"]; import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const lazy = {}; const lazy = {};
@ -55,7 +51,7 @@ const finalizerRoots = new WeakMap();
*/ */
var gRegistry = new WeakMap(); var gRegistry = new WeakMap();
var ContentDOMReference = { export var ContentDOMReference = {
_init() { _init() {
Services.obs.addObserver(this, FINALIZATION_TOPIC); Services.obs.addObserver(this, FINALIZATION_TOPIC);
}, },

View file

@ -4,10 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["DeferredTask"];
const lazy = {}; const lazy = {};
/** /**
@ -114,7 +110,7 @@ const Timer = Components.Constructor(
* aDelayMs have elapsed. If omitted, waits indefinitely for an idle * aDelayMs have elapsed. If omitted, waits indefinitely for an idle
* callback. * callback.
*/ */
var DeferredTask = function(aTaskFn, aDelayMs, aIdleTimeoutMs) { export var DeferredTask = function(aTaskFn, aDelayMs, aIdleTimeoutMs) {
this._taskFn = aTaskFn; this._taskFn = aTaskFn;
this._delayMs = aDelayMs; this._delayMs = aDelayMs;
this._timeoutMs = aIdleTimeoutMs; this._timeoutMs = aIdleTimeoutMs;

View file

@ -2,10 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["Deprecated"];
const PREF_DEPRECATION_WARNINGS = "devtools.errorconsole.deprecation_warnings"; const PREF_DEPRECATION_WARNINGS = "devtools.errorconsole.deprecation_warnings";
// A flag that indicates whether deprecation warnings should be logged. // A flag that indicates whether deprecation warnings should be logged.
@ -43,7 +39,7 @@ function stringifyCallstack(aStack) {
return msg; return msg;
} }
var Deprecated = { export var Deprecated = {
/** /**
* Log a deprecation warning. * Log a deprecation warning.
* *

View file

@ -2,13 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict"; import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
var EXPORTED_SYMBOLS = ["E10SUtils"];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const lazy = {}; const lazy = {};
@ -269,7 +263,7 @@ const SYSTEM_WORKERS_REMOTE_TYPES_ALLOWED = [
PRIVILEGEDABOUT_REMOTE_TYPE, PRIVILEGEDABOUT_REMOTE_TYPE,
]; ];
var E10SUtils = { export var E10SUtils = {
DEFAULT_REMOTE_TYPE, DEFAULT_REMOTE_TYPE,
NOT_REMOTE, NOT_REMOTE,
WEB_REMOTE_TYPE, WEB_REMOTE_TYPE,

View file

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const lazy = {}; const lazy = {};
ChromeUtils.defineModuleGetter( ChromeUtils.defineModuleGetter(
@ -12,9 +10,7 @@ ChromeUtils.defineModuleGetter(
"resource://gre/modules/Console.jsm" "resource://gre/modules/Console.jsm"
); );
var EXPORTED_SYMBOLS = ["EventEmitter"]; export function EventEmitter() {}
function EventEmitter() {}
let loggingEnabled = Services.prefs.getBoolPref("toolkit.dump.emit"); let loggingEnabled = Services.prefs.getBoolPref("toolkit.dump.emit");
Services.prefs.addObserver("toolkit.dump.emit", { Services.prefs.addObserver("toolkit.dump.emit", {

View file

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["Preferences"];
// The minimum and maximum integers that can be set as preferences. // The minimum and maximum integers that can be set as preferences.
// The range of valid values is narrower than the range of valid JS values // The range of valid values is narrower than the range of valid JS values
// because the native preferences code treats integers as NSPR PRInt32s, // because the native preferences code treats integers as NSPR PRInt32s,
@ -11,7 +9,7 @@ var EXPORTED_SYMBOLS = ["Preferences"];
const MAX_INT = 0x7fffffff; // Math.pow(2, 31) - 1 const MAX_INT = 0x7fffffff; // Math.pow(2, 31) - 1
const MIN_INT = -0x80000000; const MIN_INT = -0x80000000;
function Preferences(args) { export function Preferences(args) {
this._cachedPrefBranch = null; this._cachedPrefBranch = null;
if (isObject(args)) { if (isObject(args)) {
if (args.branch) { if (args.branch) {

View file

@ -2,15 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
const kAutoStartPref = "browser.privatebrowsing.autostart"; const kAutoStartPref = "browser.privatebrowsing.autostart";
// This will be set to true when the PB mode is autostarted from the command // This will be set to true when the PB mode is autostarted from the command
// line for the current session. // line for the current session.
var gTemporaryAutoStartMode = false; var gTemporaryAutoStartMode = false;
var PrivateBrowsingUtils = { export var PrivateBrowsingUtils = {
get enabled() { get enabled() {
return Services.policies.isAllowed("privatebrowsing"); return Services.policies.isAllowed("privatebrowsing");
}, },

View file

@ -2,23 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/** /**
* JS module implementation of setTimeout and clearTimeout. * JS module implementation of setTimeout and clearTimeout.
*/ */
var EXPORTED_SYMBOLS = [
"setTimeout",
"setTimeoutWithTarget",
"clearTimeout",
"setInterval",
"setIntervalWithTarget",
"clearInterval",
"requestIdleCallback",
"cancelIdleCallback",
];
// This gives us >=2^30 unique timer IDs, enough for 1 per ms for 12.4 days. // This gives us >=2^30 unique timer IDs, enough for 1 per ms for 12.4 days.
var gNextId = 1; // setTimeout and setInterval must return a positive integer var gNextId = 1; // setTimeout and setInterval must return a positive integer
@ -78,11 +65,16 @@ function _setTimeoutOrIsInterval(
return id; return id;
} }
function setTimeout(aCallback, aMilliseconds, ...aArgs) { export function setTimeout(aCallback, aMilliseconds, ...aArgs) {
return _setTimeoutOrIsInterval(aCallback, aMilliseconds, false, null, aArgs); return _setTimeoutOrIsInterval(aCallback, aMilliseconds, false, null, aArgs);
} }
function setTimeoutWithTarget(aCallback, aMilliseconds, aTarget, ...aArgs) { export function setTimeoutWithTarget(
aCallback,
aMilliseconds,
aTarget,
...aArgs
) {
return _setTimeoutOrIsInterval( return _setTimeoutOrIsInterval(
aCallback, aCallback,
aMilliseconds, aMilliseconds,
@ -92,11 +84,16 @@ function setTimeoutWithTarget(aCallback, aMilliseconds, aTarget, ...aArgs) {
); );
} }
function setInterval(aCallback, aMilliseconds, ...aArgs) { export function setInterval(aCallback, aMilliseconds, ...aArgs) {
return _setTimeoutOrIsInterval(aCallback, aMilliseconds, true, null, aArgs); return _setTimeoutOrIsInterval(aCallback, aMilliseconds, true, null, aArgs);
} }
function setIntervalWithTarget(aCallback, aMilliseconds, aTarget, ...aArgs) { export function setIntervalWithTarget(
aCallback,
aMilliseconds,
aTarget,
...aArgs
) {
return _setTimeoutOrIsInterval( return _setTimeoutOrIsInterval(
aCallback, aCallback,
aMilliseconds, aMilliseconds,
@ -112,10 +109,10 @@ function clear(aId) {
gTimerTable.delete(aId); gTimerTable.delete(aId);
} }
} }
var clearInterval = clear; export var clearInterval = clear;
var clearTimeout = clear; export var clearTimeout = clear;
function requestIdleCallback(aCallback, aOptions) { export function requestIdleCallback(aCallback, aOptions) {
if (typeof aCallback !== "function") { if (typeof aCallback !== "function") {
throw new Error("callback is not a function in requestIdleCallback"); throw new Error("callback is not a function in requestIdleCallback");
} }
@ -133,7 +130,7 @@ function requestIdleCallback(aCallback, aOptions) {
return id; return id;
} }
function cancelIdleCallback(aId) { export function cancelIdleCallback(aId) {
if (gTimerTable.has(aId)) { if (gTimerTable.has(aId)) {
gTimerTable.delete(aId); gTimerTable.delete(aId);
} }

View file

@ -7,8 +7,6 @@
* to create a two-way communication channel between chrome and content code. * to create a two-way communication channel between chrome and content code.
*/ */
var EXPORTED_SYMBOLS = ["WebChannel", "WebChannelBroker"];
const ERRNO_UNKNOWN_ERROR = 999; const ERRNO_UNKNOWN_ERROR = 999;
const ERROR_UNKNOWN = "UNKNOWN_ERROR"; const ERROR_UNKNOWN = "UNKNOWN_ERROR";
@ -17,7 +15,7 @@ const ERROR_UNKNOWN = "UNKNOWN_ERROR";
* This object handles channel registration, origin validation and message multiplexing. * This object handles channel registration, origin validation and message multiplexing.
*/ */
var WebChannelBroker = Object.create({ export var WebChannelBroker = Object.create({
/** /**
* Register a new channel that callbacks messages * Register a new channel that callbacks messages
* based on proper origin and channel name * based on proper origin and channel name
@ -86,7 +84,7 @@ var WebChannelBroker = Object.create({
* permission manager. * permission manager.
* @constructor * @constructor
*/ */
var WebChannel = function(id, originOrPermission) { export var WebChannel = function(id, originOrPermission) {
if (!id || !originOrPermission) { if (!id || !originOrPermission) {
throw new Error("WebChannel id and originOrPermission are required."); throw new Error("WebChannel id and originOrPermission are required.");
} }

View file

@ -54,16 +54,16 @@ with Files("AsanReporter.sys.mjs"):
with Files("Color.sys.mjs"): with Files("Color.sys.mjs"):
BUG_COMPONENT = ("Toolkit", "Find Toolbar") BUG_COMPONENT = ("Toolkit", "Find Toolbar")
with Files("Console.jsm"): with Files("Console.sys.mjs"):
BUG_COMPONENT = ("DevTools", "Console") BUG_COMPONENT = ("DevTools", "Console")
with Files("DateTimePicker*.jsm"): with Files("DateTimePicker*.jsm"):
BUG_COMPONENT = ("Core", "Layout: Form Controls") BUG_COMPONENT = ("Core", "Layout: Form Controls")
with Files("DeferredTask.jsm"): with Files("DeferredTask.sys.mjs"):
BUG_COMPONENT = ("Toolkit", "Async Tooling") BUG_COMPONENT = ("Toolkit", "Async Tooling")
with Files("E10SUtils.jsm"): with Files("E10SUtils.sys.mjs"):
BUG_COMPONENT = ("Core", "Security: Process Sandboxing") BUG_COMPONENT = ("Core", "Security: Process Sandboxing")
with Files("nsIE10SUtils.idl"): with Files("nsIE10SUtils.idl"):
@ -105,7 +105,7 @@ with Files("PermissionsUtils.sys.mjs"):
with Files("PopupNotifications.sys.mjs"): with Files("PopupNotifications.sys.mjs"):
BUG_COMPONENT = ("Toolkit", "Notifications and Alerts") BUG_COMPONENT = ("Toolkit", "Notifications and Alerts")
with Files("PrivateBrowsingUtils.jsm"): with Files("PrivateBrowsingUtils.sys.mjs"):
BUG_COMPONENT = ("Firefox", "Private Browsing") BUG_COMPONENT = ("Firefox", "Private Browsing")
with Files("Promise*.jsm"): with Files("Promise*.jsm"):
@ -149,7 +149,7 @@ with Files("docs/**"):
EXTRA_JS_MODULES += [ EXTRA_JS_MODULES += [
"AboutPagesUtils.sys.mjs", "AboutPagesUtils.sys.mjs",
"ActorManagerParent.jsm", "ActorManagerParent.sys.mjs",
"AppMenuNotifications.sys.mjs", "AppMenuNotifications.sys.mjs",
"AsyncPrefs.sys.mjs", "AsyncPrefs.sys.mjs",
"BinarySearch.sys.mjs", "BinarySearch.sys.mjs",
@ -158,14 +158,14 @@ EXTRA_JS_MODULES += [
"CanonicalJSON.jsm", "CanonicalJSON.jsm",
"CertUtils.sys.mjs", "CertUtils.sys.mjs",
"Color.sys.mjs", "Color.sys.mjs",
"Console.jsm", "Console.sys.mjs",
"ContentDOMReference.jsm", "ContentDOMReference.sys.mjs",
"CreditCard.sys.mjs", "CreditCard.sys.mjs",
"DateTimePickerPanel.sys.mjs", "DateTimePickerPanel.sys.mjs",
"DeferredTask.jsm", "DeferredTask.sys.mjs",
"Deprecated.jsm", "Deprecated.sys.mjs",
"E10SUtils.jsm", "E10SUtils.sys.mjs",
"EventEmitter.jsm", "EventEmitter.sys.mjs",
"FileUtils.sys.mjs", "FileUtils.sys.mjs",
"FindBarContent.sys.mjs", "FindBarContent.sys.mjs",
"Finder.sys.mjs", "Finder.sys.mjs",
@ -194,8 +194,8 @@ EXTRA_JS_MODULES += [
"OSKeyStore.sys.mjs", "OSKeyStore.sys.mjs",
"PermissionsUtils.sys.mjs", "PermissionsUtils.sys.mjs",
"PopupNotifications.sys.mjs", "PopupNotifications.sys.mjs",
"Preferences.jsm", "Preferences.sys.mjs",
"PrivateBrowsingUtils.jsm", "PrivateBrowsingUtils.sys.mjs",
"ProcessType.sys.mjs", "ProcessType.sys.mjs",
"ProfileAge.sys.mjs", "ProfileAge.sys.mjs",
"PromiseUtils.sys.mjs", "PromiseUtils.sys.mjs",
@ -209,10 +209,10 @@ EXTRA_JS_MODULES += [
"ShortcutUtils.sys.mjs", "ShortcutUtils.sys.mjs",
"Sqlite.sys.mjs", "Sqlite.sys.mjs",
"SubDialog.sys.mjs", "SubDialog.sys.mjs",
"Timer.jsm", "Timer.sys.mjs",
"Troubleshoot.sys.mjs", "Troubleshoot.sys.mjs",
"UpdateUtils.sys.mjs", "UpdateUtils.sys.mjs",
"WebChannel.jsm", "WebChannel.sys.mjs",
] ]
if CONFIG["MOZ_ASAN_REPORTER"]: if CONFIG["MOZ_ASAN_REPORTER"]:
@ -242,7 +242,7 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("windows", "gtk", "cocoa"):
DEFINES["HAVE_SHELL_SERVICE"] = 1 DEFINES["HAVE_SHELL_SERVICE"] = 1
EXTRA_PP_JS_MODULES += [ EXTRA_PP_JS_MODULES += [
"AppConstants.jsm", "AppConstants.sys.mjs",
] ]
if "Android" != CONFIG["OS_TARGET"]: if "Android" != CONFIG["OS_TARGET"]: