Skip to content

Commit e0bd2f3

Browse files
addaleaxBridgeAR
authored andcommitted
src: move Environment ctor/dtor into env.cc
This makes it easier to use methods from other headers in the constructor and destructor. PR-URL: #19202 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent f96bd54 commit e0bd2f3

File tree

3 files changed

+62
-63
lines changed

3 files changed

+62
-63
lines changed

src/env-inl.h

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -318,67 +318,6 @@ inline Environment* Environment::GetThreadLocalEnv() {
318318
return static_cast<Environment*>(uv_key_get(&thread_local_env));
319319
}
320320

321-
inline Environment::Environment(IsolateData* isolate_data,
322-
v8::Local<v8::Context> context)
323-
: isolate_(context->GetIsolate()),
324-
isolate_data_(isolate_data),
325-
immediate_info_(context->GetIsolate()),
326-
tick_info_(context->GetIsolate()),
327-
timer_base_(uv_now(isolate_data->event_loop())),
328-
printed_error_(false),
329-
trace_sync_io_(false),
330-
abort_on_uncaught_exception_(false),
331-
emit_napi_warning_(true),
332-
emit_env_nonstring_warning_(true),
333-
makecallback_cntr_(0),
334-
should_abort_on_uncaught_toggle_(isolate_, 1),
335-
#if HAVE_INSPECTOR
336-
inspector_agent_(new inspector::Agent(this)),
337-
#endif
338-
handle_cleanup_waiting_(0),
339-
http_parser_buffer_(nullptr),
340-
fs_stats_field_array_(isolate_, kFsStatsFieldsLength),
341-
context_(context->GetIsolate(), context) {
342-
// We'll be creating new objects so make sure we've entered the context.
343-
v8::HandleScope handle_scope(isolate());
344-
v8::Context::Scope context_scope(context);
345-
set_as_external(v8::External::New(isolate(), this));
346-
347-
AssignToContext(context, ContextInfo(""));
348-
349-
destroy_async_id_list_.reserve(512);
350-
performance_state_.reset(new performance::performance_state(isolate()));
351-
performance_state_->milestones[
352-
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] =
353-
PERFORMANCE_NOW();
354-
performance_state_->milestones[
355-
performance::NODE_PERFORMANCE_MILESTONE_NODE_START] =
356-
performance::performance_node_start;
357-
performance_state_->milestones[
358-
performance::NODE_PERFORMANCE_MILESTONE_V8_START] =
359-
performance::performance_v8_start;
360-
361-
// By default, always abort when --abort-on-uncaught-exception was passed.
362-
should_abort_on_uncaught_toggle_[0] = 1;
363-
}
364-
365-
inline Environment::~Environment() {
366-
v8::HandleScope handle_scope(isolate());
367-
368-
#if HAVE_INSPECTOR
369-
// Destroy inspector agent before erasing the context. The inspector
370-
// destructor depends on the context still being accessible.
371-
inspector_agent_.reset();
372-
#endif
373-
374-
context()->SetAlignedPointerInEmbedderData(
375-
ContextEmbedderIndex::kEnvironment, nullptr);
376-
377-
delete[] heap_statistics_buffer_;
378-
delete[] heap_space_statistics_buffer_;
379-
delete[] http_parser_buffer_;
380-
}
381-
382321
inline v8::Isolate* Environment::isolate() const {
383322
return isolate_;
384323
}

src/env.cc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,66 @@ void InitThreadLocalOnce() {
8585
CHECK_EQ(0, uv_key_create(&Environment::thread_local_env));
8686
}
8787

88+
Environment::Environment(IsolateData* isolate_data,
89+
Local<Context> context)
90+
: isolate_(context->GetIsolate()),
91+
isolate_data_(isolate_data),
92+
immediate_info_(context->GetIsolate()),
93+
tick_info_(context->GetIsolate()),
94+
timer_base_(uv_now(isolate_data->event_loop())),
95+
printed_error_(false),
96+
trace_sync_io_(false),
97+
abort_on_uncaught_exception_(false),
98+
emit_napi_warning_(true),
99+
makecallback_cntr_(0),
100+
should_abort_on_uncaught_toggle_(isolate_, 1),
101+
#if HAVE_INSPECTOR
102+
inspector_agent_(new inspector::Agent(this)),
103+
#endif
104+
handle_cleanup_waiting_(0),
105+
http_parser_buffer_(nullptr),
106+
fs_stats_field_array_(isolate_, kFsStatsFieldsLength),
107+
context_(context->GetIsolate(), context) {
108+
// We'll be creating new objects so make sure we've entered the context.
109+
v8::HandleScope handle_scope(isolate());
110+
v8::Context::Scope context_scope(context);
111+
set_as_external(v8::External::New(isolate(), this));
112+
113+
AssignToContext(context, ContextInfo(""));
114+
115+
destroy_async_id_list_.reserve(512);
116+
performance_state_.reset(new performance::performance_state(isolate()));
117+
performance_state_->milestones[
118+
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] =
119+
PERFORMANCE_NOW();
120+
performance_state_->milestones[
121+
performance::NODE_PERFORMANCE_MILESTONE_NODE_START] =
122+
performance::performance_node_start;
123+
performance_state_->milestones[
124+
performance::NODE_PERFORMANCE_MILESTONE_V8_START] =
125+
performance::performance_v8_start;
126+
127+
// By default, always abort when --abort-on-uncaught-exception was passed.
128+
should_abort_on_uncaught_toggle_[0] = 1;
129+
}
130+
131+
Environment::~Environment() {
132+
v8::HandleScope handle_scope(isolate());
133+
134+
#if HAVE_INSPECTOR
135+
// Destroy inspector agent before erasing the context. The inspector
136+
// destructor depends on the context still being accessible.
137+
inspector_agent_.reset();
138+
#endif
139+
140+
context()->SetAlignedPointerInEmbedderData(
141+
ContextEmbedderIndex::kEnvironment, nullptr);
142+
143+
delete[] heap_statistics_buffer_;
144+
delete[] heap_space_statistics_buffer_;
145+
delete[] http_parser_buffer_;
146+
}
147+
88148
void Environment::Start(int argc,
89149
const char* const* argv,
90150
int exec_argc,

src/env.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ class Environment {
561561
static uv_key_t thread_local_env;
562562
static inline Environment* GetThreadLocalEnv();
563563

564-
inline Environment(IsolateData* isolate_data, v8::Local<v8::Context> context);
565-
inline ~Environment();
564+
Environment(IsolateData* isolate_data, v8::Local<v8::Context> context);
565+
~Environment();
566566

567567
void Start(int argc,
568568
const char* const* argv,

0 commit comments

Comments
 (0)