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 f39ff4d

Browse filesBrowse files
aduh95marco-ippolito
authored andcommitted
worker: handle --input-type more consistently
PR-URL: #54979 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent ee5624b commit f39ff4d
Copy full SHA for f39ff4d

File tree

Expand file treeCollapse file tree

2 files changed

+12
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/main/worker_thread.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/worker_thread.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ let debug = require('internal/util/debuglog').debuglog('worker', (fn) => {
5353
});
5454

5555
const assert = require('internal/assert');
56+
const { getOptionValue } = require('internal/options');
5657
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
5758

5859
prepareWorkerThreadExecution();
@@ -153,7 +154,7 @@ port.on('message', (message) => {
153154
break;
154155
}
155156

156-
case 'classic': {
157+
case 'classic': if (getOptionValue('--input-type') !== 'module') {
157158
const { evalScript } = require('internal/process/execution');
158159
const name = '[worker eval]';
159160
// This is necessary for CJS module compilation.
@@ -169,6 +170,7 @@ port.on('message', (message) => {
169170
break;
170171
}
171172

173+
// eslint-disable-next-line no-fallthrough
172174
case 'module': {
173175
const { evalModuleEntryPoint } = require('internal/process/execution');
174176
PromisePrototypeThen(evalModuleEntryPoint(filename), undefined, (e) => {
Collapse file

‎test/parallel/test-worker-cli-options.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-worker-cli-options.js
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Flags: --expose-internals --expose-gc
22
'use strict';
3-
require('../common');
3+
const common = require('../common');
44
const { Worker } = require('worker_threads');
55
const assert = require('assert');
66

@@ -29,3 +29,11 @@ new Worker(CODE, { eval: true, env: process.env, execArgv: ['--expose-internals'
2929
assert.throws(() => {
3030
new Worker(CODE, { eval: true, execArgv: ['--expose-gc'] });
3131
}, /ERR_WORKER_INVALID_EXEC_ARGV/);
32+
33+
// Test ESM eval
34+
new Worker('export {}', { eval: true, execArgv: ['--input-type=module'] });
35+
new Worker('export {}', { eval: true, execArgv: ['--input-type=commonjs'] })
36+
.once('error', common.expectsError({ name: 'SyntaxError' }));
37+
new Worker('export {}', { eval: true, execArgv: ['--experimental-detect-module'] });
38+
new Worker('export {}', { eval: true, execArgv: ['--no-experimental-detect-module'] })
39+
.once('error', common.expectsError({ name: 'SyntaxError' }));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.