Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f55a5fe

Browse filesBrowse 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 ec1cbbe commit f55a5fe
Copy full SHA for f55a5fe

4 files changed

+26Lines changed: 26 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+8Lines changed: 8 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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`
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+3Lines 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') =>
Collapse file

‎lib/internal/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/util.js
+4Lines 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
/**
Collapse file

‎test/es-module/test-typescript.mjs‎

Copy file name to clipboardExpand all lines: test/es-module/test-typescript.mjs
+11Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.