lib: fix TypeScript support check in jitless mode · nodejs/node@9d8d932 · GitHub
Skip to content

Commit 9d8d932

Browse files
Han5991aduh95
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 6ea3e4d commit 9d8d932

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

doc/api/errors.md

Lines changed: 8 additions & 0 deletions

lib/internal/errors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,9 @@ E('ERR_VM_MODULE_NOT_MODULE',
18891889
'Provided module is not an instance of Module', Error);
18901890
E('ERR_VM_MODULE_STATUS', 'Module status %s', Error);
18911891
E('ERR_WASI_ALREADY_STARTED', 'WASI instance has already started', Error);
1892+
E('ERR_WEBASSEMBLY_NOT_SUPPORTED',
1893+
'WebAssembly is not supported in this environment, but is required for %s',
1894+
Error);
18921895
E('ERR_WEBASSEMBLY_RESPONSE', 'WebAssembly response %s', TypeError);
18931896
E('ERR_WORKER_INIT_FAILED', 'Worker initialization failure: %s', Error);
18941897
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
@@ -45,13 +45,15 @@ const {
4545
SymbolPrototypeGetDescription,
4646
SymbolReplace,
4747
SymbolSplit,
48+
globalThis,
4849
} = primordials;
4950

5051
const {
5152
codes: {
5253
ERR_NO_CRYPTO,
5354
ERR_NO_TYPESCRIPT,
5455
ERR_UNKNOWN_SIGNAL,
56+
ERR_WEBASSEMBLY_NOT_SUPPORTED,
5557
},
5658
isErrorStackTraceLimitWritable,
5759
overrideStackTrace,
@@ -222,6 +224,8 @@ function assertCrypto() {
222224
function assertTypeScript() {
223225
if (noTypeScript)
224226
throw new ERR_NO_TYPESCRIPT();
227+
if (globalThis.WebAssembly === undefined)
228+
throw new ERR_WEBASSEMBLY_NOT_SUPPORTED('TypeScript');
225229
}
226230

227231
/**

test/es-module/test-typescript.mjs

Lines changed: 11 additions & 0 deletions

0 commit comments

Comments
 (0)