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
17 changes: 17 additions & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

const kWebAssemblyObjNotAvailable = Symbol.for('amaro.error.AMARO_ERR_WEB_ASSEMBLY_OBJ_NOT_AVAILABLE')
export class WebAssemblyObjectNotAvailable extends Error {
constructor() {
super('WebAssembly global object is not available, but it is required to run Amaro (Node.js TypeScript library). This can happen, for example, when running V8 in JIT-less mode.');
this.name = 'WebAssemblyObjectNotAvailable';
this.code = 'AMARO_ERR_WEB_ASSEMBLY_OBJ_NOT_AVAILABLE';
}

static [Symbol.hasInstance](instance) {
return instance && instance[kWebAssemblyObjNotAvailable] === true
}

get [kWebAssemblyObjNotAvailable]() {
return true
}
}
4 changes: 4 additions & 0 deletions lib/wasm.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,21 @@ test("should throw syntax error for invalid typescript", async (t) => {
match(result.stderr, /await isn't allowed in non-async function/);
strictEqual(result.code, 1);
});

test("should throw WebAssemblyObjectNotAvailable when WebAssembly global is not available", async (t) => {
const result = await spawnPromisified(process.execPath, [
"--jitless",
"--no-warnings",
"--import=./dist/register-strip.mjs",
fixturesPath("hello.ts"),
]);

strictEqual(result.stdout, "");
match(result.stderr, /WebAssemblyObjectNotAvailable/);
match(result.stderr, /AMARO_ERR_WEB_ASSEMBLY_OBJ_NOT_AVAILABLE/);
match(
result.stderr,
/WebAssembly global object is not available, but it is required to run Amaro \(Node.js TypeScript library\). This can happen, for example, when running V8 in JIT-less mode./,
);
strictEqual(result.code, 1);
});
Loading