Bug 1971512 - [remote] Replace usage of "TimedPromise" with a simple timer in AnimationFramePromise. a=dmeehan DONTBUILD

Original Revision: https://phabricator.services.mozilla.com/D253321

Differential Revision: https://phabricator.services.mozilla.com/D253619
This commit is contained in:
Henrik Skupin
2025-06-13 12:06:15 +00:00
committed by dmeehan@mozilla.com
parent 03164470dd
commit 7af5bc0ba2

View File

@@ -7,6 +7,9 @@ import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
const lazy = {}; const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, { ChromeUtils.defineESModuleGetters(lazy, {
clearTimeout: "resource://gre/modules/Timer.sys.mjs",
setTimeout: "resource://gre/modules/Timer.sys.mjs",
error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs", error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
Log: "chrome://remote/content/shared/Log.sys.mjs", Log: "chrome://remote/content/shared/Log.sys.mjs",
}); });
@@ -53,21 +56,30 @@ export function AnimationFramePromise(win, options = {}) {
} }
} }
const request = resolve => { const animationFramePromise = new Promise(resolve => {
executeSoon(() => { executeSoon(() => {
win.requestAnimationFrame(resolve); win.requestAnimationFrame(resolve);
}); });
}; });
const animationFramePromise = const promises = [
timeout !== null animationFramePromise,
? new TimedPromise(request, { throws: null, timeout }) new EventPromise(win, "pagehide"), // window closed or moved to BFCache
: new Promise(request); ];
// Abort if the underlying window is no longer active (closed, BFCache) let timer;
const unloadPromise = new EventPromise(win, "pagehide"); if (timeout != null) {
promises.push(
new Promise(resolve => {
timer = lazy.setTimeout(() => {
lazy.logger.warn("Timed out waiting for animation frame");
resolve();
}, timeout);
})
);
}
return Promise.race([animationFramePromise, unloadPromise]); return Promise.race(promises).then(() => lazy.clearTimeout(timer));
} }
/** /**