Skip to content
Merged
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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ API

* **readDebugNames**: `boolean`<br />
Reads textual names from the name section.
* **check**: `boolean`<br/>
Check for invalid modules (default: true).

* **ToTextOptions**<br />
Options modifying the behavior of `WasmModule#toText`.
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ interface WasmFeatures { // see: https://github.com/WebAssembly/wabt/blob/main/s
interface ReadWasmOptions {
/** Reads textual names from the name section. */
readDebugNames?: boolean;

/** Check for invalid modules (default is true). */
check?: boolean;
}

/** Options modifying the behavior of `WasmModule#toText`. */
Expand Down
18 changes: 18 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ require("..")().then(wabt => {
test.end();
});

test("loading an invalid binary module", function (test) {
var buffer = new Uint8Array(
fs.readFileSync(__dirname + "/assembly/module-features.wasm")
);
buffer[buffer.length - 1] = 0x00; // corrupt the last byte
test.throws(function() {
mod = wabt.readWasm(buffer, {});
}, /function body must end with END opcode/);
// Specifying `check: true` allows an invalid module to be loaded.
test.doesNotThrow(function() {
mod = wabt.readWasm(buffer, {
check: false
});
});
test.ok(mod && typeof mod.toBinary === "function", "should return a module");
test.end();
});

test("modifying a module", function(test) {
test.doesNotThrow(function() {
mod.generateNames();
Expand Down