Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use even more optional chaining in the src/display/api.js file #19135

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,23 +655,26 @@ class PDFDocumentLoadingTask {
*/
async destroy() {
this.destroyed = true;
try {
if (this._worker?.port) {
this._worker._pendingDestroy = true;
}

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
await this._transport?.destroy();
} catch (ex) {
if (this._worker?.port) {
delete this._worker._pendingDestroy;
} 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;
}
throw ex;
}

this._transport = null;
if (this._worker) {
this._worker.destroy();
this._worker = null;
}

this._worker?.destroy();
this._worker = null;
}
}

Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
Expand Down