Bug 1823217 - Convert toolkit/components/crashes to ES modules. r=gsvelto

Differential Revision: https://phabricator.services.mozilla.com/D172934
This commit is contained in:
Mark Banner 2023-03-23 08:15:47 +00:00
parent f2ae48a063
commit b4d9434d7f
11 changed files with 37 additions and 75 deletions

View file

@ -3,7 +3,7 @@
"use strict";
// Ensures that content crashes are reported to the crash service
// (nsICrashService and CrashManager.jsm).
// (nsICrashService and CrashManager.sys.mjs).
/* eslint-disable mozilla/no-arbitrary-setTimeout */
SimpleTest.requestFlakyTimeout("untriaged");

View file

@ -591,8 +591,8 @@ async function collectCrashInfo() {
return;
}
const { getCrashManager } = ChromeUtils.import(
"resource://gre/modules/CrashManager.jsm"
const { getCrashManager } = ChromeUtils.importESModule(
"resource://gre/modules/CrashManager.sys.mjs"
);
const crashes = await getCrashManager().getCrashes();
CrashModuleSet = new Set(

View file

@ -2,20 +2,10 @@
* 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";
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { PromiseUtils } = ChromeUtils.importESModule(
"resource://gre/modules/PromiseUtils.sys.mjs"
);
const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { PromiseUtils } from "resource://gre/modules/PromiseUtils.sys.mjs";
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -24,15 +14,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
TelemetryController: "resource://gre/modules/TelemetryController.sys.mjs",
});
var EXPORTED_SYMBOLS = [
"CrashManager",
"getCrashManager",
// The following are exported for tests only.
"CrashStore",
"dateToDays",
"getCrashManagerNoCreate",
];
/**
* How long to wait after application startup before crash event files are
* automatically aggregated.
@ -47,7 +28,7 @@ const MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
// Converts Date to days since UNIX epoch.
// This was copied from /services/metrics.storage.jsm. The implementation
// does not account for leap seconds.
function dateToDays(date) {
export function dateToDays(date) {
return Math.floor(date.getTime() / MILLISECONDS_IN_DAY);
}
@ -123,7 +104,7 @@ function parseAndRemoveField(obj, field) {
* telemetryStoreSizeKey (string)
* Telemetry histogram to report store size under.
*/
var CrashManager = function(options) {
export var CrashManager = function(options) {
for (let k in options) {
let value = options[k];
@ -1015,7 +996,7 @@ var gCrashManager;
* The telemetry histogram that should be used to store the size
* of the data file.
*/
function CrashStore(storeDir, telemetrySizeKey) {
export function CrashStore(storeDir, telemetrySizeKey) {
this._storeDir = storeDir;
this._telemetrySizeKey = telemetrySizeKey;
@ -1627,7 +1608,7 @@ XPCOMUtils.defineLazyGetter(CrashManager, "Singleton", function() {
return gCrashManager;
});
function getCrashManager() {
export function getCrashManager() {
return CrashManager.Singleton;
}
@ -1636,6 +1617,6 @@ function getCrashManager() {
*
* @returns {CrashManager}
*/
function getCrashManagerNoCreate() {
export function getCrashManagerNoCreate() {
return gCrashManager;
}

View file

@ -4,26 +4,15 @@
/*
* This file provides common and shared functionality to facilitate
* testing of the Crashes component (CrashManager.jsm).
* testing of the Crashes component (CrashManager.sys.mjs).
*/
"use strict";
var EXPORTED_SYMBOLS = [
"configureLogging",
"getManager",
"sleep",
"TestingCrashManager",
];
/* global OS */
Cc["@mozilla.org/net/osfileconstantsservice;1"]
.getService(Ci.nsIOSFileConstantsService)
.init();
const { CrashManager } = ChromeUtils.import(
"resource://gre/modules/CrashManager.jsm"
);
import { CrashManager } from "resource://gre/modules/CrashManager.sys.mjs";
const lazy = {};
@ -34,7 +23,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
var loggingConfigured = false;
var configureLogging = function() {
export var configureLogging = function() {
if (loggingConfigured) {
return;
}
@ -47,7 +36,7 @@ var configureLogging = function() {
loggingConfigured = true;
};
var sleep = function(wait) {
export var sleep = function(wait) {
return new Promise(resolve => {
lazy.setTimeout(() => {
resolve();
@ -55,7 +44,7 @@ var sleep = function(wait) {
});
};
var TestingCrashManager = function(options) {
export var TestingCrashManager = function(options) {
CrashManager.call(this, options);
};
@ -163,7 +152,7 @@ Object.setPrototypeOf(TestingCrashManager.prototype, CrashManager.prototype);
var DUMMY_DIR_COUNT = 0;
var getManager = function() {
export var getManager = function() {
return (async function() {
const dirMode = OS.Constants.libc.S_IRWXU;
let baseFile = PathUtils.profileDir;

View file

@ -2,14 +2,8 @@
* 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";
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { AsyncShutdown } = ChromeUtils.importESModule(
"resource://gre/modules/AsyncShutdown.sys.mjs"
);
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { AsyncShutdown } from "resource://gre/modules/AsyncShutdown.sys.mjs";
// Set to true if the application is quitting
var gQuitting = false;
@ -157,7 +151,7 @@ function processExtraFile(extraPath) {
*
* It is a service because some background activity will eventually occur.
*/
function CrashService() {
export function CrashService() {
Services.obs.addObserver(this, "quit-application");
}
@ -238,5 +232,3 @@ CrashService.prototype = Object.freeze({
}
},
});
var EXPORTED_SYMBOLS = ["CrashService"];

View file

@ -8,7 +8,7 @@ Classes = [
{
'cid': '{92668367-1b17-4190-86b2-1061b2179744}',
'contract_ids': ['@mozilla.org/crashservice;1'],
'jsm': 'resource://gre/modules/CrashService.jsm',
'esModule': 'resource://gre/modules/CrashService.sys.mjs',
'constructor': 'CrashService',
'categories': {'profile-after-change': 'CrashService'},
},
@ -16,7 +16,7 @@ Classes = [
'js_name': 'crashmanager',
'cid': '{c887b6a9-a5eb-4566-a440-bebaea3e54fd}',
'contract_ids': ['@mozilla.org/crashmanager;1'],
'jsm': 'resource://gre/modules/CrashManager.jsm',
'esModule': 'resource://gre/modules/CrashManager.sys.mjs',
'constructor': 'getCrashManager',
},
]

View file

@ -11,7 +11,7 @@ From JavaScript, the service can be accessed via::
let crashManager = Services.crashmanager;
That will give you an instance of ``CrashManager`` from ``CrashManager.jsm``.
That will give you an instance of ``CrashManager`` from ``CrashManager.sys.mjs``.
From there, you can access and manipulate crash data.
The crash manager stores statistical information about crashes as well as

View file

@ -19,15 +19,15 @@ XPIDL_SOURCES += [
if CONFIG["MOZ_CRASHREPORTER"]:
GeneratedFile(
"CrashManager.jsm",
"CrashManager.sys.mjs",
script="gen_CrashManager.py",
entry_point="main",
inputs=["CrashManager.in.jsm"],
inputs=["CrashManager.in.sys.mjs"],
)
EXTRA_JS_MODULES += [
"!CrashManager.jsm",
"CrashService.jsm",
"!CrashManager.sys.mjs",
"CrashService.sys.mjs",
]
XPCOM_MANIFESTS += [
@ -35,7 +35,7 @@ if CONFIG["MOZ_CRASHREPORTER"]:
]
TESTING_JS_MODULES += [
"CrashManagerTest.jsm",
"CrashManagerTest.sys.mjs",
]
XPCSHELL_TESTS_MANIFESTS += ["tests/xpcshell/xpcshell.ini"]

View file

@ -3,14 +3,14 @@
"use strict";
const { CrashManager } = ChromeUtils.import(
"resource://gre/modules/CrashManager.jsm"
const { CrashManager } = ChromeUtils.importESModule(
"resource://gre/modules/CrashManager.sys.mjs"
);
const { TelemetryArchiveTesting } = ChromeUtils.importESModule(
"resource://testing-common/TelemetryArchiveTesting.sys.mjs"
);
const { configureLogging, getManager, sleep } = ChromeUtils.import(
"resource://testing-common/CrashManagerTest.jsm"
const { configureLogging, getManager, sleep } = ChromeUtils.importESModule(
"resource://testing-common/CrashManagerTest.sys.mjs"
);
const { TelemetryEnvironment } = ChromeUtils.importESModule(
"resource://gre/modules/TelemetryEnvironment.sys.mjs"

View file

@ -3,8 +3,8 @@
"use strict";
const { getCrashManagerNoCreate } = ChromeUtils.import(
"resource://gre/modules/CrashManager.jsm"
const { getCrashManagerNoCreate } = ChromeUtils.importESModule(
"resource://gre/modules/CrashManager.sys.mjs"
);
const { makeFakeAppDir } = ChromeUtils.importESModule(
"resource://testing-common/AppData.sys.mjs"

View file

@ -7,8 +7,8 @@
"use strict";
const { CrashManager, CrashStore, dateToDays } = ChromeUtils.import(
"resource://gre/modules/CrashManager.jsm"
const { CrashManager, CrashStore, dateToDays } = ChromeUtils.importESModule(
"resource://gre/modules/CrashManager.sys.mjs"
);
const DUMMY_DATE = new Date(Date.now() - 10 * 24 * 60 * 60 * 1000);