I have compiled a niche interpretter with WASM and the below works fine on the first function call. However any successive calls do absolutely nothing.
My understanding is WASM js made with Emscripten effectively "runs once" and is even kept alive on exit, so to invoke my wasm-js many times you'd need to remove it from the DOM each team and re-add it. I assume this understanding must be incorrect or I have some weird cache issue going on where things are being ignored...
Any help is appreciated!
export function runWASM(newCodeString) {
return new Promise((resolve) => {
const oldScript = document.getElementById('code-script');
if (oldScript) {
console.log('Removing old script');
oldScript.remove();
}
window.Module = {
arguments: ['code.sno'],
print: (text) => console.log(text),
// printErr: (text) => console.error(text),
preRun: [
function () {
window.FS.createDataFile('/', 'code.sno', newCodeString, true, false, false);
}
],
postRun: [
function () {
const doneRun = true;
resolve(doneRun);
}
],
noInitialRun: false,
noExitRuntime: false
};
console.log('Module:', window.Module);
// Add new script
const script = document.createElement('script');
script.src = '/interpretter.js';
script.id = 'code-script';
document.body.appendChild(script);
});
}