mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Ensure that the WorkerTransport._passwordCapability
is always rejected, even when errors are thrown in PDFDocumentLoadingTask.onPassword
callback
Please note that while the current code works, both in the viewer and the unit-tests, it can leave the `WorkerTransport._passwordCapability` Promise in a pending state. In the `PasswordRequest` handler, in src/display/api.js, we're returning the Promise from a `capability` object (rather than just a "plain" Promise). While an error thrown anywhere within this handler was fortunately enough to propagate it to the Worker side, it won't cause the Promise (in `WorkerTransport._passwordCapability`) to actually be rejected. Finally note that while we're now catching errors in the `PasswordRequest` handler, those errors are still propagated to the Worker side via the (now) rejected Promise and the existing `return this._passwordCapability.promise;` line. This prevents warnings about uncaught Promises, with messages such as "Error: Worker was destroyed during onPassword callback", when running the unit-tests both in browsers *and* in Node.js/Travis.
This commit is contained in:
parent
0ecc22cb04
commit
ef081a0531
2 changed files with 7 additions and 3 deletions
|
@ -1788,7 +1788,11 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
password,
|
||||
});
|
||||
};
|
||||
loadingTask.onPassword(updatePassword, exception.code);
|
||||
try {
|
||||
loadingTask.onPassword(updatePassword, exception.code);
|
||||
} catch (ex) {
|
||||
this._passwordCapability.reject(ex);
|
||||
}
|
||||
} else {
|
||||
this._passwordCapability.reject(
|
||||
new PasswordException(exception.message, exception.code));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue