summaryrefslogtreecommitdiff
path: root/lib/internal/main
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/internal/main
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/internal/main')
-rw-r--r--lib/internal/main/check_syntax.js21
-rw-r--r--lib/internal/main/run_main_module.js6
2 files changed, 11 insertions, 16 deletions
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');