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 fc90d7c

Browse filesBrowse files
aduh95targos
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 9abd1c7 commit fc90d7c
Copy full SHA for fc90d7c

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
@@ -55,6 +55,7 @@ let debug = require('internal/util/debuglog').debuglog('worker', (fn) => {
5555
});
5656

5757
const assert = require('internal/assert');
58+
const { getOptionValue } = require('internal/options');
5859
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
5960

6061
prepareWorkerThreadExecution();
@@ -152,7 +153,7 @@ port.on('message', (message) => {
152153
break;
153154
}
154155

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

172+
// eslint-disable-next-line no-fallthrough
171173
case 'module': {
172174
const { evalModuleEntryPoint } = require('internal/process/execution');
173175
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.