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

[js/web] skip default locateFile() when dynamic import is disabled #21073

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions js/web/lib/backend-wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ export const initializeFlags = (): void => {
}
}

// overwrite wasm paths override if not set
if (env.wasm.wasmPaths === undefined && scriptSrc && scriptSrc.indexOf('blob:') !== 0) {
env.wasm.wasmPaths = scriptSrc.substring(0, scriptSrc.lastIndexOf('/') + 1);
if (!BUILD_DEFS.DISABLE_DYNAMIC_IMPORT) {
// overwrite wasm paths override if not set
if (env.wasm.wasmPaths === undefined && scriptSrc && scriptSrc.indexOf('blob:') !== 0) {
env.wasm.wasmPaths = scriptSrc.substring(0, scriptSrc.lastIndexOf('/') + 1);
}
}
};

Expand Down
8 changes: 6 additions & 2 deletions js/web/lib/wasm/wasm-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,17 @@ export const initializeWebAssembly = async(flags: Env.WebAssemblyFlags): Promise
* created.
*/
numThreads,
};

if (wasmPathOverride || wasmPrefixOverride) {
/**
* A callback function to locate the WebAssembly file. The function should return the full path of the file.
*
* Since Emscripten 3.1.58, this function is only called for the .wasm file.
*/
locateFile: (fileName, scriptDirectory) => wasmPathOverride ?? (wasmPrefixOverride ?? scriptDirectory) + fileName
};
config.locateFile = (fileName, scriptDirectory) =>
wasmPathOverride ?? (wasmPrefixOverride ?? scriptDirectory) + fileName;
}

ortWasmFactory(config).then(
// wasm module initialized successfully
Expand Down
Loading