Skip to content

Commit 04c8828

Browse files
Han5991nodejs-github-bot
authored andcommitted
lib: fix TypeScript support check in jitless mode
WebAssembly is disabled when Node.js is run with --jitless. The internal TypeScript stripper relies on WebAssembly, and previously failed obscurely with a ReferenceError in this mode. This commit adds an explicit check for WebAssembly support when loading the TypeScript parser. If WebAssembly is unavailable, it now throws a descriptive ERR_WEBASSEMBLY_NOT_SUPPORTED error. Fixes: #61353 PR-URL: #61382 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 79ddd1b commit 04c8828

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

doc/api/errors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,6 +3350,14 @@ The WASI instance has already started.
33503350

33513351
The WASI instance has not been started.
33523352

3353+
<a id="ERR_WEBASSEMBLY_NOT_SUPPORTED"></a>
3354+
3355+
### `ERR_WEBASSEMBLY_NOT_SUPPORTED`
3356+
3357+
A feature requiring WebAssembly was used, but WebAssembly is not supported or
3358+
has been disabled in the current environment (for example, when running with
3359+
`--jitless`). The error message specifies which feature requires WebAssembly.
3360+
33533361
<a id="ERR_WEBASSEMBLY_RESPONSE"></a>
33543362

33553363
### `ERR_WEBASSEMBLY_RESPONSE`

lib/internal/errors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,9 @@ E('ERR_VM_MODULE_NOT_MODULE',
19051905
'Provided module is not an instance of Module', Error);
19061906
E('ERR_VM_MODULE_STATUS', 'Module status %s', Error);
19071907
E('ERR_WASI_ALREADY_STARTED', 'WASI instance has already started', Error);
1908+
E('ERR_WEBASSEMBLY_NOT_SUPPORTED',
1909+
'WebAssembly is not supported in this environment, but is required for %s',
1910+
Error);
19081911
E('ERR_WEBASSEMBLY_RESPONSE', 'WebAssembly response %s', TypeError);
19091912
E('ERR_WORKER_INIT_FAILED', 'Worker initialization failure: %s', Error);
19101913
E('ERR_WORKER_INVALID_EXEC_ARGV', (errors, msg = 'invalid execArgv flags') =>

lib/internal/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ const {
4646
SymbolPrototypeGetDescription,
4747
SymbolReplace,
4848
SymbolSplit,
49+
globalThis,
4950
} = primordials;
5051

5152
const {
5253
codes: {
5354
ERR_NO_CRYPTO,
5455
ERR_NO_TYPESCRIPT,
5556
ERR_UNKNOWN_SIGNAL,
57+
ERR_WEBASSEMBLY_NOT_SUPPORTED,
5658
},
5759
isErrorStackTraceLimitWritable,
5860
overrideStackTrace,
@@ -244,6 +246,8 @@ function assertCrypto() {
244246
function assertTypeScript() {
245247
if (noTypeScript)
246248
throw new ERR_NO_TYPESCRIPT();
249+
if (globalThis.WebAssembly === undefined)
250+
throw new ERR_WEBASSEMBLY_NOT_SUPPORTED('TypeScript');
247251
}
248252

249253
/**

test/es-module/test-typescript.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,14 @@ test('check transform types warning', async () => {
342342
assert.match(result.stdout, /Hello, TypeScript!/);
343343
assert.strictEqual(result.code, 0);
344344
});
345+
346+
test('expect error when executing a TypeScript file with --jitless', async () => {
347+
const result = await spawnPromisified(process.execPath, [
348+
'--jitless',
349+
fixtures.path('typescript/ts/test-typescript.ts'),
350+
]);
351+
352+
assert.match(result.stderr, /ERR_WEBASSEMBLY_NOT_SUPPORTED/);
353+
assert.match(result.stderr, /WebAssembly is not supported in this environment, but is required for TypeScript/);
354+
assert.strictEqual(result.code, 1);
355+
});

0 commit comments

Comments
 (0)