Skip to content

Commit

Permalink
Add hack to add memory export to the embedded module
Browse files Browse the repository at this point in the history
  • Loading branch information
asprouse committed May 28, 2024
1 parent c2a9d73 commit cc5eb11
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions host.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,33 @@ async function run(wasmFilePath, input) {
returnOnExit: true,
});

const wasm = await WebAssembly.compile(
const embeddedModule = await WebAssembly.compile(
await readFile(new URL(wasmFilePath, import.meta.url)),
);

const provider = await WebAssembly.compile(
const providerModule = await WebAssembly.compile(
await readFile(new URL("./provider.wasm", import.meta.url)),
);

const wasiImports = wasi.getImportObject();
const providerInstance = await WebAssembly.instantiate(provider, wasiImports);
const providerInstance = await WebAssembly.instantiate(
providerModule,
wasi.getImportObject(),
);

const instance = await WebAssembly.instantiate(wasm, {
...wasiImports,
const instance = await WebAssembly.instantiate(embeddedModule, {
javy_quickjs_provider_v1: providerInstance.exports,
});
const _start = instance.exports._start;

// Hack to add the memory export from the provider module
Object.defineProperty(instance, "exports", {
get() {
return {
_start,
memory: providerInstance.exports.memory,
};
},
});

wasi.start(instance);

Expand Down

0 comments on commit cc5eb11

Please sign in to comment.