diff --git a/src/shared/util.js b/src/shared/util.js index e3c3ad2dc..69e1c5317 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -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, diff --git a/web/app.js b/web/app.js index eed21ddef..f619e6396 100644 --- a/web/app.js +++ b/web/app.js @@ -559,11 +559,7 @@ const PDFViewerApplication = { } if (appConfig.annotationEditorParams) { - if ( - ((typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || - typeof AbortSignal.any === "function") && - annotationEditorMode !== AnnotationEditorType.DISABLE - ) { + if (annotationEditorMode !== AnnotationEditorType.DISABLE) { const editorSignatureButton = appConfig.toolbar?.editorSignatureButton; if (editorSignatureButton && AppOptions.get("enableSignatureEditor")) { editorSignatureButton.parentElement.hidden = false; @@ -2075,19 +2071,14 @@ const PDFViewerApplication = { _windowAbortController: { signal }, } = this; - if ( - (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || - typeof AbortSignal.any === "function" - ) { - this._touchManager = new TouchManager({ - container: window, - isPinchingDisabled: () => pdfViewer.isInPresentationMode, - isPinchingStopped: () => this.overlayManager?.active, - onPinching: this.touchPinchCallback.bind(this), - onPinchEnd: this.touchPinchEndCallback.bind(this), - signal, - }); - } + this._touchManager = new TouchManager({ + container: window, + isPinchingDisabled: () => pdfViewer.isInPresentationMode, + isPinchingStopped: () => this.overlayManager?.active, + onPinching: this.touchPinchCallback.bind(this), + onPinchEnd: this.touchPinchEndCallback.bind(this), + signal, + }); function addWindowResolutionChange(evt = null) { if (evt) { diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 9f515ca32..dda604ccc 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -711,13 +711,7 @@ class PDFViewer { hiddenCapability.resolve(); } }, - { - signal: - (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || - typeof AbortSignal.any === "function" - ? AbortSignal.any([signal, ac.signal]) - : signal, - } + { signal: AbortSignal.any([signal, ac.signal]) } ); await Promise.race([ @@ -914,11 +908,7 @@ class PDFViewer { viewer.before(element); } - if ( - ((typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || - typeof AbortSignal.any === "function") && - annotationEditorMode !== AnnotationEditorType.DISABLE - ) { + if (annotationEditorMode !== AnnotationEditorType.DISABLE) { const mode = annotationEditorMode; if (pdfDocument.isPureXfa) {