Skip to content

Commit d4f9509

Browse files
joyeecheungtargos
authored andcommittedMar 30, 2019
process: delay process.argv[0] and process.argv0 handling
Since these depends on process runtime states, delay them until pre-execution. PR-URL: #26517 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 03bd649 commit d4f9509

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed
 

‎lib/internal/bootstrap/node.js

-7
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,6 @@ if (!config.noBrowserGlobals) {
206206
defineOperation(global, 'setImmediate', timers.setImmediate);
207207
}
208208

209-
Object.defineProperty(process, 'argv0', {
210-
enumerable: true,
211-
configurable: false,
212-
value: process.argv[0]
213-
});
214-
process.argv[0] = process.execPath;
215-
216209
// TODO(jasnell): The following have been globals since around 2012.
217210
// That's just silly. The underlying perfctr support has been removed
218211
// so these are now deprecated non-ops that can be removed after one

‎lib/internal/bootstrap/pre_execution.js

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const { getOptionValue } = require('internal/options');
44

55
function prepareMainThreadExecution() {
6+
// Patch the process object with legacy properties and normalizations
7+
patchProcessObject();
68
setupTraceCategoryState();
79

810
setupWarningHandler();
@@ -59,6 +61,15 @@ function prepareMainThreadExecution() {
5961
loadPreloadModules();
6062
}
6163

64+
function patchProcessObject() {
65+
Object.defineProperty(process, 'argv0', {
66+
enumerable: true,
67+
configurable: false,
68+
value: process.argv[0]
69+
});
70+
process.argv[0] = process.execPath;
71+
}
72+
6273
function setupWarningHandler() {
6374
const {
6475
onWarning
@@ -307,6 +318,7 @@ function loadPreloadModules() {
307318
}
308319

309320
module.exports = {
321+
patchProcessObject,
310322
setupCoverageHooks,
311323
setupWarningHandler,
312324
setupDebugEnv,

‎lib/internal/main/worker_thread.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// message port.
55

66
const {
7+
patchProcessObject,
78
setupCoverageHooks,
89
setupWarningHandler,
910
setupDebugEnv,
@@ -41,6 +42,7 @@ const {
4142

4243
const publicWorker = require('worker_threads');
4344

45+
patchProcessObject();
4446
setupDebugEnv();
4547

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

0 commit comments

Comments
 (0)
Please sign in to comment.