Skip to content

Commit 9023395

Browse files
Merge pull request #19681 from Snuffleupagus/AbortSignal-any-basic-polyfill
[api-minor] Add a basic `AbortSignal.any` polyfill in PDF.js `legacy` builds
2 parents 7f70835 + 028e4f7 commit 9023395

3 files changed

Lines changed: 42 additions & 30 deletions

File tree

src/shared/util.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,37 @@ if (
11721172
};
11731173
}
11741174

1175+
if (
1176+
typeof PDFJSDev !== "undefined" &&
1177+
!PDFJSDev.test("SKIP_BABEL") &&
1178+
typeof AbortSignal.any !== "function"
1179+
) {
1180+
AbortSignal.any = function (iterable) {
1181+
const ac = new AbortController();
1182+
const { signal } = ac;
1183+
1184+
// Return immediately if any of the signals are already aborted.
1185+
for (const s of iterable) {
1186+
if (s.aborted) {
1187+
ac.abort(s.reason);
1188+
return signal;
1189+
}
1190+
}
1191+
// Register "abort" listeners for all signals.
1192+
for (const s of iterable) {
1193+
s.addEventListener(
1194+
"abort",
1195+
() => {
1196+
ac.abort(s.reason);
1197+
},
1198+
{ signal } // Automatically remove the listener.
1199+
);
1200+
}
1201+
1202+
return signal;
1203+
};
1204+
}
1205+
11751206
export {
11761207
_isValidExplicitDest,
11771208
AbortException,

web/app.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,7 @@ const PDFViewerApplication = {
559559
}
560560

561561
if (appConfig.annotationEditorParams) {
562-
if (
563-
((typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
564-
typeof AbortSignal.any === "function") &&
565-
annotationEditorMode !== AnnotationEditorType.DISABLE
566-
) {
562+
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
567563
const editorSignatureButton = appConfig.toolbar?.editorSignatureButton;
568564
if (editorSignatureButton && AppOptions.get("enableSignatureEditor")) {
569565
editorSignatureButton.parentElement.hidden = false;
@@ -2075,19 +2071,14 @@ const PDFViewerApplication = {
20752071
_windowAbortController: { signal },
20762072
} = this;
20772073

2078-
if (
2079-
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
2080-
typeof AbortSignal.any === "function"
2081-
) {
2082-
this._touchManager = new TouchManager({
2083-
container: window,
2084-
isPinchingDisabled: () => pdfViewer.isInPresentationMode,
2085-
isPinchingStopped: () => this.overlayManager?.active,
2086-
onPinching: this.touchPinchCallback.bind(this),
2087-
onPinchEnd: this.touchPinchEndCallback.bind(this),
2088-
signal,
2089-
});
2090-
}
2074+
this._touchManager = new TouchManager({
2075+
container: window,
2076+
isPinchingDisabled: () => pdfViewer.isInPresentationMode,
2077+
isPinchingStopped: () => this.overlayManager?.active,
2078+
onPinching: this.touchPinchCallback.bind(this),
2079+
onPinchEnd: this.touchPinchEndCallback.bind(this),
2080+
signal,
2081+
});
20912082

20922083
function addWindowResolutionChange(evt = null) {
20932084
if (evt) {

web/pdf_viewer.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -711,13 +711,7 @@ class PDFViewer {
711711
hiddenCapability.resolve();
712712
}
713713
},
714-
{
715-
signal:
716-
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
717-
typeof AbortSignal.any === "function"
718-
? AbortSignal.any([signal, ac.signal])
719-
: signal,
720-
}
714+
{ signal: AbortSignal.any([signal, ac.signal]) }
721715
);
722716

723717
await Promise.race([
@@ -914,11 +908,7 @@ class PDFViewer {
914908
viewer.before(element);
915909
}
916910

917-
if (
918-
((typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
919-
typeof AbortSignal.any === "function") &&
920-
annotationEditorMode !== AnnotationEditorType.DISABLE
921-
) {
911+
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
922912
const mode = annotationEditorMode;
923913

924914
if (pdfDocument.isPureXfa) {

0 commit comments

Comments
 (0)