From 252a4074e48c727fb09729ab08dad1ad60d9ab34 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 9 Oct 2020 19:36:14 -0700 Subject: [PATCH] js: Fix reactor interface to not use Emscripten imports We now create the array wrapper for each decode which should be almost free, to avoid having to use a non-standard sbrk interface. --- js/meshopt_decoder.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/js/meshopt_decoder.js b/js/meshopt_decoder.js index dbc24a853..ce5c53ceb 100644 --- a/js/meshopt_decoder.js +++ b/js/meshopt_decoder.js @@ -28,20 +28,13 @@ var MeshoptDecoder = (function() { console.log("Warning: meshopt_decoder is using experimental SIMD support"); } - var instance, heap; - - var env = { - emscripten_notify_memory_growth: function(index) { - heap = new Uint8Array(instance.exports.memory.buffer); - } - }; + var instance; var promise = - WebAssembly.instantiate(unpack(wasm), { env }) + WebAssembly.instantiate(unpack(wasm), {}) .then(function(result) { instance = result.instance; - instance.exports._initialize(); - env.emscripten_notify_memory_growth(0); + instance.exports.__wasm_call_ctors(); }); function unpack(data) { @@ -62,6 +55,7 @@ var MeshoptDecoder = (function() { var count4 = (count + 3) & ~3; // pad for SIMD filter var tp = sbrk(count4 * size); var sp = sbrk(source.length); + var heap = new Uint8Array(instance.exports.memory.buffer); heap.set(source, sp); var res = fun(tp, count, size, sp, source.length); if (res == 0 && filter) {