From 5b35334238a13c1c599247c885386a347a74b1a2 Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Fri, 5 Jan 2024 09:22:34 +0000 Subject: [PATCH] Bug 1864821 - Replace PromiseUtils.defer() with Promise.withResolvers() in extension code. r=extension-reviewers,geckoview-reviewers,rpl,m_kato Differential Revision: https://phabricator.services.mozilla.com/D197488 --- browser/components/extensions/parent/ext-browser.js | 3 +-- browser/components/extensions/parent/ext-tabs.js | 3 +-- .../xpcshell/test_ext_chrome_settings_overrides_update.js | 3 +-- mobile/android/components/extensions/ext-tabs.js | 3 +-- toolkit/components/extensions/ExtensionChild.sys.mjs | 3 +-- toolkit/components/extensions/ExtensionDNRStore.sys.mjs | 3 +-- .../test/xpcshell/test_ext_MessageManagerProxy.js | 5 +---- .../test/xpcshell/test_ext_extensionPreferencesManager.js | 8 ++------ .../extensions/test/xpcshell/test_webRequest_ancestors.js | 7 ++----- 9 files changed, 11 insertions(+), 27 deletions(-) diff --git a/browser/components/extensions/parent/ext-browser.js b/browser/components/extensions/parent/ext-browser.js index 2c04515f7c46..355f4f066810 100644 --- a/browser/components/extensions/parent/ext-browser.js +++ b/browser/components/extensions/parent/ext-browser.js @@ -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; @@ -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); diff --git a/browser/components/extensions/parent/ext-tabs.js b/browser/components/extensions/parent/ext-tabs.js index 64a405605192..53d470e6f1ea 100644 --- a/browser/components/extensions/parent/ext-tabs.js +++ b/browser/components/extensions/parent/ext-tabs.js @@ -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", }); @@ -127,7 +126,7 @@ let tabListener = { if (promise) { return promise; } - deferred = PromiseUtils.defer(); + deferred = Promise.withResolvers(); if ( !this.initializingTabs.has(nativeTab) && (nativeTab.linkedBrowser.innerWindowID || diff --git a/browser/components/extensions/test/xpcshell/test_ext_chrome_settings_overrides_update.js b/browser/components/extensions/test/xpcshell/test_ext_chrome_settings_overrides_update.js index 8ad339896b7f..847adefb393e 100644 --- a/browser/components/extensions/test/xpcshell/test_ext_chrome_settings_overrides_update.js +++ b/browser/components/extensions/test/xpcshell/test_ext_chrome_settings_overrides_update.js @@ -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", }); @@ -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)) { diff --git a/mobile/android/components/extensions/ext-tabs.js b/mobile/android/components/extensions/ext-tabs.js index f4f44a89673e..cd31781d1b9f 100644 --- a/mobile/android/components/extensions/ext-tabs.js +++ b/mobile/android/components/extensions/ext-tabs.js @@ -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", }); @@ -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 || diff --git a/toolkit/components/extensions/ExtensionChild.sys.mjs b/toolkit/components/extensions/ExtensionChild.sys.mjs index a06ac8024f11..20c3c8f2ab6b 100644 --- a/toolkit/components/extensions/ExtensionChild.sys.mjs +++ b/toolkit/components/extensions/ExtensionChild.sys.mjs @@ -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"; @@ -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 { diff --git a/toolkit/components/extensions/ExtensionDNRStore.sys.mjs b/toolkit/components/extensions/ExtensionDNRStore.sys.mjs index 5febc16b899d..7221e2cd3b73 100644 --- a/toolkit/components/extensions/ExtensionDNRStore.sys.mjs +++ b/toolkit/components/extensions/ExtensionDNRStore.sys.mjs @@ -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", }); @@ -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) { diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_MessageManagerProxy.js b/toolkit/components/extensions/test/xpcshell/test_ext_MessageManagerProxy.js index 988da4f40521..cb6ec47b5250 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_MessageManagerProxy.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_MessageManagerProxy.js @@ -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) { @@ -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"); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_extensionPreferencesManager.js b/toolkit/components/extensions/test/xpcshell/test_ext_extensionPreferencesManager.js index 2f6e3dbe1423..75b011214234 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_extensionPreferencesManager.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_extensionPreferencesManager.js @@ -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; @@ -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 }; diff --git a/toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js b/toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js index 43e2d11872f0..a391937e44e0 100644 --- a/toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js +++ b/toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js @@ -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" ); @@ -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( @@ -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");