Skip to content

Commit

Permalink
keep callbacks on stack to allow nested consumer usage
Browse files Browse the repository at this point in the history
  • Loading branch information
David Sheldrick committed Apr 21, 2018
1 parent b93aadb commit 121d627
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/wasm.js
Expand Up @@ -20,7 +20,7 @@ module.exports = function wasm() {
return cachedWasm;
}

let currentCallback = null;
const callbackStack = [];

cachedWasm = readWasm().then(buffer => {
return WebAssembly.instantiate(buffer, {
Expand Down Expand Up @@ -61,7 +61,7 @@ module.exports = function wasm() {
}
}

currentCallback(mapping);
callbackStack[callbackStack.length - 1](mapping);
},

start_all_generated_locations_for: function () { console.time("all_generated_locations_for"); },
Expand Down Expand Up @@ -90,11 +90,11 @@ module.exports = function wasm() {
return {
exports: wasm.instance.exports,
withMappingCallback: (mappingCallback, f) => {
currentCallback = mappingCallback;
callbackStack.push(mappingCallback)
try {
f();
} finally {
currentCallback = null;
callbackStack.pop()
}
}
};
Expand Down

0 comments on commit 121d627

Please sign in to comment.