mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
worker: handle --input-type
more consistently
PR-URL: https://github.com/nodejs/node/pull/54979 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
parent
c42d8461b0
commit
6031a4bc7c
@ -55,6 +55,7 @@ let debug = require('internal/util/debuglog').debuglog('worker', (fn) => {
|
||||
});
|
||||
|
||||
const assert = require('internal/assert');
|
||||
const { getOptionValue } = require('internal/options');
|
||||
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
|
||||
|
||||
prepareWorkerThreadExecution();
|
||||
@ -152,7 +153,7 @@ port.on('message', (message) => {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'classic': {
|
||||
case 'classic': if (getOptionValue('--input-type') !== 'module') {
|
||||
const { evalScript } = require('internal/process/execution');
|
||||
const name = '[worker eval]';
|
||||
// This is necessary for CJS module compilation.
|
||||
@ -168,6 +169,7 @@ port.on('message', (message) => {
|
||||
break;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-fallthrough
|
||||
case 'module': {
|
||||
const { evalModuleEntryPoint } = require('internal/process/execution');
|
||||
PromisePrototypeThen(evalModuleEntryPoint(filename), undefined, (e) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Flags: --expose-internals --expose-gc
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const { Worker } = require('worker_threads');
|
||||
const assert = require('assert');
|
||||
|
||||
@ -29,3 +29,11 @@ new Worker(CODE, { eval: true, env: process.env, execArgv: ['--expose-internals'
|
||||
assert.throws(() => {
|
||||
new Worker(CODE, { eval: true, execArgv: ['--expose-gc'] });
|
||||
}, /ERR_WORKER_INVALID_EXEC_ARGV/);
|
||||
|
||||
// Test ESM eval
|
||||
new Worker('export {}', { eval: true, execArgv: ['--input-type=module'] });
|
||||
new Worker('export {}', { eval: true, execArgv: ['--input-type=commonjs'] })
|
||||
.once('error', common.expectsError({ name: 'SyntaxError' }));
|
||||
new Worker('export {}', { eval: true, execArgv: ['--experimental-detect-module'] });
|
||||
new Worker('export {}', { eval: true, execArgv: ['--no-experimental-detect-module'] })
|
||||
.once('error', common.expectsError({ name: 'SyntaxError' }));
|
||||
|
Loading…
Reference in New Issue
Block a user