From 81dfa61777ee52cbae52ff2b609fffc2f8568bed Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 30 Jul 2023 08:34:41 +0200 Subject: [PATCH 1/2] Ensure that failing to open the password dialog once won't permanently disable it (PR 15335 follow-up) *Please note:* This situation should never happen in practice, but it nonetheless cannot hurt to fix this. If the `PasswordPrompt.open` method would ever be called synchronously back-to-back *and* if opening of the dialog fails the first time, then the second invocation would remain pending indefinitely since we just clear out the capability. --- web/password_prompt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/password_prompt.js b/web/password_prompt.js index 01251a1f8..66b17dd56 100644 --- a/web/password_prompt.js +++ b/web/password_prompt.js @@ -74,7 +74,7 @@ class PasswordPrompt { try { await this.overlayManager.open(this.dialog); } catch (ex) { - this.#activeCapability = null; + this.#activeCapability.resolve(); throw ex; } From 930cbc4d27dfbf386004cc99d14491b325f6febb Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 30 Jul 2023 11:45:35 +0200 Subject: [PATCH 2/2] Make the `passwordCapability` field, in `WorkerTransport`, actually private as intended --- src/display/api.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 7fc56fcd9..61a95bef6 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2367,6 +2367,8 @@ class WorkerTransport { #pagePromises = new Map(); + #passwordCapability = null; + constructor(messageHandler, loadingTask, networkStream, params, factory) { this.messageHandler = messageHandler; this.loadingTask = loadingTask; @@ -2384,7 +2386,6 @@ class WorkerTransport { this.destroyed = false; this.destroyCapability = null; - this._passwordCapability = null; this._networkStream = networkStream; this._fullReader = null; @@ -2495,11 +2496,9 @@ class WorkerTransport { this.destroyed = true; this.destroyCapability = new PromiseCapability(); - if (this._passwordCapability) { - this._passwordCapability.reject( - new Error("Worker was destroyed during onPassword callback") - ); - } + this.#passwordCapability?.reject( + new Error("Worker was destroyed during onPassword callback") + ); const waitOn = []; // We need to wait for all renderings to be completed, e.g. @@ -2702,27 +2701,27 @@ class WorkerTransport { }); messageHandler.on("PasswordRequest", exception => { - this._passwordCapability = new PromiseCapability(); + this.#passwordCapability = new PromiseCapability(); if (loadingTask.onPassword) { const updatePassword = password => { if (password instanceof Error) { - this._passwordCapability.reject(password); + this.#passwordCapability.reject(password); } else { - this._passwordCapability.resolve({ password }); + this.#passwordCapability.resolve({ password }); } }; try { loadingTask.onPassword(updatePassword, exception.code); } catch (ex) { - this._passwordCapability.reject(ex); + this.#passwordCapability.reject(ex); } } else { - this._passwordCapability.reject( + this.#passwordCapability.reject( new PasswordException(exception.message, exception.code) ); } - return this._passwordCapability.promise; + return this.#passwordCapability.promise; }); messageHandler.on("DataLoaded", data => {