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

Avoid dispatching an event in pdfjsSandbox when destruction has run #18293

Closed
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
40 changes: 23 additions & 17 deletions web/generic_scripting.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,39 @@ async function docProperties(pdfDocument) {
}

class GenericScripting {
#readyCapability = Promise.withResolvers();

#sandbox = null;

constructor(sandboxBundleSrc) {
this._ready = new Promise((resolve, reject) => {
const sandbox =
typeof PDFJSDev === "undefined"
? import(sandboxBundleSrc) // eslint-disable-line no-unsanitized/method
: __non_webpack_import__(sandboxBundleSrc);
sandbox
.then(pdfjsSandbox => {
resolve(pdfjsSandbox.QuickJSSandbox());
})
.catch(reject);
});
const sandbox =
typeof PDFJSDev === "undefined"
? import(sandboxBundleSrc) // eslint-disable-line no-unsanitized/method
: __non_webpack_import__(sandboxBundleSrc);
sandbox
.then(async pdfjsSandbox => {
this.#sandbox = await pdfjsSandbox.QuickJSSandbox();
this.#readyCapability.resolve();
})
.catch(this.#readyCapability.reject);
}

async createSandbox(data) {
const sandbox = await this._ready;
sandbox.create(data);
await this.#readyCapability.promise;
this.#sandbox?.create(data);
}

async dispatchEventInSandbox(event) {
const sandbox = await this._ready;
setTimeout(() => sandbox.dispatchEvent(event), 0);
await this.#readyCapability.promise;
if (this.#sandbox) {
setTimeout(() => this.#sandbox?.dispatchEvent(event), 0);
}
}

async destroySandbox() {
const sandbox = await this._ready;
sandbox.nukeSandbox();
await this.#readyCapability.promise;
this.#sandbox?.nukeSandbox();
this.#sandbox = null;
}
}

Expand Down