Skip to content

Commit 2ee4bb7

Browse files
addaleaxrvagg
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. Backport-PR-URL: #21599 PR-URL: #19202 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 8053474 commit 2ee4bb7

File tree

3 files changed

+72
-72
lines changed

3 files changed

+72
-72
lines changed

src/env-inl.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -277,76 +277,6 @@ inline Environment* Environment::GetCurrent(
277277
info.Data().template As<v8::External>()->Value());
278278
}
279279

280-
inline Environment::Environment(IsolateData* isolate_data,
281-
v8::Local<v8::Context> context)
282-
: isolate_(context->GetIsolate()),
283-
isolate_data_(isolate_data),
284-
timer_base_(uv_now(isolate_data->event_loop())),
285-
using_domains_(false),
286-
printed_error_(false),
287-
trace_sync_io_(false),
288-
abort_on_uncaught_exception_(false),
289-
makecallback_cntr_(0),
290-
scheduled_immediate_count_(isolate_, 1),
291-
#if HAVE_INSPECTOR
292-
inspector_agent_(new inspector::Agent(this)),
293-
#endif
294-
handle_cleanup_waiting_(0),
295-
http_parser_buffer_(nullptr),
296-
fs_stats_field_array_(nullptr),
297-
context_(context->GetIsolate(), context) {
298-
// We'll be creating new objects so make sure we've entered the context.
299-
v8::HandleScope handle_scope(isolate());
300-
v8::Context::Scope context_scope(context);
301-
set_as_external(v8::External::New(isolate(), this));
302-
303-
v8::Local<v8::Primitive> null = v8::Null(isolate());
304-
v8::Local<v8::Object> binding_cache_object = v8::Object::New(isolate());
305-
CHECK(binding_cache_object->SetPrototype(context, null).FromJust());
306-
set_binding_cache_object(binding_cache_object);
307-
308-
v8::Local<v8::Object> internal_binding_cache_object =
309-
v8::Object::New(isolate());
310-
CHECK(internal_binding_cache_object->SetPrototype(context, null).FromJust());
311-
set_internal_binding_cache_object(internal_binding_cache_object);
312-
313-
set_module_load_list_array(v8::Array::New(isolate()));
314-
315-
AssignToContext(context);
316-
317-
destroy_async_id_list_.reserve(512);
318-
performance_state_.reset(new performance::performance_state(isolate()));
319-
performance_state_->milestones[
320-
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] =
321-
PERFORMANCE_NOW();
322-
performance_state_->milestones[
323-
performance::NODE_PERFORMANCE_MILESTONE_NODE_START] =
324-
performance::performance_node_start;
325-
performance_state_->milestones[
326-
performance::NODE_PERFORMANCE_MILESTONE_V8_START] =
327-
performance::performance_v8_start;
328-
}
329-
330-
inline Environment::~Environment() {
331-
v8::HandleScope handle_scope(isolate());
332-
333-
#if HAVE_INSPECTOR
334-
// Destroy inspector agent before erasing the context. The inspector
335-
// destructor depends on the context still being accessible.
336-
inspector_agent_.reset();
337-
#endif
338-
339-
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
340-
nullptr);
341-
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
342-
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
343-
#undef V
344-
345-
delete[] heap_statistics_buffer_;
346-
delete[] heap_space_statistics_buffer_;
347-
delete[] http_parser_buffer_;
348-
}
349-
350280
inline v8::Isolate* Environment::isolate() const {
351281
return isolate_;
352282
}

src/env.cc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,76 @@ IsolateData::~IsolateData() {
7777
platform_->UnregisterIsolate(this);
7878
}
7979

80+
Environment::Environment(IsolateData* isolate_data,
81+
Local<Context> context)
82+
: isolate_(context->GetIsolate()),
83+
isolate_data_(isolate_data),
84+
timer_base_(uv_now(isolate_data->event_loop())),
85+
using_domains_(false),
86+
printed_error_(false),
87+
trace_sync_io_(false),
88+
abort_on_uncaught_exception_(false),
89+
makecallback_cntr_(0),
90+
scheduled_immediate_count_(isolate_, 1),
91+
#if HAVE_INSPECTOR
92+
inspector_agent_(new inspector::Agent(this)),
93+
#endif
94+
handle_cleanup_waiting_(0),
95+
http_parser_buffer_(nullptr),
96+
fs_stats_field_array_(nullptr),
97+
context_(context->GetIsolate(), context) {
98+
// We'll be creating new objects so make sure we've entered the context.
99+
v8::HandleScope handle_scope(isolate());
100+
v8::Context::Scope context_scope(context);
101+
set_as_external(v8::External::New(isolate(), this));
102+
103+
v8::Local<v8::Primitive> null = v8::Null(isolate());
104+
v8::Local<v8::Object> binding_cache_object = v8::Object::New(isolate());
105+
CHECK(binding_cache_object->SetPrototype(context, null).FromJust());
106+
set_binding_cache_object(binding_cache_object);
107+
108+
v8::Local<v8::Object> internal_binding_cache_object =
109+
v8::Object::New(isolate());
110+
CHECK(internal_binding_cache_object->SetPrototype(context, null).FromJust());
111+
set_internal_binding_cache_object(internal_binding_cache_object);
112+
113+
set_module_load_list_array(v8::Array::New(isolate()));
114+
115+
AssignToContext(context);
116+
117+
destroy_async_id_list_.reserve(512);
118+
performance_state_.reset(new performance::performance_state(isolate()));
119+
performance_state_->milestones[
120+
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] =
121+
PERFORMANCE_NOW();
122+
performance_state_->milestones[
123+
performance::NODE_PERFORMANCE_MILESTONE_NODE_START] =
124+
performance::performance_node_start;
125+
performance_state_->milestones[
126+
performance::NODE_PERFORMANCE_MILESTONE_V8_START] =
127+
performance::performance_v8_start;
128+
}
129+
130+
Environment::~Environment() {
131+
v8::HandleScope handle_scope(isolate());
132+
133+
#if HAVE_INSPECTOR
134+
// Destroy inspector agent before erasing the context. The inspector
135+
// destructor depends on the context still being accessible.
136+
inspector_agent_.reset();
137+
#endif
138+
139+
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
140+
nullptr);
141+
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
142+
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
143+
#undef V
144+
145+
delete[] heap_statistics_buffer_;
146+
delete[] heap_space_statistics_buffer_;
147+
delete[] http_parser_buffer_;
148+
}
149+
80150
void Environment::Start(int argc,
81151
const char* const* argv,
82152
int exec_argc,

src/env.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ class Environment {
547547
static inline Environment* GetCurrent(
548548
const v8::PropertyCallbackInfo<T>& info);
549549

550-
inline Environment(IsolateData* isolate_data, v8::Local<v8::Context> context);
551-
inline ~Environment();
550+
Environment(IsolateData* isolate_data, v8::Local<v8::Context> context);
551+
~Environment();
552552

553553
void Start(int argc,
554554
const char* const* argv,

0 commit comments

Comments
 (0)