Fix the exception propagation when rejecting workerReadyCapability

Currently when an exception is thrown, we try to reject `workerReadyCapability` with multiple arguments in src/core/api.js. This obviously doesn't work, hence this patch changes that to instead reject with the exception object as is.
In src/core/worker.js the exception is currently (unncessarily) wrapped in an object, so this patch also simplifies that to directly send the exception object instead.
This commit is contained in:
Jonas Jenwald 2014-08-23 16:03:49 +02:00
parent b3be74d81c
commit ca027ebfdb
3 changed files with 40 additions and 40 deletions

View file

@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals CanvasGraphics, combineUrl, createScratchCanvas, error,
FontLoader, globalScope, info, isArrayBuffer, loadJpegStream,
MessageHandler, PDFJS, Promise, StatTimer, warn,
PasswordResponses, Util, loadScript, createPromiseCapability,
FontFace */
/* globals PDFJS, isArrayBuffer, error, combineUrl, createPromiseCapability,
StatTimer, globalScope, MessageHandler, info, FontLoader, Util, warn,
PasswordResponses, PasswordException, InvalidPDFException,
MissingPDFException, UnknownErrorException, FontFace, loadJpegStream,
createScratchCanvas, Promise, CanvasGraphics */
'use strict';
@ -865,36 +865,40 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.workerReadyCapability.resolve(pdfDocument);
}, this);
messageHandler.on('NeedPassword', function transportPassword(data) {
messageHandler.on('NeedPassword',
function transportNeedPassword(exception) {
if (this.passwordCallback) {
return this.passwordCallback(updatePassword,
PasswordResponses.NEED_PASSWORD);
}
this.workerReadyCapability.reject(data.exception.message,
data.exception);
this.workerReadyCapability.reject(
new PasswordException(exception.message, exception.code));
}, this);
messageHandler.on('IncorrectPassword', function transportBadPass(data) {
messageHandler.on('IncorrectPassword',
function transportIncorrectPassword(exception) {
if (this.passwordCallback) {
return this.passwordCallback(updatePassword,
PasswordResponses.INCORRECT_PASSWORD);
}
this.workerReadyCapability.reject(data.exception.message,
data.exception);
this.workerReadyCapability.reject(
new PasswordException(exception.message, exception.code));
}, this);
messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
this.workerReadyCapability.reject(data.exception.name, data.exception);
messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
this.workerReadyCapability.reject(
new InvalidPDFException(exception.message));
}, this);
messageHandler.on('MissingPDF', function transportMissingPDF(data) {
this.workerReadyCapability.reject(data.exception.message,
data.exception);
messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
this.workerReadyCapability.reject(
new MissingPDFException(exception.message));
}, this);
messageHandler.on('UnknownError', function transportUnknownError(data) {
this.workerReadyCapability.reject(data.exception.message,
data.exception);
messageHandler.on('UnknownError',
function transportUnknownError(exception) {
this.workerReadyCapability.reject(
new UnknownErrorException(exception.message, exception.details));
}, this);
messageHandler.on('DataLoaded', function transportPage(data) {