Skip to content

Commit

Permalink
Bug 1864821 - Replace PromiseUtils.defer() with Promise.withResolvers…
Browse files Browse the repository at this point in the history
…() in extension code. r=extension-reviewers,geckoview-reviewers,rpl,m_kato

Differential Revision: https://phabricator.services.mozilla.com/D197488
  • Loading branch information
Standard8 committed Jan 5, 2024
1 parent d2ee551 commit 5b35334
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 27 deletions.
3 changes: 1 addition & 2 deletions browser/components/extensions/parent/ext-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ ChromeUtils.defineESModuleGetters(this, {
AboutReaderParent: "resource:///actors/AboutReaderParent.sys.mjs",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs",
});

var { ExtensionError } = ExtensionUtils;
Expand Down Expand Up @@ -442,7 +441,7 @@ class TabTracker extends TabTrackerBase {
deferredForTabOpen(nativeTab) {
let deferred = this._deferredTabOpenEvents.get(nativeTab);
if (!deferred) {
deferred = PromiseUtils.defer();
deferred = Promise.withResolvers();
this._deferredTabOpenEvents.set(nativeTab, deferred);
deferred.promise.then(() => {
this._deferredTabOpenEvents.delete(nativeTab);
Expand Down
3 changes: 1 addition & 2 deletions browser/components/extensions/parent/ext-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ChromeUtils.defineESModuleGetters(this, {
ExtensionControlledPopup:
"resource:///modules/ExtensionControlledPopup.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs",
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
});

Expand Down Expand Up @@ -127,7 +126,7 @@ let tabListener = {
if (promise) {
return promise;
}
deferred = PromiseUtils.defer();
deferred = Promise.withResolvers();
if (
!this.initializingTabs.has(nativeTab) &&
(nativeTab.linkedBrowser.innerWindowID ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { AddonTestUtils } = ChromeUtils.importESModule(
ChromeUtils.defineESModuleGetters(this, {
AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
HomePage: "resource:///modules/HomePage.sys.mjs",
PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs",
RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
sinon: "resource://testing-common/Sinon.sys.mjs",
});
Expand All @@ -27,7 +26,7 @@ AddonTestUtils.createAppInfo(
// Similar to TestUtils.topicObserved, but returns a deferred promise that
// can be resolved
function topicObservable(topic, checkFn) {
let deferred = PromiseUtils.defer();
let deferred = Promise.withResolvers();
function observer(subject, topic, data) {
try {
if (checkFn && !checkFn(subject, data)) {
Expand Down
3 changes: 1 addition & 2 deletions mobile/android/components/extensions/ext-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

ChromeUtils.defineESModuleGetters(this, {
GeckoViewTabBridge: "resource://gre/modules/GeckoViewTab.sys.mjs",
PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs",
mobileWindowTracker: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
});

Expand Down Expand Up @@ -62,7 +61,7 @@ const tabListener = {
awaitTabReady(nativeTab) {
let deferred = this.tabReadyPromises.get(nativeTab);
if (!deferred) {
deferred = PromiseUtils.defer();
deferred = Promise.withResolvers();
if (
!this.initializingTabs.has(nativeTab) &&
(nativeTab.browser.innerWindowID ||
Expand Down
3 changes: 1 addition & 2 deletions toolkit/components/extensions/ExtensionChild.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
ExtensionProcessScript:
"resource://gre/modules/ExtensionProcessScript.sys.mjs",
NativeApp: "resource://gre/modules/NativeMessaging.sys.mjs",
PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs",
});

import { ExtensionCommon } from "resource://gre/modules/ExtensionCommon.sys.mjs";
Expand Down Expand Up @@ -881,7 +880,7 @@ class ChildAPIManager {
*/
callParentAsyncFunction(path, args, callback, options = {}) {
let callId = getUniqueId();
let deferred = lazy.PromiseUtils.defer();
let deferred = Promise.withResolvers();
this.callPromises.set(callId, deferred);

let {
Expand Down
3 changes: 1 addition & 2 deletions toolkit/components/extensions/ExtensionDNRStore.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
Extension: "resource://gre/modules/Extension.sys.mjs",
ExtensionDNR: "resource://gre/modules/ExtensionDNR.sys.mjs",
ExtensionDNRLimits: "resource://gre/modules/ExtensionDNRLimits.sys.mjs",
PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs",
Schemas: "resource://gre/modules/Schemas.sys.mjs",
});

Expand Down Expand Up @@ -298,7 +297,7 @@ class Queue {
if (this.#closed) {
throw new Error("Unexpected queueTask call on closed queue");
}
const deferred = lazy.PromiseUtils.defer();
const deferred = Promise.withResolvers();
this.#tasks.push({ callback, deferred });
// Run the queued task right away if there isn't one already running.
if (!this.#runningTask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
const { MessageManagerProxy } = ChromeUtils.importESModule(
"resource://gre/modules/MessageManagerProxy.sys.mjs"
);
const { PromiseUtils } = ChromeUtils.importESModule(
"resource://gre/modules/PromiseUtils.sys.mjs"
);

class TestMessageManagerProxy extends MessageManagerProxy {
constructor(contentPage, identifier) {
Expand Down Expand Up @@ -39,7 +36,7 @@ class TestMessageManagerProxy extends MessageManagerProxy {

async testPingPong(description) {
equal(this.deferred, null, "should not be waiting for a message");
this.deferred = PromiseUtils.defer();
this.deferred = Promise.withResolvers();
this.sendAsyncMessage("test:MessageManagerProxy:Ping", description);
let result = await this.deferred.promise;
equal(result, `${this.identifier}:${description}`, "Expected ping-pong");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ ChromeUtils.defineESModuleGetters(this, {
Preferences: "resource://gre/modules/Preferences.sys.mjs",
});

var { PromiseUtils } = ChromeUtils.importESModule(
"resource://gre/modules/PromiseUtils.sys.mjs"
);

const { createAppInfo, promiseShutdownManager, promiseStartupManager } =
AddonTestUtils;

Expand Down Expand Up @@ -556,12 +552,12 @@ add_task(async function test_preference_manager_set_when_disabled() {
ok(isUndefinedPref("foo"), "test pref is not set");

await ExtensionSettingsStore.initialize();
let lastItemChange = PromiseUtils.defer();
let lastItemChange = Promise.withResolvers();
ExtensionPreferencesManager.addSetting("some-pref", {
prefNames: ["foo", "bar"],
onPrefsChanged(item) {
lastItemChange.resolve(item);
lastItemChange = PromiseUtils.defer();
lastItemChange = Promise.withResolvers();
},
setCallback(value) {
return { [this.prefNames[0]]: value, [this.prefNames[1]]: false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
var { WebRequest } = ChromeUtils.importESModule(
"resource://gre/modules/WebRequest.sys.mjs"
);
var { PromiseUtils } = ChromeUtils.importESModule(
"resource://gre/modules/PromiseUtils.sys.mjs"
);
var { ExtensionParent } = ChromeUtils.importESModule(
"resource://gre/modules/ExtensionParent.sys.mjs"
);
Expand All @@ -20,7 +17,7 @@ add_task(async function setup() {
});

add_task(async function test_ancestors_exist() {
let deferred = PromiseUtils.defer();
let deferred = Promise.withResolvers();
function onBeforeRequest(details) {
info(`onBeforeRequest ${details.url}`);
ok(
Expand All @@ -46,7 +43,7 @@ add_task(async function test_ancestors_exist() {
});

add_task(async function test_ancestors_null() {
let deferred = PromiseUtils.defer();
let deferred = Promise.withResolvers();
function onBeforeRequest(details) {
info(`onBeforeRequest ${details.url}`);
ok(details.frameAncestors === undefined, "ancestors do not exist");
Expand Down

0 comments on commit 5b35334

Please sign in to comment.