Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
process: delay process.argv[0] and process.argv0 handling
Since these depends on process runtime states, delay them until
pre-execution.
  • Loading branch information
joyeecheung committed Mar 8, 2019
commit 7971185f9701d6df96bbf1250315e0160e0ef0e2
7 changes: 0 additions & 7 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,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() {
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 @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -290,6 +301,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