Bug 1873189 - Port bug 1845586 - Replace PromiseUtils.defer with Promise.withResolvers. r=aleca

Differential Revision: https://phabricator.services.mozilla.com/D197777

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Magnus Melin 2024-01-05 17:10:16 +00:00
Родитель f7576e31f4
Коммит 87b2fa80d3
25 изменённых файлов: 67 добавлений и 71 удалений

Просмотреть файл

@ -1027,7 +1027,7 @@ let CalendarFilteredViewMixin = Base =>
*
* @type {object}
*/
#deferred = PromiseUtils.defer();
#deferred = Promise.withResolvers();
/**
* Any async iterator currently reading from a calendar.
@ -1232,7 +1232,7 @@ let CalendarFilteredViewMixin = Base =>
// If a previous refresh completed, start a new Promise that resolves when the next refresh
// completes. Otherwise, continue with the current Promise.
// If #currentRefresh is completed, #deferred is already resolved, so we can safely discard it.
this.#deferred = PromiseUtils.defer();
this.#deferred = Promise.withResolvers();
}
this.#currentRefresh = null;
}

Просмотреть файл

@ -14,7 +14,7 @@ add_setup(async function () {
loginInfo.init(CalDAVServer.origin, null, "test", "bob", "bob", "", "");
await Services.logins.addLoginAsync(loginInfo);
}
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
calendar = createCalendar("caldav", CalDAVServer.url, true);
await calendarObserver._onLoadPromise.promise;
info("calendar set-up complete");

Просмотреть файл

@ -14,7 +14,7 @@ add_setup(async function () {
loginInfo.init(CalDAVServer.origin, null, "test", "bob", "bob", "", "");
await Services.logins.addLoginAsync(loginInfo);
}
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
calendar = createCalendar("caldav", CalDAVServer.url, false);
await calendarObserver._onLoadPromise.promise;
info("calendar set-up complete");

Просмотреть файл

@ -21,7 +21,7 @@ add_setup(async function () {
// Remove the next line when this is fixed.
calendarObserver._batchRequired = false;
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
calendar = createCalendar("ics", ICSServer.url, true);
await calendarObserver._onLoadPromise.promise;
info("calendar set-up complete");

Просмотреть файл

@ -14,7 +14,7 @@ add_setup(async function () {
loginInfo.init(ICSServer.origin, null, "test", "bob", "bob", "", "");
await Services.logins.addLoginAsync(loginInfo);
}
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
calendar = createCalendar("ics", ICSServer.url, false);
await calendarObserver._onLoadPromise.promise;
info("calendar set-up complete");

Просмотреть файл

@ -111,8 +111,8 @@ async function runAddItem(calendar) {
event.startDate = cal.createDateTime("20200303T205500Z");
event.endDate = cal.createDateTime("20200303T210200Z");
calendarObserver._onAddItemPromise = PromiseUtils.defer();
calendarObserver._onModifyItemPromise = PromiseUtils.defer();
calendarObserver._onAddItemPromise = Promise.withResolvers();
calendarObserver._onModifyItemPromise = Promise.withResolvers();
await calendar.addItem(event);
await Promise.any([
calendarObserver._onAddItemPromise.promise,
@ -133,7 +133,7 @@ async function runModifyItem(calendar) {
const clone = event.clone();
clone.title = "Modified event";
calendarObserver._onModifyItemPromise = PromiseUtils.defer();
calendarObserver._onModifyItemPromise = Promise.withResolvers();
await calendar.modifyItem(clone, event);
await calendarObserver._onModifyItemPromise.promise;
}
@ -146,7 +146,7 @@ async function runModifyItem(calendar) {
async function runDeleteItem(calendar) {
const event = await calendar.getItem("6b7dd6f6-d6f0-4e93-a953-bb5473c4c47a");
calendarObserver._onDeleteItemPromise = PromiseUtils.defer();
calendarObserver._onDeleteItemPromise = Promise.withResolvers();
await calendar.deleteItem(event);
await calendarObserver._onDeleteItemPromise.promise;
}

Просмотреть файл

@ -23,8 +23,8 @@ add_setup(async function () {
registerCleanupFunction(() => CalDAVServer.close());
add_task(async function () {
calendarObserver._onAddItemPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onAddItemPromise = Promise.withResolvers();
calendarObserver._onLoadPromise = Promise.withResolvers();
const calendar = createCalendar("caldav", CalDAVServer.url, true);
await calendarObserver._onAddItemPromise.promise;
await calendarObserver._onLoadPromise.promise;
@ -34,12 +34,12 @@ add_task(async function () {
info("creating the item");
calendarObserver._batchRequired = true;
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runAddItem(calendar);
await calendarObserver._onLoadPromise.promise;
info("modifying the item");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runModifyItem(calendar);
await calendarObserver._onLoadPromise.promise;
@ -55,7 +55,7 @@ add_task(async function () {
*/
add_task(async function testCalendarWithNoPrivSupport() {
CalDAVServer.privileges = null;
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
const calendar = createCalendar("caldav", CalDAVServer.url, true);
await calendarObserver._onLoadPromise.promise;
@ -100,8 +100,8 @@ add_task(async function testModifyItemWithNoChanges() {
* items from the local calendar.
*/
add_task(async function testSyncError1() {
calendarObserver._onAddItemPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onAddItemPromise = Promise.withResolvers();
calendarObserver._onLoadPromise = Promise.withResolvers();
const calendar = createCalendar("caldav", CalDAVServer.url, true);
await calendarObserver._onAddItemPromise.promise;
await calendarObserver._onLoadPromise.promise;
@ -114,7 +114,7 @@ add_task(async function testSyncError1() {
info("syncing with rate limit error");
CalDAVServer.throwRateLimitErrors = true;
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
calendar.refresh();
await calendarObserver._onLoadPromise.promise;
CalDAVServer.throwRateLimitErrors = false;
@ -132,7 +132,7 @@ add_task(async function testSyncError1() {
);
info("syncing without rate limit error");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
calendar.refresh();
await calendarObserver._onLoadPromise.promise;
info("sync without rate limit error complete");
@ -171,8 +171,8 @@ add_task(async function testSyncError2() {
);
}
calendarObserver._onAddItemPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onAddItemPromise = Promise.withResolvers();
calendarObserver._onLoadPromise = Promise.withResolvers();
const calendar = createCalendar("caldav", CalDAVServer.url, true);
await calendarObserver._onAddItemPromise.promise;
await calendarObserver._onLoadPromise.promise;
@ -184,7 +184,7 @@ add_task(async function testSyncError2() {
info("forced syncing with multiple pages");
calendar.wrappedJSObject.mUncachedCalendar.wrappedJSObject.mWebdavSyncToken = null;
calendar.wrappedJSObject.mUncachedCalendar.wrappedJSObject.saveCalendarProperties();
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
calendar.refresh();
await calendarObserver._onLoadPromise.promise;
info("forced sync with multiple pages complete");

Просмотреть файл

@ -23,8 +23,8 @@ add_setup(async function () {
registerCleanupFunction(() => CalDAVServer.close());
add_task(async function () {
calendarObserver._onAddItemPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onAddItemPromise = Promise.withResolvers();
calendarObserver._onLoadPromise = Promise.withResolvers();
const calendar = createCalendar("caldav", CalDAVServer.url, false);
await calendarObserver._onAddItemPromise.promise;
await calendarObserver._onLoadPromise.promise;
@ -34,12 +34,12 @@ add_task(async function () {
info("creating the item");
calendarObserver._batchRequired = true;
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runAddItem(calendar);
await calendarObserver._onLoadPromise.promise;
info("modifying the item");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runModifyItem(calendar);
await calendarObserver._onLoadPromise.promise;
@ -55,7 +55,7 @@ add_task(async function () {
*/
add_task(async function testCalendarWithNoPrivSupport() {
CalDAVServer.privileges = null;
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
const calendar = createCalendar("caldav", CalDAVServer.url, false);
await calendarObserver._onLoadPromise.promise;

Просмотреть файл

@ -27,8 +27,8 @@ add_task(async function () {
// Remove the next line when this is fixed.
calendarObserver._batchRequired = false;
calendarObserver._onAddItemPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onAddItemPromise = Promise.withResolvers();
calendarObserver._onLoadPromise = Promise.withResolvers();
const calendar = createCalendar("ics", ICSServer.url, true);
await calendarObserver._onAddItemPromise.promise;
await calendarObserver._onLoadPromise.promise;
@ -37,17 +37,17 @@ add_task(async function () {
Assert.ok(await calendar.getItem("5a9fa76c-93f3-4ad8-9f00-9e52aedd2821"));
info("creating the item");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runAddItem(calendar);
await calendarObserver._onLoadPromise.promise;
info("modifying the item");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runModifyItem(calendar);
await calendarObserver._onLoadPromise.promise;
info("deleting the item");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runDeleteItem(calendar);
await calendarObserver._onLoadPromise.promise;
});

Просмотреть файл

@ -20,8 +20,8 @@ ICSServer.putICSInternal(
registerCleanupFunction(() => ICSServer.close());
add_task(async function () {
calendarObserver._onAddItemPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onAddItemPromise = Promise.withResolvers();
calendarObserver._onLoadPromise = Promise.withResolvers();
const calendar = createCalendar("ics", ICSServer.url, false);
await calendarObserver._onAddItemPromise.promise;
await calendarObserver._onLoadPromise.promise;
@ -30,17 +30,17 @@ add_task(async function () {
Assert.ok(await calendar.getItem("5a9fa76c-93f3-4ad8-9f00-9e52aedd2821"));
info("creating the item");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runAddItem(calendar);
await calendarObserver._onLoadPromise.promise;
info("modifying the item");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runModifyItem(calendar);
await calendarObserver._onLoadPromise.promise;
info("deleting the item");
calendarObserver._onLoadPromise = PromiseUtils.defer();
calendarObserver._onLoadPromise = Promise.withResolvers();
await runDeleteItem(calendar);
await calendarObserver._onLoadPromise.promise;
});

Просмотреть файл

@ -84,7 +84,7 @@ const webProgressListener = {
Ci.nsIWebProgress.NOTIFY_STATE_ALL | Ci.nsIWebProgress.NOTIFY_LOCATION
);
this._deferred = PromiseUtils.defer();
this._deferred = Promise.withResolvers();
return this._deferred.promise;
},
@ -114,7 +114,7 @@ const mockExternalProtocolService = {
},
promiseEvent() {
this._deferred = PromiseUtils.defer();
this._deferred = Promise.withResolvers();
return this._deferred.promise;
},

Просмотреть файл

@ -501,7 +501,7 @@ const mockExternalProtocolService = {
},
promiseEvent() {
this._deferred = PromiseUtils.defer();
this._deferred = Promise.withResolvers();
return this._deferred.promise;
},

Просмотреть файл

@ -102,7 +102,7 @@ class MockAlertsService {
QueryInterface = ChromeUtils.generateQI(["nsIAlertsService"]);
constructor() {
this._deferredPromise = PromiseUtils.defer();
this._deferredPromise = Promise.withResolvers();
}
showAlert() {
@ -110,7 +110,7 @@ class MockAlertsService {
}
deferPromise() {
this._deferredPromise = PromiseUtils.defer();
this._deferredPromise = Promise.withResolvers();
}
get promise() {

Просмотреть файл

@ -79,7 +79,7 @@ add_task(async function testCreateCard() {
// Saving the contact will get an immediate notification.
// Delay the server response so we can test the state of the UI.
const promise1 = TestUtils.topicObserved("addrbook-contact-created");
CardDAVServer.responseDelay = PromiseUtils.defer();
CardDAVServer.responseDelay = Promise.withResolvers();
EventUtils.synthesizeMouseAtCenter(saveEditButton, {}, abWindow);
await promise1;
await notInEditingMode();
@ -105,7 +105,7 @@ add_task(async function testCreateCard() {
// Saving the contact will get an immediate notification.
// Delay the server response so we can test the state of the UI.
const promise3 = TestUtils.topicObserved("addrbook-contact-updated");
CardDAVServer.responseDelay = PromiseUtils.defer();
CardDAVServer.responseDelay = Promise.withResolvers();
EventUtils.synthesizeMouseAtCenter(saveEditButton, {}, abWindow);
await promise3;
await notInEditingMode();
@ -129,7 +129,7 @@ add_task(async function testCreateCard() {
// Saving the contact will get an immediate notification.
// Delay the server response so we can test the state of the UI.
const promise5 = TestUtils.topicObserved("addrbook-contact-deleted");
CardDAVServer.responseDelay = PromiseUtils.defer();
CardDAVServer.responseDelay = Promise.withResolvers();
BrowserTestUtils.promiseAlertDialog("accept");
EventUtils.synthesizeMouseAtCenter(deleteButton, {}, abWindow);
await promise5;
@ -178,7 +178,7 @@ add_task(async function testCreateCardWithUIDChange() {
// Saving the contact will get an immediate notification.
// Delay the server response so we can test the state of the UI.
const promise1 = TestUtils.topicObserved("addrbook-contact-created");
CardDAVServer.responseDelay = PromiseUtils.defer();
CardDAVServer.responseDelay = Promise.withResolvers();
EventUtils.synthesizeMouseAtCenter(saveEditButton, {}, abWindow);
await promise1;
await notInEditingMode();
@ -219,7 +219,7 @@ add_task(async function testCreateCardWithUIDChange() {
// Saving the contact will get an immediate notification.
// Delay the server response so we can test the state of the UI.
const promise4 = TestUtils.topicObserved("addrbook-contact-deleted");
CardDAVServer.responseDelay = PromiseUtils.defer();
CardDAVServer.responseDelay = Promise.withResolvers();
BrowserTestUtils.promiseAlertDialog("accept");
EventUtils.synthesizeMouseAtCenter(deleteButton, {}, abWindow);
await promise4;

Просмотреть файл

@ -354,7 +354,7 @@ var gBrowserInit = {
const initiallyFocusedElement = document.commandDispatcher.focusedElement;
const promise = gBrowser.selectedBrowser.isRemoteBrowser
? PromiseUtils.defer().promise
? Promise.withResolvers().promise
: Promise.resolve();
contentProgress.addListener({

Просмотреть файл

@ -70,7 +70,7 @@ const tabListener = {
awaitTabReady(nativeTabInfo) {
let deferred = this.tabReadyPromises.get(nativeTabInfo);
if (!deferred) {
deferred = PromiseUtils.defer();
deferred = Promise.withResolvers();
const browser = getTabBrowser(nativeTabInfo);
if (
!this.initializingTabs.has(nativeTabInfo) &&

Просмотреть файл

@ -6,10 +6,6 @@
var EXPORTED_SYMBOLS = ["PopupNotifications"];
const { PromiseUtils } = ChromeUtils.importESModule(
"resource://gre/modules/PromiseUtils.sys.mjs"
);
const NOTIFICATION_EVENT_DISMISSED = "dismissed";
const NOTIFICATION_EVENT_REMOVED = "removed";
const NOTIFICATION_EVENT_SHOWING = "showing";
@ -638,7 +634,7 @@ PopupNotifications.prototype = {
if (this._ignoreDismissal) {
return this._ignoreDismissal.promise;
}
const deferred = PromiseUtils.defer();
const deferred = Promise.withResolvers();
this._ignoreDismissal = deferred;
this.panel.hidePopup();
return deferred.promise;

Просмотреть файл

@ -50,12 +50,12 @@ var gDBView;
var gTreeView;
var CommandUpdaterWithPromise = function () {
this.deferred = PromiseUtils.defer();
this.deferred = Promise.withResolvers();
};
CommandUpdaterWithPromise.prototype = {
async promiseSelectionSummarized() {
await this.deferred.promise;
this.deferred = PromiseUtils.defer();
this.deferred = Promise.withResolvers();
return this.deferred.promise;
},

Просмотреть файл

@ -209,7 +209,7 @@ add_task(async function testBccWithSendLater() {
);
await promise;
const onStopSendingPromise = PromiseUtils.defer();
const onStopSendingPromise = Promise.withResolvers();
const msgSendLater = Cc[
"@mozilla.org/messengercompose/sendlater;1"
].getService(Ci.nsIMsgSendLater);
@ -299,7 +299,7 @@ add_task(async function testBccOnlyWithSendLater() {
);
await promise;
const onStopSendingPromise = PromiseUtils.defer();
const onStopSendingPromise = Promise.withResolvers();
const msgSendLater = Cc[
"@mozilla.org/messengercompose/sendlater;1"
].getService(Ci.nsIMsgSendLater);

Просмотреть файл

@ -47,7 +47,7 @@ var msgSendLater = Cc["@mozilla.org/messengercompose/sendlater;1"].getService(
);
var messageListener;
var onStopCopyPromise = PromiseUtils.defer();
var onStopCopyPromise = Promise.withResolvers();
/* exported OnStopCopy */
// for head_compose.js
@ -184,7 +184,7 @@ async function sendMessageLater(aTestFileIndex) {
);
await onStopCopyPromise.promise;
// Reset onStopCopyPromise.
onStopCopyPromise = PromiseUtils.defer();
onStopCopyPromise = Promise.withResolvers();
}
function resetCounts() {
@ -214,7 +214,7 @@ async function sendUnsentMessages() {
// sequence and ensures the data is correct.
class MsgSendLaterListener {
constructor() {
this._deferredPromise = PromiseUtils.defer();
this._deferredPromise = Promise.withResolvers();
}
checkMessageSend(aCurrentMessage) {
@ -292,7 +292,7 @@ class MsgSendLaterListener {
}
deferPromise() {
this._deferredPromise = PromiseUtils.defer();
this._deferredPromise = Promise.withResolvers();
}
get promise() {

Просмотреть файл

@ -44,7 +44,7 @@ const contents = "Sundays are nothing without callaloo.";
*/
const headerSink = {
expectResults(maxLen) {
this._deferred = PromiseUtils.defer();
this._deferred = Promise.withResolvers();
this.expectedCount = maxLen;
this.countReceived = 0;
this.results = [];

Просмотреть файл

@ -81,7 +81,7 @@ var smimeDataDirectory = "../../../data/smime/";
const smimeHeaderSink = {
expectResults(maxLen) {
// dump("Restarting for next test\n");
this._deferred = PromiseUtils.defer();
this._deferred = Promise.withResolvers();
this._expectedEvents = maxLen;
this.countReceived = 0;
this._results = [];
@ -605,7 +605,7 @@ var gMessages = [
},
];
const gCopyWaiter = PromiseUtils.defer();
const gCopyWaiter = Promise.withResolvers();
add_task(async function copy_messages() {
for (const msg of gMessages) {

Просмотреть файл

@ -101,7 +101,7 @@ var smimeDataDirectory = "../../../data/smime/";
const smimeHeaderSink = {
expectResults(maxLen) {
// dump("Restarting for next test\n");
this._deferred = PromiseUtils.defer();
this._deferred = Promise.withResolvers();
this._expectedEvents = maxLen;
this.countReceived = 0;
this._results = [];
@ -621,7 +621,7 @@ var gMessages = [
},
];
const gCopyWaiter = PromiseUtils.defer();
const gCopyWaiter = Promise.withResolvers();
add_task(async function copy_messages() {
for (const msg of gMessages) {

Просмотреть файл

@ -88,7 +88,7 @@ var smimeDataDirectory = "../../../data/smime/";
const smimeHeaderSink = {
expectResults(maxLen) {
// dump("Restarting for next test\n");
this._deferred = PromiseUtils.defer();
this._deferred = Promise.withResolvers();
this._expectedEvents = maxLen;
this.countReceived = 0;
this._results = [];

Просмотреть файл

@ -167,7 +167,7 @@ add_task(async function test_search() {
add_task(async function test_grouplist() {
// This tests nsNntpService::GetListOfGroupsOnServer.
const subserver = localserver.QueryInterface(Ci.nsISubscribableServer);
const subscribablePromise = PromiseUtils.defer();
const subscribablePromise = Promise.withResolvers();
const subscribeListener = {
OnDonePopulating() {
subscribablePromise.resolve();
@ -271,7 +271,7 @@ class DummyMsgWindow {
]);
constructor() {
this._deferredPromise = PromiseUtils.defer();
this._deferredPromise = Promise.withResolvers();
}
get statusFeedback() {
@ -290,7 +290,7 @@ class DummyMsgWindow {
}
deferPromise() {
this._deferredPromise = PromiseUtils.defer();
this._deferredPromise = Promise.withResolvers();
}
get promise() {