From 62222416514effb94e8142385062589069b357ca Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sun, 20 Nov 2022 14:05:35 +0100 Subject: [PATCH] Wasm: update loader to use instantiateStreaming method --- .../org/teavm/backend/wasm/wasm-runtime.js | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/core/src/main/resources/org/teavm/backend/wasm/wasm-runtime.js b/core/src/main/resources/org/teavm/backend/wasm/wasm-runtime.js index 699308ac1..ab5605193 100644 --- a/core/src/main/resources/org/teavm/backend/wasm/wasm-runtime.js +++ b/core/src/main/resources/org/teavm/backend/wasm/wasm-runtime.js @@ -159,25 +159,6 @@ TeaVM.wasm = function() { } function load(path, options) { - let xhr = new XMLHttpRequest(); - xhr.responseType = "arraybuffer"; - xhr.open("GET", path); - - return new Promise((resolve, reject) => { - xhr.onload = () => { - let response = xhr.response; - if (!response) { - reject("Error loading Wasm data") - return; - } - - resolve(response); - }; - xhr.send(); - }).then(data => create(data, options)); - } - - function create(data, options) { if (!options) { options = {}; } @@ -188,12 +169,12 @@ TeaVM.wasm = function() { options.installImports(importObj); } - return WebAssembly.instantiate(data, importObj).then(resultObject => { - controller.instance = resultObject.instance; - let teavm = createTeaVM(resultObject.instance); + return WebAssembly.instantiateStreaming(fetch(path), importObj).then((obj => { + controller.instance = obj.instance; + let teavm = createTeaVM(obj.instance); teavm.main = createMain(teavm, controller); return teavm; - }); + })); } function createMain(teavm, controller) { @@ -223,5 +204,5 @@ TeaVM.wasm = function() { } } - return { JavaError, load, create }; + return { JavaError, load }; }();