1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Ensure that ReadableStreams are cancelled with actual Errors

There's a number of spots in the current code, and tests, where `cancel` methods are not called with appropriate arguments (leading to Promises not being rejected with Errors as intended).
In some cases the cancel `reason` is implicitly set to `undefined`, and in others the cancel `reason` is just a plain String. To address this inconsistency, the patch changes things such that cancelling is done with `AbortException`s everywhere instead.
This commit is contained in:
Jonas Jenwald 2019-08-01 16:31:32 +02:00
parent d909b86b28
commit a3150166ec
8 changed files with 32 additions and 29 deletions

View file

@ -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();