mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #11034 from Snuffleupagus/cancel-with-AbortException
Ensure that `ReadableStream`s are cancelled with actual Errors
This commit is contained in:
commit
9c8fe3142a
8 changed files with 32 additions and 29 deletions
|
@ -567,14 +567,13 @@ class ChunkedStreamManager {
|
|||
return Math.floor((end - 1) / this.chunkSize) + 1;
|
||||
}
|
||||
|
||||
abort() {
|
||||
abort(reason) {
|
||||
this.aborted = true;
|
||||
if (this.pdfNetworkStream) {
|
||||
this.pdfNetworkStream.cancelAllRequests('abort');
|
||||
this.pdfNetworkStream.cancelAllRequests(reason);
|
||||
}
|
||||
for (const requestId in this.promisesByRequest) {
|
||||
this.promisesByRequest[requestId].reject(
|
||||
new Error('Request was aborted'));
|
||||
this.promisesByRequest[requestId].reject(reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ class BasePdfManager {
|
|||
this._password = password;
|
||||
}
|
||||
|
||||
terminate() {
|
||||
terminate(reason) {
|
||||
unreachable('Abstract method `terminate` called');
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ class LocalPdfManager extends BasePdfManager {
|
|||
return this._loadedStreamPromise;
|
||||
}
|
||||
|
||||
terminate() {}
|
||||
terminate(reason) {}
|
||||
}
|
||||
|
||||
class NetworkPdfManager extends BasePdfManager {
|
||||
|
@ -188,8 +188,8 @@ class NetworkPdfManager extends BasePdfManager {
|
|||
return this.streamManager.onLoadedStream();
|
||||
}
|
||||
|
||||
terminate() {
|
||||
this.streamManager.abort();
|
||||
terminate(reason) {
|
||||
this.streamManager.abort(reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
arrayByteLength, arraysToBytes, createPromiseCapability, getVerbosityLevel,
|
||||
info, InvalidPDFException, MissingPDFException, PasswordException,
|
||||
setVerbosityLevel, UnexpectedResponseException, UnknownErrorException,
|
||||
UNSUPPORTED_FEATURES, VerbosityLevel, warn
|
||||
AbortException, arrayByteLength, arraysToBytes, createPromiseCapability,
|
||||
getVerbosityLevel, info, InvalidPDFException, MissingPDFException,
|
||||
PasswordException, setVerbosityLevel, UnexpectedResponseException,
|
||||
UnknownErrorException, UNSUPPORTED_FEATURES, VerbosityLevel, warn
|
||||
} from '../shared/util';
|
||||
import { clearPrimitiveCaches, Ref } from './primitives';
|
||||
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
||||
|
@ -274,8 +274,8 @@ var WorkerMessageHandler = {
|
|||
cancelXHRs = null;
|
||||
});
|
||||
|
||||
cancelXHRs = function () {
|
||||
pdfStream.cancelAllRequests('abort');
|
||||
cancelXHRs = function(reason) {
|
||||
pdfStream.cancelAllRequests(reason);
|
||||
};
|
||||
|
||||
return pdfManagerCapability.promise;
|
||||
|
@ -349,7 +349,7 @@ var WorkerMessageHandler = {
|
|||
if (terminated) {
|
||||
// We were in a process of setting up the manager, but it got
|
||||
// terminated in the middle.
|
||||
newPdfManager.terminate();
|
||||
newPdfManager.terminate(new AbortException('Worker was terminated.'));
|
||||
throw new Error('Worker was terminated');
|
||||
}
|
||||
pdfManager = newPdfManager;
|
||||
|
@ -579,11 +579,11 @@ var WorkerMessageHandler = {
|
|||
handler.on('Terminate', function wphTerminate(data) {
|
||||
terminated = true;
|
||||
if (pdfManager) {
|
||||
pdfManager.terminate();
|
||||
pdfManager.terminate(new AbortException('Worker was terminated.'));
|
||||
pdfManager = null;
|
||||
}
|
||||
if (cancelXHRs) {
|
||||
cancelXHRs();
|
||||
cancelXHRs(new AbortException('Worker was terminated.'));
|
||||
}
|
||||
clearPrimitiveCaches();
|
||||
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
/* eslint no-var: error */
|
||||
|
||||
import {
|
||||
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
||||
isArrayBuffer, isSameOrigin, MissingPDFException, NativeImageDecoding,
|
||||
PasswordException, setVerbosityLevel, shadow, stringToBytes,
|
||||
UnexpectedResponseException, UnknownErrorException, unreachable, URL, warn
|
||||
AbortException, assert, createPromiseCapability, getVerbosityLevel, info,
|
||||
InvalidPDFException, isArrayBuffer, isSameOrigin, MissingPDFException,
|
||||
NativeImageDecoding, PasswordException, setVerbosityLevel, shadow,
|
||||
stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
||||
unreachable, URL, warn
|
||||
} from '../shared/util';
|
||||
import {
|
||||
deprecated, DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer,
|
||||
|
@ -1768,7 +1769,8 @@ class WorkerTransport {
|
|||
Promise.all(waitOn).then(() => {
|
||||
this.fontLoader.clear();
|
||||
if (this._networkStream) {
|
||||
this._networkStream.cancelAllRequests();
|
||||
this._networkStream.cancelAllRequests(
|
||||
new AbortException('Worker was terminated.'));
|
||||
}
|
||||
|
||||
if (this.messageHandler) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue