Skip to content

Commit 83daf40

Browse files
committed
fix: error message when WebAssembly global do not exists
1 parent 25e2f9c commit 83daf40

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

lib/errors.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
const kWebAssemblyObjNotAvailable = Symbol.for('amaro.error.AMARO_ERR_WEB_ASSEMBLY_OBJ_NOT_AVAILABLE')
3+
export class WebAssemblyObjectNotAvailable extends Error {
4+
constructor() {
5+
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.');
6+
this.name = 'WebAssemblyObjectNotAvailable';
7+
this.code = 'AMARO_ERR_WEB_ASSEMBLY_OBJ_NOT_AVAILABLE';
8+
}
9+
10+
static [Symbol.hasInstance](instance) {
11+
return instance && instance[kWebAssemblyObjNotAvailable] === true
12+
}
13+
14+
get [kWebAssemblyObjNotAvailable]() {
15+
return true
16+
}
17+
}

lib/wasm.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/loader.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,18 @@ test("should throw syntax error for invalid typescript", async (t) => {
9999
match(result.stderr, /await isn't allowed in non-async function/);
100100
strictEqual(result.code, 1);
101101
});
102+
103+
test("should throw WebAssemblyObjectNotAvailable when WebAssembly global is not available", async (t) => {
104+
const result = await spawnPromisified(process.execPath, [
105+
"--jitless",
106+
"--no-warnings",
107+
"--import=./dist/register-strip.mjs",
108+
fixturesPath("hello.ts"),
109+
]);
110+
111+
strictEqual(result.stdout, "");
112+
match(result.stderr, /WebAssemblyObjectNotAvailable/);
113+
match(result.stderr, /AMARO_ERR_WEB_ASSEMBLY_OBJ_NOT_AVAILABLE/);
114+
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./);
115+
strictEqual(result.code, 1);
116+
});

0 commit comments

Comments
 (0)