1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[api-minor] Add a basic AbortSignal.any polyfill in PDF.js legacy builds

This is an admittedly very basic polyfill, to allow us to remove a bunch of inline feature testing, that I've thrown together based on reading https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static and related MDN articles.

Compared to PR 19218 it's obviously much more "primitive", however the implementation is simple and it doesn't suffer from any licensing issues (since I wrote the code myself).
This commit is contained in:
Jonas Jenwald 2025-03-18 10:54:49 +01:00
parent 00e3a4d87a
commit 028e4f7ea8
3 changed files with 42 additions and 30 deletions

View file

@ -1172,6 +1172,37 @@ if (
};
}
if (
typeof PDFJSDev !== "undefined" &&
!PDFJSDev.test("SKIP_BABEL") &&
typeof AbortSignal.any !== "function"
) {
AbortSignal.any = function (iterable) {
const ac = new AbortController();
const { signal } = ac;
// Return immediately if any of the signals are already aborted.
for (const s of iterable) {
if (s.aborted) {
ac.abort(s.reason);
return signal;
}
}
// Register "abort" listeners for all signals.
for (const s of iterable) {
s.addEventListener(
"abort",
() => {
ac.abort(s.reason);
},
{ signal } // Automatically remove the listener.
);
}
return signal;
};
}
export {
_isValidExplicitDest,
AbortException,