mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 07:38:07 +02:00
[api-minor] Reject the RenderTask
with an actual Error
, instead of just a string
, when rendering is cancelled
This patch gets rid of the only case in the code-base where we're throwing a plain `string`, rather than an `Error`, which besides better/more consistent error handling also allows us to enable the [`no-throw-literal`](http://eslint.org/docs/rules/no-throw-literal) ESLint rule.
This commit is contained in:
parent
6d672c4ba6
commit
d37d271afa
7 changed files with 66 additions and 8 deletions
|
@ -17,19 +17,23 @@
|
|||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define('pdfjs-test/unit/api_spec', ['exports', 'pdfjs/shared/util',
|
||||
'pdfjs/display/global', 'pdfjs/display/api'], factory);
|
||||
'pdfjs/display/dom_utils', 'pdfjs/display/global', 'pdfjs/display/api'],
|
||||
factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
factory(exports, require('../../src/shared/util.js'),
|
||||
require('../../src/display/global.js'),
|
||||
require('../../src/display/api.js'));
|
||||
require('../../src/display/dom_utils.js'),
|
||||
require('../../src/display/global.js'),
|
||||
require('../../src/display/api.js'));
|
||||
} else {
|
||||
factory((root.pdfjsTestUnitApiSpec = {}), root.pdfjsSharedUtil,
|
||||
root.pdfjsDisplayGlobal, root.pdfjsDisplayApi);
|
||||
root.pdfjsDisplayDOMUtils, root.pdfjsDisplayGlobal, root.pdfjsDisplayApi);
|
||||
}
|
||||
}(this, function (exports, sharedUtil, displayGlobal, displayApi) {
|
||||
}(this, function (exports, sharedUtil, displayDOMUtils, displayGlobal,
|
||||
displayApi) {
|
||||
|
||||
var PDFJS = displayGlobal.PDFJS;
|
||||
var createPromiseCapability = sharedUtil.createPromiseCapability;
|
||||
var RenderingCancelledException = displayDOMUtils.RenderingCancelledException;
|
||||
var PDFDocumentProxy = displayApi.PDFDocumentProxy;
|
||||
var InvalidPDFException = sharedUtil.InvalidPDFException;
|
||||
var MissingPDFException = sharedUtil.MissingPDFException;
|
||||
|
@ -1000,6 +1004,25 @@ describe('api', function() {
|
|||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
|
||||
it('cancels rendering of page', function(done) {
|
||||
var canvas = document.createElement('canvas');
|
||||
var viewport = page.getViewport(1);
|
||||
|
||||
var renderTask = page.render({
|
||||
canvasContext: canvas.getContext('2d'),
|
||||
viewport: viewport,
|
||||
});
|
||||
renderTask.cancel();
|
||||
|
||||
renderTask.promise.then(function() {
|
||||
done.fail('shall cancel rendering');
|
||||
}).catch(function (error) {
|
||||
expect(error instanceof RenderingCancelledException).toEqual(true);
|
||||
expect(error.type).toEqual('canvas');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Multiple PDFJS instances', function() {
|
||||
// Regression test for https://github.com/mozilla/pdf.js/issues/6205
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue