From feb5b209ed3994096d0ec17178d38a74803e0dd6 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 10 May 2025 21:30:27 +0200 Subject: [PATCH] web: Adapt new async WASM loading API --- dist/web/source/wasm-config.js | 10 +++++----- out/serve.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 out/serve.py diff --git a/dist/web/source/wasm-config.js b/dist/web/source/wasm-config.js index 5dda37ad0..22632b890 100644 --- a/dist/web/source/wasm-config.js +++ b/dist/web/source/wasm-config.js @@ -9,8 +9,9 @@ fetch("imhex.wasm.size").then(async (resp) => { // inspired from: https://github.com/WordPress/wordpress-playground/pull/46 (but had to be modified) function monkeyPatch(progressFun) { const _instantiateStreaming = WebAssembly.instantiateStreaming; - WebAssembly.instantiateStreaming = (response, ...args) => { + WebAssembly.instantiateStreaming = async (responsePromise, ...args) => { // Do not collect wasm content length here see above + let response = await responsePromise const file = response.url.substring( new URL(response.url).origin.length + 1 ); @@ -235,12 +236,11 @@ var Module = { totalDependencies: 0, monitorRunDependencies: function(left) { }, - instantiateWasm: function(imports, successCallback) { + instantiateWasm: async function(imports, successCallback) { imports.env.glfwSetCursor = glfwSetCursorCustom imports.env.glfwCreateStandardCursor = glfwCreateStandardCursorCustom - instantiateAsync(wasmBinary, wasmBinaryFile, imports, (result) => { - successCallback(result.instance, result.module) - }); + let result = await instantiateAsync(null, findWasmBinary(), imports); + successCallback(result.instance, result.module) }, arguments: [] }; diff --git a/out/serve.py b/out/serve.py new file mode 100644 index 000000000..26b01e2aa --- /dev/null +++ b/out/serve.py @@ -0,0 +1,15 @@ +import http.server +import os + +class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): + + def end_headers(self): + self.send_header("Cross-Origin-Embedder-Policy", "require-corp") + self.send_header("Cross-Origin-Opener-Policy", "same-origin") + http.server.SimpleHTTPRequestHandler.end_headers(self) + +if __name__ == '__main__': + os.chdir(".") + httpd = http.server.HTTPServer(("localhost", 9090), MyHttpRequestHandler) + print(f"Serving {os.getcwd()} on http://{httpd.server_address[0]}:{httpd.server_address[1]}") + httpd.serve_forever()