Skip to content

Commit

Permalink
wasm2js support for WebAssembly.Module.exports()
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Jan 10, 2025
1 parent 0b9460a commit bdf76f3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/wasm2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ var WebAssembly = {
info['env']['__tempMemory__'] = 0; // risky!
// This will be replaced by the actual wasm2js code.
var exports = instantiate(info, wasmMemory);

// Save the exports on the module object, so that
// WebAssembly.Module.exports() works. Ideally we would do this in
// WebAssembly.Module(), but we don't know the exports at that point - all
// the actual work happens in Instance(), here. In practice this is enough
// as calls to WebAssembly.Module.exports() from the fuzzer happen after
// instantiation.
module.exports = exports;

return {
'exports': exports
};
Expand All @@ -83,6 +92,15 @@ var WebAssembly = {
}
};

// Add the exports() API on top of the Module constructor.
WebAssembly.Module.exports = (module) => {
var ret = [];
for (var key in module.exports) {
ret.push({ name: key });
}
return ret;
};

var tempRet0 = 0;

var env = {
Expand Down

0 comments on commit bdf76f3

Please sign in to comment.