Skip to content

Commit

Permalink
~fixed bad import changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed Mar 23, 2024
1 parent f5ac04d commit b7671eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions source/wasm/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class Module {

importFunction(mod: string, name: string, typeIdx: number) {
const idx = this.importSect.registerFunction(mod, name, typeIdx);
if (idx === null) return null;

const ref = new FuncRef(true);
ref.resolve(idx);
Expand Down
12 changes: 5 additions & 7 deletions source/wasm/section/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class Register {
}
}

interface InnerObject {
interface ModuleMap {
[key: string]: Register;
}

interface OuterObject {
[key: string]: InnerObject;
interface NamespaceMap {
[key: string]: ModuleMap;
}


export default class ImportSection {
_entries: OuterObject;
_entries: NamespaceMap;
_funcs: number;

constructor() {
Expand All @@ -50,9 +50,7 @@ export default class ImportSection {

if (!mod[name]) {
mod[name] = new Register(module, name, typeIdx, this._funcs++);
} else if (mod[name].type !== typeIdx) {
throw new Error(`Attempting to register import "${module}" "${name}" with new type`);
}
} else if (mod[name].type !== typeIdx) return null;

return mod[name].idx;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/wasm/hello-world.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Deno.test(`Wasm module test: should print "${goalText}"`, async () => {
const mem = mod.addMemory(1);
mod.exportMemory("memory", mem);

const type0 = mod.makeType([Type.Intrinsic.i32], [Type.Intrinsic.i32]);
const type1 = mod.makeType([Type.Intrinsic.i32, Type.Intrinsic.i32, Type.Intrinsic.i32, Type.Intrinsic.i32], [Type.Intrinsic.i32]);

const fd_write = mod.importFunction("wasi_snapshot_preview1", "fd_write", type1);
if (fd_write === null) fail(`Unable to import fd_write`);

mod.setData(0, goalText);
// The WASI iovec struct, which consists of a pointer to
Expand Down

0 comments on commit b7671eb

Please sign in to comment.