diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-20 09:02:57 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-04 05:14:54 +0800 |
commit | 9dba96dc1a754616c81a550c057ce7cf9552e9cf (patch) | |
tree | fbec9fd2a7a51634ac50c849192d8fd0e9f02cbb /lib/internal/bootstrap | |
parent | d005f382cdcec7dff1d61cf5ab3604e55f004471 (diff) | |
download | android-node-v8-9dba96dc1a754616c81a550c057ce7cf9552e9cf.tar.gz android-node-v8-9dba96dc1a754616c81a550c057ce7cf9552e9cf.tar.bz2 android-node-v8-9dba96dc1a754616c81a550c057ce7cf9552e9cf.zip |
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 <me@gus.host>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/internal/bootstrap')
-rw-r--r-- | lib/internal/bootstrap/pre_execution.js | 18 |
1 files changed, 15 insertions, 3 deletions
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'); |