From ec7746350d4bea66c342df2af41a213e4bd0287c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 9 Aug 2023 17:03:25 +0200 Subject: [PATCH] Introduce even more optional chaining in the code-base This replaces a few more small/simple if-statements with optional chaining. --- src/core/chunked_stream.js | 5 ++--- src/display/api.js | 8 +++----- src/display/editor/tools.js | 6 ++---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 014b50bbc..635474953 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -546,9 +546,8 @@ class ChunkedStreamManager { abort(reason) { this.aborted = true; - if (this.pdfNetworkStream) { - this.pdfNetworkStream.cancelAllRequests(reason); - } + this.pdfNetworkStream?.cancelAllRequests(reason); + for (const capability of this._promisesByRequest.values()) { capability.reject(reason); } diff --git a/src/display/api.js b/src/display/api.js index c982062c7..dcbbe2fa7 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2533,11 +2533,9 @@ class WorkerTransport { this.#methodPromises.clear(); this.filterFactory.destroy(); - if (this._networkStream) { - this._networkStream.cancelAllRequests( - new AbortException("Worker was terminated.") - ); - } + this._networkStream?.cancelAllRequests( + new AbortException("Worker was terminated.") + ); if (this.messageHandler) { this.messageHandler.destroy(); diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index 637d0645a..ede98728b 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -878,10 +878,8 @@ class AnnotationEditorUIManager { copy(event) { event.preventDefault(); - if (this.#activeEditor) { - // An editor is being edited so just commit it. - this.#activeEditor.commitOrRemove(); - } + // An editor is being edited so just commit it. + this.#activeEditor?.commitOrRemove(); if (!this.hasSelection) { return;