mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-28 23:28:16 +02:00
[api-minor] Re-factor how the useWorkerFetch
option is used internally
With the recently added OpenJPEG no-wasm fallback we need to send the `wasmUrl` option to the worker-thread *regardless* of the value of the `useWorkerFetch` option, since the fallback won't work if we don't have a URL to `import` it from. For consistency the code is re-factored to always send the factory-urls to the worker-thread, and simply check the `useWorkerFetch` option there instead. Also, as a follow-up to PR 19525, introduce a new `useWasm` option that can be used in e.g. browser-tests to forcibly disable WebAssembly usage.
This commit is contained in:
parent
6d3bb47655
commit
641e2f506e
5 changed files with 29 additions and 20 deletions
|
@ -31,24 +31,26 @@ class JpxImage {
|
|||
|
||||
static #modulePromise = null;
|
||||
|
||||
static #hasJSFallback = false;
|
||||
static #useWasm = true;
|
||||
|
||||
static #useWorkerFetch = true;
|
||||
|
||||
static #wasmUrl = null;
|
||||
|
||||
static setOptions({ handler, wasmUrl }) {
|
||||
if (this.#buffer || this.#hasJSFallback || this.#modulePromise) {
|
||||
static setOptions({ handler, useWasm, useWorkerFetch, wasmUrl }) {
|
||||
if (this.#buffer || this.#modulePromise) {
|
||||
return;
|
||||
}
|
||||
this.#wasmUrl = wasmUrl || null;
|
||||
if (wasmUrl === null) {
|
||||
this.#useWasm = useWasm;
|
||||
this.#useWorkerFetch = useWorkerFetch;
|
||||
this.#wasmUrl = wasmUrl;
|
||||
|
||||
if (!useWorkerFetch) {
|
||||
this.#handler = handler;
|
||||
}
|
||||
}
|
||||
|
||||
static async #getJsModule(fallbackCallback) {
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
|
||||
this.#wasmUrl ??= "/build/generic/web/wasm/";
|
||||
}
|
||||
const path =
|
||||
typeof PDFJSDev === "undefined"
|
||||
? `../${this.#wasmUrl}openjpeg_nowasm_fallback.js`
|
||||
|
@ -63,8 +65,6 @@ class JpxImage {
|
|||
} catch (e) {
|
||||
warn(`JpxImage#getJsModule: ${e}`);
|
||||
}
|
||||
|
||||
this.#hasJSFallback = true;
|
||||
fallbackCallback(instance);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ class JpxImage {
|
|||
const filename = "openjpeg.wasm";
|
||||
try {
|
||||
if (!this.#buffer) {
|
||||
if (this.#wasmUrl !== null) {
|
||||
if (this.#useWorkerFetch) {
|
||||
this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`);
|
||||
} else {
|
||||
this.#buffer = await this.#handler.sendWithPromise(
|
||||
|
@ -100,7 +100,7 @@ class JpxImage {
|
|||
if (!this.#modulePromise) {
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
const promises = [promise];
|
||||
if (this.#hasJSFallback) {
|
||||
if (!this.#useWasm) {
|
||||
this.#getJsModule(resolve);
|
||||
} else {
|
||||
promises.push(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue