From 9dba96dc1a754616c81a550c057ce7cf9552e9cf Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 20 Mar 2019 09:02:57 +0800 Subject: process: patch more process properties during pre-execution Delay the creation of process properties that depend on runtime states and properties that should not be accessed during bootstrap and patch them during pre-execution: - process.argv - process.execPath - process.title - process.pid - process.ppid - process.REVERT_* - process.debugPort PR-URL: https://github.com/nodejs/node/pull/26945 Reviewed-By: Gus Caplan Reviewed-By: Benjamin Gruenbaum --- lib/internal/bootstrap/pre_execution.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/internal/bootstrap/pre_execution.js') diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index ab7e169d7a..297aea9dd7 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -3,9 +3,9 @@ const { getOptionValue } = require('internal/options'); const { Buffer } = require('buffer'); -function prepareMainThreadExecution() { +function prepareMainThreadExecution(expandArgv1 = false) { // Patch the process object with legacy properties and normalizations - patchProcessObject(); + patchProcessObject(expandArgv1); setupTraceCategoryState(); setupInspectorHooks(); setupWarningHandler(); @@ -48,7 +48,13 @@ function prepareMainThreadExecution() { loadPreloadModules(); } -function patchProcessObject() { +function patchProcessObject(expandArgv1) { + const { + patchProcessObject: patchProcessObjectNative + } = internalBinding('process_methods'); + + patchProcessObjectNative(process); + Object.defineProperty(process, 'argv0', { enumerable: true, configurable: false, @@ -56,6 +62,12 @@ function patchProcessObject() { }); process.argv[0] = process.execPath; + if (expandArgv1 && process.argv[1] && !process.argv[1].startsWith('-')) { + // Expand process.argv[1] into a full path. + const path = require('path'); + process.argv[1] = path.resolve(process.argv[1]); + } + // TODO(joyeecheung): most of these should be deprecated and removed, // execpt some that we need to be able to mutate during run time. addReadOnlyProcessAlias('_eval', '--eval'); -- cgit v1.2.3