diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index d3a18b4d0fb..86c4bfd6544 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -214,13 +214,6 @@ if (!config.noBrowserGlobals) { setupDOMException(); -Object.defineProperty(process, 'argv0', { - enumerable: true, - configurable: false, - value: process.argv[0] -}); -process.argv[0] = process.execPath; - // process.allowedNodeEnvironmentFlags Object.defineProperty(process, 'allowedNodeEnvironmentFlags', { get() { diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 79bb5cc2916..95203c470f7 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -6,6 +6,8 @@ const { getOptionValue } = require('internal/options'); let traceEventsAsyncHook; function prepareMainThreadExecution() { + // Patch the process object with legacy properties and normalizations + patchProcessObject(); setupTraceCategoryState(); setupWarningHandler(); @@ -48,6 +50,15 @@ function prepareMainThreadExecution() { loadPreloadModules(); } +function patchProcessObject() { + Object.defineProperty(process, 'argv0', { + enumerable: true, + configurable: false, + value: process.argv[0] + }); + process.argv[0] = process.execPath; +} + function setupWarningHandler() { const { onWarning @@ -296,6 +307,7 @@ function loadPreloadModules() { } module.exports = { + patchProcessObject, setupCoverageHooks, setupWarningHandler, setupDebugEnv, diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 885d6dfcb1b..c5a729b5721 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -4,6 +4,7 @@ // message port. const { + patchProcessObject, setupCoverageHooks, setupWarningHandler, setupDebugEnv, @@ -41,6 +42,7 @@ const { const publicWorker = require('worker_threads'); +patchProcessObject(); setupDebugEnv(); const debug = require('util').debuglog('worker');