browser(firefox): fix race between idleTasksFinishedPromise and window closure (#6308)
This commit is contained in:
Родитель
d31107f342
Коммит
10c76ff56f
|
@ -1,2 +1,2 @@
|
|||
1246
|
||||
Changed: lushnikov@chromium.org Tue 20 Apr 2021 10:26:28 AM PDT
|
||||
1247
|
||||
Changed: dgozman@gmail.com Fri Apr 23 15:46:40 PDT 2021
|
||||
|
|
|
@ -138,7 +138,12 @@ class BrowserHandler {
|
|||
"navigator:browser"
|
||||
);
|
||||
if (browserWindow && browserWindow.gBrowserInit) {
|
||||
await browserWindow.gBrowserInit.idleTasksFinishedPromise;
|
||||
// idleTasksFinishedPromise does not resolve when the window
|
||||
// is closed early enough, so we race against window closure.
|
||||
await Promise.race([
|
||||
browserWindow.gBrowserInit.idleTasksFinishedPromise,
|
||||
waitForWindowClosed(browserWindow),
|
||||
]);
|
||||
}
|
||||
// Try to fully initialize browser before closing.
|
||||
// See comment in `Browser.enable`.
|
||||
|
@ -281,6 +286,22 @@ async function waitForAddonManager() {
|
|||
});
|
||||
}
|
||||
|
||||
async function waitForWindowClosed(browserWindow) {
|
||||
if (browserWindow.closed)
|
||||
return;
|
||||
await new Promise((resolve => {
|
||||
const listener = {
|
||||
onCloseWindow: window => {
|
||||
if (window === browserWindow) {
|
||||
Services.wm.removeListener(listener);
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
};
|
||||
Services.wm.addListener(listener);
|
||||
}));
|
||||
}
|
||||
|
||||
function nullToUndefined(value) {
|
||||
return value === null ? undefined : value;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче