summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-03-20 09:02:57 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-04-04 05:14:54 +0800
commit9dba96dc1a754616c81a550c057ce7cf9552e9cf (patch)
treefbec9fd2a7a51634ac50c849192d8fd0e9f02cbb /lib
parentd005f382cdcec7dff1d61cf5ab3604e55f004471 (diff)
downloadandroid-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')
-rw-r--r--lib/internal/bootstrap/pre_execution.js18
-rw-r--r--lib/internal/main/check_syntax.js21
-rw-r--r--lib/internal/main/run_main_module.js6
-rw-r--r--lib/internal/process/warning.js3
4 files changed, 27 insertions, 21 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');
diff --git a/lib/internal/main/check_syntax.js b/lib/internal/main/check_syntax.js
index 8c73d522ed..5bfe4ec3cd 100644
--- a/lib/internal/main/check_syntax.js
+++ b/lib/internal/main/check_syntax.js
@@ -18,20 +18,18 @@ const {
stripShebang, stripBOM
} = require('internal/modules/cjs/helpers');
-let CJSModule;
-function CJSModuleInit() {
- if (!CJSModule)
- CJSModule = require('internal/modules/cjs/loader');
-}
+// TODO(joyeecheung): not every one of these are necessary
+prepareMainThreadExecution(true);
if (process.argv[1] && process.argv[1] !== '-') {
// Expand process.argv[1] into a full path.
const path = require('path');
process.argv[1] = path.resolve(process.argv[1]);
- // TODO(joyeecheung): not every one of these are necessary
- prepareMainThreadExecution();
- CJSModuleInit();
+ // This has to be done after prepareMainThreadExecution because it
+ // relies on process.execPath
+ const CJSModule = require('internal/modules/cjs/loader');
+
// Read the source.
const filename = CJSModule._resolveFilename(process.argv[1]);
@@ -42,9 +40,6 @@ if (process.argv[1] && process.argv[1] !== '-') {
checkSyntax(source, filename);
} else {
- // TODO(joyeecheung): not every one of these are necessary
- prepareMainThreadExecution();
- CJSModuleInit();
markBootstrapComplete();
readStdin((code) => {
@@ -56,6 +51,10 @@ function checkSyntax(source, filename) {
// Remove Shebang.
source = stripShebang(source);
+ // This has to be done after prepareMainThreadExecution because it
+ // relies on process.execPath
+ const CJSModule = require('internal/modules/cjs/loader');
+
const { getOptionValue } = require('internal/options');
const experimentalModules = getOptionValue('--experimental-modules');
if (experimentalModules) {
diff --git a/lib/internal/main/run_main_module.js b/lib/internal/main/run_main_module.js
index 634abe493e..8f9d256ecf 100644
--- a/lib/internal/main/run_main_module.js
+++ b/lib/internal/main/run_main_module.js
@@ -4,11 +4,7 @@ const {
prepareMainThreadExecution
} = require('internal/bootstrap/pre_execution');
-// Expand process.argv[1] into a full path.
-const path = require('path');
-process.argv[1] = path.resolve(process.argv[1]);
-
-prepareMainThreadExecution();
+prepareMainThreadExecution(true);
const CJSModule = require('internal/modules/cjs/loader');
diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js
index e0e1709bdb..71a2c4fa3a 100644
--- a/lib/internal/process/warning.js
+++ b/lib/internal/process/warning.js
@@ -1,6 +1,5 @@
'use strict';
-const prefix = `(${process.release.name}:${process.pid}) `;
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
// Lazily loaded
@@ -55,7 +54,7 @@ function onWarning(warning) {
if (isDeprecation && process.noDeprecation) return;
const trace = process.traceProcessWarnings ||
(isDeprecation && process.traceDeprecation);
- var msg = prefix;
+ var msg = `(${process.release.name}:${process.pid}) `;
if (warning.code)
msg += `[${warning.code}] `;
if (trace && warning.stack) {