Skip to content

Commit 121d627

Browse files
author
David Sheldrick
committed
keep callbacks on stack to allow nested consumer usage
1 parent b93aadb commit 121d627

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/wasm.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function wasm() {
2020
return cachedWasm;
2121
}
2222

23-
let currentCallback = null;
23+
const callbackStack = [];
2424

2525
cachedWasm = readWasm().then(buffer => {
2626
return WebAssembly.instantiate(buffer, {
@@ -61,7 +61,7 @@ module.exports = function wasm() {
6161
}
6262
}
6363

64-
currentCallback(mapping);
64+
callbackStack[callbackStack.length - 1](mapping);
6565
},
6666

6767
start_all_generated_locations_for: function () { console.time("all_generated_locations_for"); },
@@ -90,11 +90,11 @@ module.exports = function wasm() {
9090
return {
9191
exports: wasm.instance.exports,
9292
withMappingCallback: (mappingCallback, f) => {
93-
currentCallback = mappingCallback;
93+
callbackStack.push(mappingCallback)
9494
try {
9595
f();
9696
} finally {
97-
currentCallback = null;
97+
callbackStack.pop()
9898
}
9999
}
100100
};

0 commit comments

Comments
 (0)