mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Use even more optional chaining in the src/display/api.js
file
This slightly shortens the code, in various `destroy`-methods, which cannot hurt. Also, use pre-processor checks to simplify `PDFDocumentLoadingTask.destroy` in the Firefox PDF Viewer since the `PDFWorker.fromPort`-method isn't used there.
This commit is contained in:
parent
8f08ca2150
commit
4b0900fdfa
1 changed files with 29 additions and 28 deletions
|
@ -655,23 +655,26 @@ class PDFDocumentLoadingTask {
|
|||
*/
|
||||
async destroy() {
|
||||
this.destroyed = true;
|
||||
try {
|
||||
if (this._worker?.port) {
|
||||
this._worker._pendingDestroy = true;
|
||||
}
|
||||
await this._transport?.destroy();
|
||||
} catch (ex) {
|
||||
if (this._worker?.port) {
|
||||
delete this._worker._pendingDestroy;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
this._transport = null;
|
||||
if (this._worker) {
|
||||
this._worker.destroy();
|
||||
this._worker = null;
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||
await this._transport?.destroy();
|
||||
} else {
|
||||
try {
|
||||
if (this._worker?.port) {
|
||||
this._worker._pendingDestroy = true;
|
||||
}
|
||||
await this._transport?.destroy();
|
||||
} catch (ex) {
|
||||
if (this._worker?.port) {
|
||||
delete this._worker._pendingDestroy;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
this._transport = null;
|
||||
|
||||
this._worker?.destroy();
|
||||
this._worker = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2336,17 +2339,16 @@ class PDFWorker {
|
|||
*/
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
if (this._webWorker) {
|
||||
// We need to terminate only web worker created resource.
|
||||
this._webWorker.terminate();
|
||||
this._webWorker = null;
|
||||
}
|
||||
|
||||
// We need to terminate only web worker created resource.
|
||||
this._webWorker?.terminate();
|
||||
this._webWorker = null;
|
||||
|
||||
PDFWorker.#workerPorts?.delete(this._port);
|
||||
this._port = null;
|
||||
if (this._messageHandler) {
|
||||
this._messageHandler.destroy();
|
||||
this._messageHandler = null;
|
||||
}
|
||||
|
||||
this._messageHandler?.destroy();
|
||||
this._messageHandler = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2600,10 +2602,9 @@ class WorkerTransport {
|
|||
new AbortException("Worker was terminated.")
|
||||
);
|
||||
|
||||
if (this.messageHandler) {
|
||||
this.messageHandler.destroy();
|
||||
this.messageHandler = null;
|
||||
}
|
||||
this.messageHandler?.destroy();
|
||||
this.messageHandler = null;
|
||||
|
||||
this.destroyCapability.resolve();
|
||||
}, this.destroyCapability.reject);
|
||||
return this.destroyCapability.promise;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue