зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
d2ee55188c
Коммит
5b35334238
|
@ -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);
|
||||
|
|
|
@ -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 ||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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 ||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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");
|
||||
|
|
Загрузка…
Ссылка в новой задаче