diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index d9ad263ca0b46f..2b5d2ee3f41ee8 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -206,13 +206,6 @@ if (!config.noBrowserGlobals) { defineOperation(global, 'setImmediate', timers.setImmediate); } -Object.defineProperty(process, 'argv0', { - enumerable: true, - configurable: false, - value: process.argv[0] -}); -process.argv[0] = process.execPath; - // TODO(jasnell): The following have been globals since around 2012. // That's just silly. The underlying perfctr support has been removed // so these are now deprecated non-ops that can be removed after one diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index a518fcfd621a6a..f716b2de6d4951 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -3,6 +3,8 @@ const { getOptionValue } = require('internal/options'); function prepareMainThreadExecution() { + // Patch the process object with legacy properties and normalizations + patchProcessObject(); setupTraceCategoryState(); setupWarningHandler(); @@ -59,6 +61,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 @@ -307,6 +318,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 885d6dfcb1be24..c5a729b5721f94 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');