From 0d17fa410e4776b4932c708162feb13df40583df Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Wed, 15 Feb 2023 16:43:10 -0800 Subject: [PATCH 1/2] use a fresh WebAssembly instance for each SourceMapConsumer --- lib/wasm.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/wasm.js b/lib/wasm.js index 3091d9ee..9d47fe23 100644 --- a/lib/wasm.js +++ b/lib/wasm.js @@ -13,18 +13,21 @@ function Mapping() { this.name = null; } -let cachedWasm = null; - -module.exports = function wasm() { - if (cachedWasm) { - return cachedWasm; +let cachedCompiledWasm = null; +async function compile() { + if (!cachedCompiledWasm) { + const buf = await readWasm() + cachedCompiledWasm = await WebAssembly.compile(buf) } + return cachedCompiledWasm +} +module.exports = function wasm() { const callbackStack = []; - cachedWasm = readWasm() - .then(buffer => { - return WebAssembly.instantiate(buffer, { + return compile() + .then(module => { + return WebAssembly.instantiate(module, { env: { mapping_callback( generatedLine, @@ -116,9 +119,9 @@ module.exports = function wasm() { }, }); }) - .then(Wasm => { + .then(instance => { return { - exports: Wasm.instance.exports, + exports: instance.exports, withMappingCallback: (mappingCallback, f) => { callbackStack.push(mappingCallback); try { @@ -129,10 +132,4 @@ module.exports = function wasm() { }, }; }) - .then(null, e => { - cachedWasm = null; - throw e; - }); - - return cachedWasm; }; From 64b14efb6102bf64c55c1c185bbfc9db9757ac32 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Wed, 15 Feb 2023 16:52:50 -0800 Subject: [PATCH 2/2] lint --- lib/wasm.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/wasm.js b/lib/wasm.js index 9d47fe23..a83f0003 100644 --- a/lib/wasm.js +++ b/lib/wasm.js @@ -16,10 +16,10 @@ function Mapping() { let cachedCompiledWasm = null; async function compile() { if (!cachedCompiledWasm) { - const buf = await readWasm() - cachedCompiledWasm = await WebAssembly.compile(buf) + const buf = await readWasm(); + cachedCompiledWasm = await WebAssembly.compile(buf); } - return cachedCompiledWasm + return cachedCompiledWasm; } module.exports = function wasm() { @@ -131,5 +131,5 @@ module.exports = function wasm() { } }, }; - }) + }); };