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 <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Joyee Cheung 2019-03-08 14:25:47 +01:00
parent eb0bf8d307
commit 728c939e57
No known key found for this signature in database
GPG Key ID: 92B78A53C8303B8D
3 changed files with 14 additions and 7 deletions

View File

@ -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() {

View File

@ -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,

View File

@ -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');