Review by rreverser

This commit is contained in:
Surma
2021-07-20 11:50:48 +01:00
parent d4056026fb
commit fb867dcdaa

View File

@@ -10,13 +10,16 @@ export function pathify(path: string): string {
export function instantiateEmscriptenWasm<T extends EmscriptenWasm.Module>( export function instantiateEmscriptenWasm<T extends EmscriptenWasm.Module>(
factory: EmscriptenWasm.ModuleFactory<T>, factory: EmscriptenWasm.ModuleFactory<T>,
path: string, path: string,
workerWasm: string = '', workerJS: string = '',
): Promise<T> { ): Promise<T> {
return factory({ return factory({
locateFile(requestPath) { locateFile(requestPath) {
// The glue code generated by emscripten uses the original
// file names of the worker file and the wasm binary.
// These will have changed in the bundling process and
// we need to inject them here.
if (requestPath.endsWith('.wasm')) return pathify(path); if (requestPath.endsWith('.wasm')) return pathify(path);
if (requestPath.endsWith('.worker.js')) if (requestPath.endsWith('.worker.js')) return new URL(workerJS).pathname;
return new URL(workerWasm).pathname;
return requestPath; return requestPath;
}, },
}); });