mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Ensure that ReadableStream
s 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:
parent
d909b86b28
commit
a3150166ec
8 changed files with 32 additions and 29 deletions
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
/* eslint no-var: error */
|
||||
|
||||
import { AbortException } from '../../src/shared/util';
|
||||
import { PDFFetchStream } from '../../src/display/fetch_stream';
|
||||
|
||||
describe('fetch_stream', function() {
|
||||
|
@ -72,7 +73,7 @@ describe('fetch_stream', function() {
|
|||
isStreamingSupported = fullReader.isStreamingSupported;
|
||||
isRangeSupported = fullReader.isRangeSupported;
|
||||
// We shall be able to close full reader without any issue.
|
||||
fullReader.cancel(new Error('Don\'t need full reader'));
|
||||
fullReader.cancel(new AbortException('Don\'t need fullReader.'));
|
||||
fullReaderCancelled = true;
|
||||
});
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createPromiseCapability } from '../../src/shared/util';
|
||||
import { AbortException, createPromiseCapability } from '../../src/shared/util';
|
||||
import { LoopbackPort } from '../../src/display/api';
|
||||
import { MessageHandler } from '../../src/shared/message_handler';
|
||||
|
||||
|
@ -124,7 +124,7 @@ describe('message_handler', function () {
|
|||
return sleep(10);
|
||||
}).then(() => {
|
||||
expect(log).toEqual('01p2');
|
||||
return reader.cancel();
|
||||
return reader.cancel(new AbortException('reader cancelled.'));
|
||||
}).then(() => {
|
||||
expect(log).toEqual('01p2c4');
|
||||
done();
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AbortException } from '../../src/shared/util';
|
||||
import { PDFNetworkStream } from '../../src/display/network';
|
||||
|
||||
describe('network', function() {
|
||||
|
@ -79,7 +80,7 @@ describe('network', function() {
|
|||
isStreamingSupported = fullReader.isStreamingSupported;
|
||||
isRangeSupported = fullReader.isRangeSupported;
|
||||
// we shall be able to close the full reader without issues
|
||||
fullReader.cancel('Don\'t need full reader');
|
||||
fullReader.cancel(new AbortException('Don\'t need fullReader.'));
|
||||
fullReaderCancelled = true;
|
||||
});
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
/* globals __non_webpack_require__ */
|
||||
|
||||
import { assert } from '../../src/shared/util';
|
||||
import { AbortException, assert } from '../../src/shared/util';
|
||||
import isNodeJS from '../../src/shared/is_node';
|
||||
import { PDFNodeStream } from '../../src/display/node_stream';
|
||||
|
||||
|
@ -167,14 +167,14 @@ describe('node_stream', function() {
|
|||
isStreamingSupported1 = fullReader1.isStreamingSupported;
|
||||
isRangeSupported1 = fullReader1.isRangeSupported;
|
||||
// we shall be able to close the full reader without issues
|
||||
fullReader1.cancel('Don\'t need full reader');
|
||||
fullReader1.cancel(new AbortException('Don\'t need fullReader1.'));
|
||||
fullReaderCancelled1 = true;
|
||||
});
|
||||
|
||||
let promise2 = fullReader2.headersReady.then(function () {
|
||||
isStreamingSupported2 = fullReader2.isStreamingSupported;
|
||||
isRangeSupported2 = fullReader2.isRangeSupported;
|
||||
fullReader2.cancel('Don\'t need full reader');
|
||||
fullReader2.cancel(new AbortException('Don\'t need fullReader2.'));
|
||||
fullReaderCancelled2 = true;
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue