summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-03-08 14:39:57 +0100
committerJoyee Cheung <joyeec9h3@gmail.com>2019-03-12 08:00:19 +0800
commit0a95c87dc660f593d532b9daae5ad0b13890b1c8 (patch)
treec707f4050b050f780e7b914c528644dc87a09579
parent728c939e57ec471bf0a114b86074829be622f421 (diff)
downloadandroid-node-v8-0a95c87dc660f593d532b9daae5ad0b13890b1c8.tar.gz
android-node-v8-0a95c87dc660f593d532b9daae5ad0b13890b1c8.tar.bz2
android-node-v8-0a95c87dc660f593d532b9daae5ad0b13890b1c8.zip
process: create legacy process properties during pre-execution
Shim legacy process object properties of CLI options during pre-execution instead of serializing them during bootstrap. PR-URL: https://github.com/nodejs/node/pull/26517 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
-rw-r--r--lib/internal/bootstrap/pre_execution.js31
-rw-r--r--src/node_process_object.cc89
2 files changed, 34 insertions, 86 deletions
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index 95203c470f..04083b53a2 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -57,13 +57,42 @@ function patchProcessObject() {
value: process.argv[0]
});
process.argv[0] = process.execPath;
+
+ // 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');
+ addReadOnlyProcessAlias('_print_eval', '--print');
+ addReadOnlyProcessAlias('_syntax_check_only', '--check');
+ addReadOnlyProcessAlias('_forceRepl', '--interactive');
+ addReadOnlyProcessAlias('_preload_modules', '--require');
+ addReadOnlyProcessAlias('noDeprecation', '--no-deprecation');
+ addReadOnlyProcessAlias('noProcessWarnings', '--no-warnings');
+ addReadOnlyProcessAlias('traceProcessWarnings', '--trace-warnings');
+ addReadOnlyProcessAlias('throwDeprecation', '--throw-deprecation');
+ addReadOnlyProcessAlias('profProcess', '--prof-process');
+ addReadOnlyProcessAlias('traceDeprecation', '--trace-deprecation');
+ addReadOnlyProcessAlias('_breakFirstLine', '--inspect-brk', false);
+ addReadOnlyProcessAlias('_breakNodeFirstLine', '--inspect-brk-node', false);
+}
+
+function addReadOnlyProcessAlias(name, option, enumerable = true) {
+ const value = getOptionValue(option);
+ if (value) {
+ Object.defineProperty(process, name, {
+ writable: false,
+ configurable: true,
+ enumerable,
+ value
+ });
+ }
}
function setupWarningHandler() {
const {
onWarning
} = require('internal/process/warning');
- if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') {
+ if (!getOptionValue('--no-warnings') &&
+ process.env.NODE_NO_WARNINGS !== '1') {
process.on('warning', onWarning);
}
}
diff --git a/src/node_process_object.cc b/src/node_process_object.cc
index c8a2c26690..0b97a5b213 100644
--- a/src/node_process_object.cc
+++ b/src/node_process_object.cc
@@ -158,91 +158,10 @@ MaybeLocal<Object> CreateProcessObject(
FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),
GetParentProcessId).FromJust());
- // TODO(joyeecheung): the following process properties that are set using
- // parsed CLI flags should be migrated to `internal/options` in JS land.
-
- // -e, --eval
- // TODO(addaleax): Remove this.
- if (env->options()->has_eval_string) {
- READONLY_PROPERTY(process,
- "_eval",
- String::NewFromUtf8(
- env->isolate(),
- env->options()->eval_string.c_str(),
- NewStringType::kNormal).ToLocalChecked());
- }
-
- // -p, --print
- // TODO(addaleax): Remove this.
- if (env->options()->print_eval) {
- READONLY_PROPERTY(process, "_print_eval", True(env->isolate()));
- }
-
- // -c, --check
- // TODO(addaleax): Remove this.
- if (env->options()->syntax_check_only) {
- READONLY_PROPERTY(process, "_syntax_check_only", True(env->isolate()));
- }
-
- // -i, --interactive
- // TODO(addaleax): Remove this.
- if (env->options()->force_repl) {
- READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
- }
-
- // -r, --require
- // TODO(addaleax): Remove this.
- const std::vector<std::string>& preload_modules =
- env->options()->preload_modules;
- if (!preload_modules.empty()) {
- READONLY_PROPERTY(process,
- "_preload_modules",
- ToV8Value(env->context(), preload_modules)
- .ToLocalChecked());
- }
-
- // --no-deprecation
- if (env->options()->no_deprecation) {
- READONLY_PROPERTY(process, "noDeprecation", True(env->isolate()));
- }
-
- // --no-warnings
- if (env->options()->no_warnings) {
- READONLY_PROPERTY(process, "noProcessWarnings", True(env->isolate()));
- }
-
- // --trace-warnings
- if (env->options()->trace_warnings) {
- READONLY_PROPERTY(process, "traceProcessWarnings", True(env->isolate()));
- }
-
- // --throw-deprecation
- if (env->options()->throw_deprecation) {
- READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate()));
- }
-
- // --prof-process
- // TODO(addaleax): Remove this.
- if (env->options()->prof_process) {
- READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
- }
-
- // --trace-deprecation
- if (env->options()->trace_deprecation) {
- READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
- }
-
- // --inspect-brk
- if (env->options()->debug_options().wait_for_connect()) {
- READONLY_DONT_ENUM_PROPERTY(process,
- "_breakFirstLine", True(env->isolate()));
- }
-
- // --inspect-brk-node
- if (env->options()->debug_options().break_node_first_line) {
- READONLY_DONT_ENUM_PROPERTY(process,
- "_breakNodeFirstLine", True(env->isolate()));
- }
+ // TODO(joyeecheung): make this available in JS during pre-execution.
+ // Note that to use this in releases the code doing the revert need to be
+ // careful to delay the check until after the bootstrap but that may not
+ // be possible depending on the feature being reverted.
// --security-revert flags
#define V(code, _, __) \