Commit b4d9434d authored by Mark Banner's avatar Mark Banner
Browse files

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

parent f2ae48a0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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");
+2 −2
Original line number Diff line number Diff line
@@ -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(
+9 −28
Original line number Diff line number Diff line
@@ -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;
}
+6 −17
Original line number Diff line number Diff line
@@ -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;
+3 −11
Original line number Diff line number Diff line
@@ -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"];
Loading