Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70f8e71

Browse filesBrowse files
joyeecheungBridgeAR
authored andcommitted
src: inline ProcessCliArgs in the Environment constructor
Inline `ProcessCliArgs()` in the `Environment` constructor, and emit the `Environment` creation trace events with the arguments earlier. Remove the unused arguments passed to `CreateProcessObject()` since these are now attached to process in `PatchProcessObject()` during pre-execution instead. PR-URL: #27539 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent f8c9a58 commit 70f8e71
Copy full SHA for 70f8e71

File tree

Expand file treeCollapse file tree

7 files changed

+32
-43
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+32
-43
lines changed
Open diff view settings
Collapse file

‎src/api/environment.cc‎

Copy file name to clipboardExpand all lines: src/api/environment.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,12 @@ Environment* CreateEnvironment(IsolateData* isolate_data,
281281
Environment* env = new Environment(
282282
isolate_data,
283283
context,
284+
args,
285+
exec_args,
284286
static_cast<Environment::Flags>(Environment::kIsMainThread |
285287
Environment::kOwnsProcessState |
286288
Environment::kOwnsInspector));
287289
env->InitializeLibuv(per_process::v8_is_profiling);
288-
env->ProcessCliArgs(args, exec_args);
289290
if (RunBootstrapping(env).IsEmpty()) {
290291
return nullptr;
291292
}
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+22-29Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,17 @@ uint64_t Environment::AllocateThreadId() {
237237

238238
Environment::Environment(IsolateData* isolate_data,
239239
Local<Context> context,
240+
const std::vector<std::string>& args,
241+
const std::vector<std::string>& exec_args,
240242
Flags flags,
241243
uint64_t thread_id)
242244
: isolate_(context->GetIsolate()),
243245
isolate_data_(isolate_data),
244246
immediate_info_(context->GetIsolate()),
245247
tick_info_(context->GetIsolate()),
246248
timer_base_(uv_now(isolate_data->event_loop())),
249+
exec_argv_(exec_args),
250+
argv_(args),
247251
should_abort_on_uncaught_toggle_(isolate_, 1),
248252
stream_base_state_(isolate_, StreamBase::kNumStreamBaseStateFields),
249253
flags_(flags),
@@ -306,6 +310,22 @@ Environment::Environment(IsolateData* isolate_data,
306310
performance::NODE_PERFORMANCE_MILESTONE_V8_START,
307311
performance::performance_v8_start);
308312

313+
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
314+
TRACING_CATEGORY_NODE1(environment)) != 0) {
315+
auto traced_value = tracing::TracedValue::Create();
316+
traced_value->BeginArray("args");
317+
for (const std::string& arg : args) traced_value->AppendString(arg);
318+
traced_value->EndArray();
319+
traced_value->BeginArray("exec_args");
320+
for (const std::string& arg : exec_args) traced_value->AppendString(arg);
321+
traced_value->EndArray();
322+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE1(environment),
323+
"Environment",
324+
this,
325+
"args",
326+
std::move(traced_value));
327+
}
328+
309329
// By default, always abort when --abort-on-uncaught-exception was passed.
310330
should_abort_on_uncaught_toggle_[0] = 1;
311331

@@ -318,6 +338,8 @@ Environment::Environment(IsolateData* isolate_data,
318338
if (options_->no_force_async_hooks_checks) {
319339
async_hooks_.no_force_checks();
320340
}
341+
342+
set_process_object(node::CreateProcessObject(this).ToLocalChecked());
321343
}
322344

323345
CompileFnEntry::CompileFnEntry(Environment* env, uint32_t id)
@@ -434,35 +456,6 @@ void Environment::ExitEnv() {
434456
isolate_->TerminateExecution();
435457
}
436458

437-
MaybeLocal<Object> Environment::ProcessCliArgs(
438-
const std::vector<std::string>& args,
439-
const std::vector<std::string>& exec_args) {
440-
argv_ = args;
441-
exec_argv_ = exec_args;
442-
443-
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
444-
TRACING_CATEGORY_NODE1(environment)) != 0) {
445-
auto traced_value = tracing::TracedValue::Create();
446-
traced_value->BeginArray("args");
447-
for (const std::string& arg : args) traced_value->AppendString(arg);
448-
traced_value->EndArray();
449-
traced_value->BeginArray("exec_args");
450-
for (const std::string& arg : exec_args) traced_value->AppendString(arg);
451-
traced_value->EndArray();
452-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE1(environment),
453-
"Environment",
454-
this,
455-
"args",
456-
std::move(traced_value));
457-
}
458-
459-
Local<Object> process_object =
460-
node::CreateProcessObject(this, args, exec_args)
461-
.FromMaybe(Local<Object>());
462-
set_process_object(process_object);
463-
return process_object;
464-
}
465-
466459
void Environment::RegisterHandleCleanups() {
467460
HandleCleanupCb close_and_finish = [](Environment* env, uv_handle_t* handle,
468461
void* arg) {
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,14 +823,13 @@ class Environment : public MemoryRetainer {
823823

824824
Environment(IsolateData* isolate_data,
825825
v8::Local<v8::Context> context,
826+
const std::vector<std::string>& args,
827+
const std::vector<std::string>& exec_args,
826828
Flags flags = Flags(),
827829
uint64_t thread_id = kNoThreadId);
828830
~Environment();
829831

830832
void InitializeLibuv(bool start_profiler_idle_notifier);
831-
v8::MaybeLocal<v8::Object> ProcessCliArgs(
832-
const std::vector<std::string>& args,
833-
const std::vector<std::string>& exec_args);
834833
inline const std::vector<std::string>& exec_argv();
835834
inline const std::vector<std::string>& argv();
836835

Collapse file

‎src/node_main_instance.cc‎

Copy file name to clipboardExpand all lines: src/node_main_instance.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
188188
std::unique_ptr<Environment> env = std::make_unique<Environment>(
189189
isolate_data_.get(),
190190
context,
191+
args_,
192+
exec_args_,
191193
static_cast<Environment::Flags>(Environment::kIsMainThread |
192194
Environment::kOwnsProcessState |
193195
Environment::kOwnsInspector));
194196
env->InitializeLibuv(per_process::v8_is_profiling);
195-
env->ProcessCliArgs(args_, exec_args_);
196197

197198
#if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM
198199
CHECK(!env->inspector_agent()->IsListening());
Collapse file

‎src/node_process.h‎

Copy file name to clipboardExpand all lines: src/node_process.h
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
3131
const char* warning,
3232
const char* deprecation_code);
3333

34-
v8::MaybeLocal<v8::Object> CreateProcessObject(
35-
Environment* env,
36-
const std::vector<std::string>& args,
37-
const std::vector<std::string>& exec_args);
34+
v8::MaybeLocal<v8::Object> CreateProcessObject(Environment* env);
3835
void PatchProcessObject(const v8::FunctionCallbackInfo<v8::Value>& args);
3936

4037
namespace task_queue {
Collapse file

‎src/node_process_object.cc‎

Copy file name to clipboardExpand all lines: src/node_process_object.cc
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ static void GetParentProcessId(Local<Name> property,
6868
info.GetReturnValue().Set(uv_os_getppid());
6969
}
7070

71-
MaybeLocal<Object> CreateProcessObject(
72-
Environment* env,
73-
const std::vector<std::string>& args,
74-
const std::vector<std::string>& exec_args) {
71+
MaybeLocal<Object> CreateProcessObject(Environment* env) {
7572
Isolate* isolate = env->isolate();
7673
EscapableHandleScope scope(isolate);
7774
Local<Context> context = env->context();
Collapse file

‎src/node_worker.cc‎

Copy file name to clipboardExpand all lines: src/node_worker.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ void Worker::Run() {
256256
// public API.
257257
env_.reset(new Environment(data.isolate_data_.get(),
258258
context,
259+
std::move(argv_),
260+
std::move(exec_argv_),
259261
Environment::kNoFlags,
260262
thread_id_));
261263
CHECK_NOT_NULL(env_);
@@ -264,7 +266,6 @@ void Worker::Run() {
264266
env_->set_worker_context(this);
265267

266268
env_->InitializeLibuv(profiler_idle_notifier_started_);
267-
env_->ProcessCliArgs(std::move(argv_), std::move(exec_argv_));
268269
}
269270
{
270271
Mutex::ScopedLock lock(mutex_);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.