mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
In display/api.js
ensure that we always reject with an Error
in JpegDecode
, and adjust a couple of other rejection sites as well
In the case where the document was destroyed, we were rejecting the `Promise` in `JpegDecode` with a string instead of an `Error`. The patch also brings the wording more inline with other such rejections. Use the `isInt` utility function when validating the `pageNumber` parameter in `WorkerTransport_getPage`, to make it more obvious what's actually happening. There's also a couple more unit-tests added, to ensure that we always fail in the expected way. Finally, we can simplify the rejection handling in `WorkerTransport_getPageIndexByRef` somewhat. (Note that the only reason for using `catch` here is that since the promise is rejected on the worker side, the `reason` becomes a string instead of an `Error` which is why we "re-reject" on the display side.)
This commit is contained in:
parent
38c85039d1
commit
37998076c9
2 changed files with 35 additions and 17 deletions
|
@ -49,6 +49,7 @@ var error = sharedUtil.error;
|
|||
var deprecated = sharedUtil.deprecated;
|
||||
var getVerbosityLevel = sharedUtil.getVerbosityLevel;
|
||||
var info = sharedUtil.info;
|
||||
var isInt = sharedUtil.isInt;
|
||||
var isArrayBuffer = sharedUtil.isArrayBuffer;
|
||||
var isSameOrigin = sharedUtil.isSameOrigin;
|
||||
var loadJpegStream = sharedUtil.loadJpegStream;
|
||||
|
@ -1612,7 +1613,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
|
||||
messageHandler.on('JpegDecode', function(data) {
|
||||
if (this.destroyed) {
|
||||
return Promise.reject('Worker was terminated');
|
||||
return Promise.reject(new Error('Worker was destroyed'));
|
||||
}
|
||||
|
||||
var imageUrl = data[0];
|
||||
|
@ -1662,8 +1663,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
},
|
||||
|
||||
getPage: function WorkerTransport_getPage(pageNumber, capability) {
|
||||
if (pageNumber <= 0 || pageNumber > this.numPages ||
|
||||
(pageNumber|0) !== pageNumber) {
|
||||
if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
|
||||
return Promise.reject(new Error('Invalid page request'));
|
||||
}
|
||||
|
||||
|
@ -1686,12 +1686,11 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
},
|
||||
|
||||
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
|
||||
return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).
|
||||
then(function (pageIndex) {
|
||||
return pageIndex;
|
||||
}, function (reason) {
|
||||
return Promise.reject(new Error(reason));
|
||||
});
|
||||
return this.messageHandler.sendWithPromise('GetPageIndex', {
|
||||
ref: ref,
|
||||
}).catch(function (reason) {
|
||||
return Promise.reject(new Error(reason));
|
||||
});
|
||||
},
|
||||
|
||||
getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue