Skip to content

Commit 0a95c87

Browse files
committedMar 12, 2019
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: #26517 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 728c939 commit 0a95c87

File tree

2 files changed

+34
-86
lines changed

2 files changed

+34
-86
lines changed
 

‎lib/internal/bootstrap/pre_execution.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,42 @@ function patchProcessObject() {
5757
value: process.argv[0]
5858
});
5959
process.argv[0] = process.execPath;
60+
61+
// TODO(joyeecheung): most of these should be deprecated and removed,
62+
// execpt some that we need to be able to mutate during run time.
63+
addReadOnlyProcessAlias('_eval', '--eval');
64+
addReadOnlyProcessAlias('_print_eval', '--print');
65+
addReadOnlyProcessAlias('_syntax_check_only', '--check');
66+
addReadOnlyProcessAlias('_forceRepl', '--interactive');
67+
addReadOnlyProcessAlias('_preload_modules', '--require');
68+
addReadOnlyProcessAlias('noDeprecation', '--no-deprecation');
69+
addReadOnlyProcessAlias('noProcessWarnings', '--no-warnings');
70+
addReadOnlyProcessAlias('traceProcessWarnings', '--trace-warnings');
71+
addReadOnlyProcessAlias('throwDeprecation', '--throw-deprecation');
72+
addReadOnlyProcessAlias('profProcess', '--prof-process');
73+
addReadOnlyProcessAlias('traceDeprecation', '--trace-deprecation');
74+
addReadOnlyProcessAlias('_breakFirstLine', '--inspect-brk', false);
75+
addReadOnlyProcessAlias('_breakNodeFirstLine', '--inspect-brk-node', false);
76+
}
77+
78+
function addReadOnlyProcessAlias(name, option, enumerable = true) {
79+
const value = getOptionValue(option);
80+
if (value) {
81+
Object.defineProperty(process, name, {
82+
writable: false,
83+
configurable: true,
84+
enumerable,
85+
value
86+
});
87+
}
6088
}
6189

6290
function setupWarningHandler() {
6391
const {
6492
onWarning
6593
} = require('internal/process/warning');
66-
if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') {
94+
if (!getOptionValue('--no-warnings') &&
95+
process.env.NODE_NO_WARNINGS !== '1') {
6796
process.on('warning', onWarning);
6897
}
6998
}

‎src/node_process_object.cc

+4-85
Original file line numberDiff line numberDiff line change
@@ -158,91 +158,10 @@ MaybeLocal<Object> CreateProcessObject(
158158
FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),
159159
GetParentProcessId).FromJust());
160160

161-
// TODO(joyeecheung): the following process properties that are set using
162-
// parsed CLI flags should be migrated to `internal/options` in JS land.
163-
164-
// -e, --eval
165-
// TODO(addaleax): Remove this.
166-
if (env->options()->has_eval_string) {
167-
READONLY_PROPERTY(process,
168-
"_eval",
169-
String::NewFromUtf8(
170-
env->isolate(),
171-
env->options()->eval_string.c_str(),
172-
NewStringType::kNormal).ToLocalChecked());
173-
}
174-
175-
// -p, --print
176-
// TODO(addaleax): Remove this.
177-
if (env->options()->print_eval) {
178-
READONLY_PROPERTY(process, "_print_eval", True(env->isolate()));
179-
}
180-
181-
// -c, --check
182-
// TODO(addaleax): Remove this.
183-
if (env->options()->syntax_check_only) {
184-
READONLY_PROPERTY(process, "_syntax_check_only", True(env->isolate()));
185-
}
186-
187-
// -i, --interactive
188-
// TODO(addaleax): Remove this.
189-
if (env->options()->force_repl) {
190-
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
191-
}
192-
193-
// -r, --require
194-
// TODO(addaleax): Remove this.
195-
const std::vector<std::string>& preload_modules =
196-
env->options()->preload_modules;
197-
if (!preload_modules.empty()) {
198-
READONLY_PROPERTY(process,
199-
"_preload_modules",
200-
ToV8Value(env->context(), preload_modules)
201-
.ToLocalChecked());
202-
}
203-
204-
// --no-deprecation
205-
if (env->options()->no_deprecation) {
206-
READONLY_PROPERTY(process, "noDeprecation", True(env->isolate()));
207-
}
208-
209-
// --no-warnings
210-
if (env->options()->no_warnings) {
211-
READONLY_PROPERTY(process, "noProcessWarnings", True(env->isolate()));
212-
}
213-
214-
// --trace-warnings
215-
if (env->options()->trace_warnings) {
216-
READONLY_PROPERTY(process, "traceProcessWarnings", True(env->isolate()));
217-
}
218-
219-
// --throw-deprecation
220-
if (env->options()->throw_deprecation) {
221-
READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate()));
222-
}
223-
224-
// --prof-process
225-
// TODO(addaleax): Remove this.
226-
if (env->options()->prof_process) {
227-
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
228-
}
229-
230-
// --trace-deprecation
231-
if (env->options()->trace_deprecation) {
232-
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
233-
}
234-
235-
// --inspect-brk
236-
if (env->options()->debug_options().wait_for_connect()) {
237-
READONLY_DONT_ENUM_PROPERTY(process,
238-
"_breakFirstLine", True(env->isolate()));
239-
}
240-
241-
// --inspect-brk-node
242-
if (env->options()->debug_options().break_node_first_line) {
243-
READONLY_DONT_ENUM_PROPERTY(process,
244-
"_breakNodeFirstLine", True(env->isolate()));
245-
}
161+
// TODO(joyeecheung): make this available in JS during pre-execution.
162+
// Note that to use this in releases the code doing the revert need to be
163+
// careful to delay the check until after the bootstrap but that may not
164+
// be possible depending on the feature being reverted.
246165

247166
// --security-revert flags
248167
#define V(code, _, __) \

0 commit comments

Comments
 (0)
Please sign in to comment.