1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Added Promise.catch

Fixed Promise so it rejects on uncaught exception
Catch possible rejection on ViewHistory.setMultiple
This commit is contained in:
Samuel Chantaraud 2014-05-22 13:53:19 -04:00
parent d2da73b8c4
commit 37c3641fad
3 changed files with 19 additions and 4 deletions

View file

@ -1011,7 +1011,7 @@ PDFJS.createPromiseCapability = createPromiseCapability;
/**
* Polyfill for Promises:
* The following promise implementation tries to generally implment the
* The following promise implementation tries to generally implement the
* Promise/A+ spec. Some notable differences from other promise libaries are:
* - There currently isn't a seperate deferred and promise object.
* - Unhandled rejections eventually show an error if they aren't handled.
@ -1057,6 +1057,11 @@ PDFJS.createPromiseCapability = createPromiseCapability;
});
};
}
if (typeof globalScope.Promise.prototype.catch !== 'function') {
globalScope.Promise.prototype.catch = function (onReject) {
return globalScope.Promise.prototype.then(undefined, onReject);
};
}
return;
}
//#if !MOZCENTRAL
@ -1180,7 +1185,11 @@ PDFJS.createPromiseCapability = createPromiseCapability;
function Promise(resolver) {
this._status = STATUS_PENDING;
this._handlers = [];
resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
try {
resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
} catch (e) {
this._reject(e);
}
}
/**
* Builds a promise that is resolved when all the passed in promises are
@ -1307,6 +1316,10 @@ PDFJS.createPromiseCapability = createPromiseCapability;
});
HandlerManager.scheduleHandlers(this);
return nextPromise;
},
catch: function Promise_catch(onReject) {
return this.then(undefined, onReject);
}
};