Bug 1842545 - Convert remained JSM to ESM. r=geckoview-reviewers,amejiamarmol

Also, AndroidLog.sys.mjs still has unnecessary CommonJS support although this
support is gone by bug 1773390.

Differential Revision: https://phabricator.services.mozilla.com/D183111
This commit is contained in:
Makoto Kato 2023-07-11 02:14:00 +00:00
parent 7568064e67
commit 234a615953
10 changed files with 24 additions and 59 deletions

View File

@ -7,8 +7,8 @@
"use strict";
const { GeckoViewChildModule } = ChromeUtils.import(
"resource://gre/modules/GeckoViewChildModule.jsm"
const { GeckoViewChildModule } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewChildModule.sys.mjs"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"

View File

@ -4,8 +4,8 @@
"use strict";
var { DelayedInit } = ChromeUtils.import(
"resource://gre/modules/DelayedInit.jsm"
var { DelayedInit } = ChromeUtils.importESModule(
"resource://gre/modules/DelayedInit.sys.mjs"
);
var { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
@ -18,16 +18,13 @@ ChromeUtils.defineESModuleGetters(this, {
GeckoViewActorManager: "resource://gre/modules/GeckoViewActorManager.sys.mjs",
GeckoViewSettings: "resource://gre/modules/GeckoViewSettings.sys.mjs",
GeckoViewUtils: "resource://gre/modules/GeckoViewUtils.sys.mjs",
HistogramStopwatch: "resource://gre/modules/GeckoViewTelemetry.sys.mjs",
InitializationTracker: "resource://gre/modules/GeckoViewTelemetry.sys.mjs",
RemoteSecuritySettings:
"resource://gre/modules/psm/RemoteSecuritySettings.sys.mjs",
SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(this, {
HistogramStopwatch: "resource://gre/modules/GeckoViewTelemetry.jsm",
InitializationTracker: "resource://gre/modules/GeckoViewTelemetry.jsm",
});
XPCOMUtils.defineLazyGetter(this, "WindowEventDispatcher", () =>
EventDispatcher.for(window)
);

View File

@ -2,6 +2,7 @@
* 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/. */
import { DelayedInit } from "resource://gre/modules/DelayedInit.sys.mjs";
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
const lazy = {};
@ -14,10 +15,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
const { debug, warn } = GeckoViewUtils.initLogging("Startup");
var { DelayedInit } = ChromeUtils.import(
"resource://gre/modules/DelayedInit.jsm"
);
function InitLater(fn, object, name) {
return DelayedInit.schedule(fn, object, name, 15000 /* 15s max wait */);
}

View File

@ -2,16 +2,16 @@
* 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";
/**
* Native Android logging for JavaScript. Lets you specify a priority and tag
* in addition to the message being logged. Resembles the android.util.Log API
* <http://developer.android.com/reference/android/util/Log.html>.
*
* // Import it as a JSM:
* let Log = ChromeUtils.import("resource://gre/modules/AndroidLog.jsm")
* .AndroidLog;
* // Import it as a ESM:
* let Log =
* ChromeUtils.importESModule("resource://gre/modules/AndroidLog.sys.mjs")
* .AndroidLog;
*
* // Use Log.i, Log.v, Log.d, Log.w, and Log.e to log verbose, debug, info,
* // warning, and error messages, respectively.
@ -36,10 +36,7 @@
* truncates tags longer than MAX_TAG_LENGTH characters (not including "Gecko").
*/
const EXPORTED_SYMBOLS = ["AndroidLog"];
const { ctypes } = ChromeUtils.importESModule(
"resource://gre/modules/ctypes.sys.mjs"
);
import { ctypes } from "resource://gre/modules/ctypes.sys.mjs";
// From <https://android.googlesource.com/platform/system/core/+/master/include/android/log.h>.
const ANDROID_LOG_VERBOSE = 2;
@ -64,7 +61,7 @@ var __android_log_write = liblog.declare(
ctypes.char.ptr
); // message
var AndroidLog = {
export var AndroidLog = {
MAX_TAG_LENGTH,
v: (tag, msg) => __android_log_write(ANDROID_LOG_VERBOSE, "Gecko" + tag, msg),
d: (tag, msg) => __android_log_write(ANDROID_LOG_DEBUG, "Gecko" + tag, msg),
@ -83,9 +80,3 @@ var AndroidLog = {
};
},
};
if (typeof Components == "undefined") {
// Specify exported symbols for require.js module loader.
// eslint-disable-next-line no-undef
module.exports = AndroidLog;
}

View File

@ -1,11 +1,6 @@
/* 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";
/* globals MessageLoop */
var EXPORTED_SYMBOLS = ["DelayedInit"];
/**
* Use DelayedInit to schedule initializers to run some time after startup.
@ -40,7 +35,7 @@ var EXPORTED_SYMBOLS = ["DelayedInit"];
* InitLater(() => Foo.init());
* InitLater(() => Bar.init(), this, "Bar");
*/
var DelayedInit = {
export var DelayedInit = {
schedule(fn, object, name, maxWait) {
return Impl.scheduleInit(fn, object, name, maxWait);
},

View File

@ -2,17 +2,11 @@
* 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 EXPORTED_SYMBOLS = ["GeckoViewChildModule"];
const { GeckoViewUtils } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewUtils.sys.mjs"
);
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
const { debug, warn } = GeckoViewUtils.initLogging("Module[C]");
class GeckoViewChildModule {
export class GeckoViewChildModule {
static initLogging(aModuleName) {
this._moduleName = aModuleName;
const tag = aModuleName.replace("GeckoView", "") + "[C]";

View File

@ -23,10 +23,7 @@ XPCOMUtils.defineLazyServiceGetter(
ChromeUtils.defineESModuleGetters(lazy, {
BrowserTelemetryUtils: "resource://gre/modules/BrowserTelemetryUtils.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
HistogramStopwatch: "resource://gre/modules/GeckoViewTelemetry.jsm",
HistogramStopwatch: "resource://gre/modules/GeckoViewTelemetry.sys.mjs",
});
var IdentityHandler = {

View File

@ -1,11 +1,8 @@
/* 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 EXPORTED_SYMBOLS = ["HistogramStopwatch", "InitializationTracker"];
var InitializationTracker = {
export var InitializationTracker = {
initialized: false,
onInitialized(profilerTime) {
if (!this.initialized) {
@ -19,7 +16,7 @@ var InitializationTracker = {
};
// A helper for histogram timer probes.
class HistogramStopwatch {
export class HistogramStopwatch {
constructor(aName, aAssociated) {
this._name = aName;
this._obj = aAssociated;

View File

@ -8,15 +8,12 @@ import { Log } from "resource://gre/modules/Log.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AndroidLog: "resource://gre/modules/AndroidLog.sys.mjs",
EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
clearTimeout: "resource://gre/modules/Timer.sys.mjs",
setTimeout: "resource://gre/modules/Timer.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
AndroidLog: "resource://gre/modules/AndroidLog.jsm",
});
/**
* A formatter that does not prepend time/name/level information to messages,
* because those fields are logged separately when using the Android logger.

View File

@ -5,16 +5,16 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXTRA_JS_MODULES += [
"AndroidLog.jsm",
"AndroidLog.sys.mjs",
"BrowserUsageTelemetry.sys.mjs",
"ChildCrashHandler.sys.mjs",
"DelayedInit.jsm",
"DelayedInit.sys.mjs",
"GeckoViewActorChild.sys.mjs",
"GeckoViewActorManager.sys.mjs",
"GeckoViewActorParent.sys.mjs",
"GeckoViewAutocomplete.sys.mjs",
"GeckoViewAutofill.sys.mjs",
"GeckoViewChildModule.jsm",
"GeckoViewChildModule.sys.mjs",
"GeckoViewConsole.sys.mjs",
"GeckoViewContent.sys.mjs",
"GeckoViewContentBlocking.sys.mjs",
@ -31,7 +31,7 @@ EXTRA_JS_MODULES += [
"GeckoViewSettings.sys.mjs",
"GeckoViewStorageController.sys.mjs",
"GeckoViewTab.sys.mjs",
"GeckoViewTelemetry.jsm",
"GeckoViewTelemetry.sys.mjs",
"GeckoViewTestUtils.sys.mjs",
"GeckoViewUtils.sys.mjs",
"GeckoViewWebExtension.sys.mjs",