Skip to content

Commit

Permalink
process: delay process.argv[0] and process.argv0 handling
Browse files Browse the repository at this point in the history
Since these depends on process runtime states, delay them until
pre-execution.

PR-URL: #26517
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
joyeecheung authored and targos committed Mar 30, 2019
1 parent 03bd649 commit d4f9509
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 0 additions & 7 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const { getOptionValue } = require('internal/options');

function prepareMainThreadExecution() {
// Patch the process object with legacy properties and normalizations
patchProcessObject();
setupTraceCategoryState();

setupWarningHandler();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -307,6 +318,7 @@ function loadPreloadModules() {
}

module.exports = {
patchProcessObject,
setupCoverageHooks,
setupWarningHandler,
setupDebugEnv,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// message port.

const {
patchProcessObject,
setupCoverageHooks,
setupWarningHandler,
setupDebugEnv,
Expand Down Expand Up @@ -41,6 +42,7 @@ const {

const publicWorker = require('worker_threads');

patchProcessObject();
setupDebugEnv();

const debug = require('util').debuglog('worker');
Expand Down

0 comments on commit d4f9509

Please sign in to comment.