Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ declare namespace binaryen {
addActiveElementSegment(table: string, name: string, funcNames: readonly string[], offset: ExpressionRef): ElementSegmentRef;
addPassiveElementSegment(name: string, funcNames: readonly string[]): ElementSegmentRef;
getElementSegment(name: string): ElementSegmentRef;
getTableSegments(table: string): string[];
getTableSegments(table: TableRef): ElementSegmentRef[];
removeElementSegment(name: string): void;
addTag(name: string, params: Type, results: Type): TagRef;
getTag(name: string): TagRef;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"scripts": {
"readme": "doctoc README.md --github --title \"### Contents\"",
"check": "tsc index.d.ts --noEmit --strict --noImplicitAny --strictNullChecks --listFiles --diagnostics",
"check": "tsc index.d.ts tests/table-segments.ts --noEmit --strict --noImplicitAny --strictNullChecks --listFiles --diagnostics",
"test": "npm run check && node tests/sanity && node tests/example",
"bundle": "node scripts/bundle.js"
},
Expand Down
15 changes: 15 additions & 0 deletions tests/sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,18 @@ assert(typeof js === "string" && js.length);
console.log("wrapping an existing module");
var wrapped = binaryen.wrapModule(mod.ptr);
assert(wrapped.getFunction("main"));

console.log("getting element references for a table");
var tables = new binaryen.Module();
tables.addFunction("answer", binaryen.none, binaryen.i32, [], tables.i32.const(42));
var dispatch = tables.addTable("dispatch", 1, 1);
tables.addTable("other", 1, 1);
tables.addActiveElementSegment("dispatch", "matched", [ "answer" ], tables.i32.const(0));
tables.addActiveElementSegment("other", "unrelated", [ "answer" ], tables.i32.const(0));
var segments = tables.getTableSegments(dispatch);
assert.deepStrictEqual(segments, [ tables.getElementSegment("matched") ]);
var segmentInfo = binaryen.getElementSegmentInfo(segments[0]);
assert.strictEqual(segmentInfo.name, "matched");
assert.strictEqual(segmentInfo.table, "dispatch");
assert.deepStrictEqual(segmentInfo.data, [ "answer" ]);
tables.dispose();
17 changes: 17 additions & 0 deletions tests/table-segments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import binaryen from "../index.js";

const module = new binaryen.Module();
const table = module.addTable("dispatch", 1, 1);
const segments: binaryen.ElementSegmentRef[] = module.getTableSegments(table);
const info = binaryen.getElementSegmentInfo(segments[0]);
const segmentName: string = info.name;

// A table name is not a table reference accepted by the runtime.
// @ts-expect-error
module.getTableSegments("dispatch");

// Element references are not names accepted by getElementSegment.
// @ts-expect-error
const names: string[] = segments;

module.dispose();