From d4f95091d074adfcf79e1f7d64f5e8b599a5f9f0 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 8 Mar 2019 14:25:47 +0100 Subject: [PATCH] process: delay process.argv[0] and process.argv0 handling Since these depends on process runtime states, delay them until pre-execution. PR-URL: https://github.com/nodejs/node/pull/26517 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater --- lib/internal/bootstrap/node.js | 7 ------- lib/internal/bootstrap/pre_execution.js | 12 ++++++++++++ lib/internal/main/worker_thread.js | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) 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');