From 2ee4bb78267b76b872d19dd01403f240144f770f Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 6 Mar 2018 19:05:42 +0100 Subject: [PATCH] src: move `Environment` ctor/dtor into env.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it easier to use methods from other headers in the constructor and destructor. Backport-PR-URL: https://github.com/nodejs/node/pull/21599 PR-URL: https://github.com/nodejs/node/pull/19202 Reviewed-By: Joyee Cheung Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell Reviewed-By: Daniel Bevenius Reviewed-By: Colin Ihrig --- src/env-inl.h | 70 --------------------------------------------------- src/env.cc | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/env.h | 4 +-- 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 5860c5219696fd..cb501d1dae5dc7 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -277,76 +277,6 @@ inline Environment* Environment::GetCurrent( info.Data().template As()->Value()); } -inline Environment::Environment(IsolateData* isolate_data, - v8::Local context) - : isolate_(context->GetIsolate()), - isolate_data_(isolate_data), - timer_base_(uv_now(isolate_data->event_loop())), - using_domains_(false), - printed_error_(false), - trace_sync_io_(false), - abort_on_uncaught_exception_(false), - makecallback_cntr_(0), - scheduled_immediate_count_(isolate_, 1), -#if HAVE_INSPECTOR - inspector_agent_(new inspector::Agent(this)), -#endif - handle_cleanup_waiting_(0), - http_parser_buffer_(nullptr), - fs_stats_field_array_(nullptr), - context_(context->GetIsolate(), context) { - // We'll be creating new objects so make sure we've entered the context. - v8::HandleScope handle_scope(isolate()); - v8::Context::Scope context_scope(context); - set_as_external(v8::External::New(isolate(), this)); - - v8::Local null = v8::Null(isolate()); - v8::Local binding_cache_object = v8::Object::New(isolate()); - CHECK(binding_cache_object->SetPrototype(context, null).FromJust()); - set_binding_cache_object(binding_cache_object); - - v8::Local internal_binding_cache_object = - v8::Object::New(isolate()); - CHECK(internal_binding_cache_object->SetPrototype(context, null).FromJust()); - set_internal_binding_cache_object(internal_binding_cache_object); - - set_module_load_list_array(v8::Array::New(isolate())); - - AssignToContext(context); - - destroy_async_id_list_.reserve(512); - performance_state_.reset(new performance::performance_state(isolate())); - performance_state_->milestones[ - performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] = - PERFORMANCE_NOW(); - performance_state_->milestones[ - performance::NODE_PERFORMANCE_MILESTONE_NODE_START] = - performance::performance_node_start; - performance_state_->milestones[ - performance::NODE_PERFORMANCE_MILESTONE_V8_START] = - performance::performance_v8_start; -} - -inline Environment::~Environment() { - v8::HandleScope handle_scope(isolate()); - -#if HAVE_INSPECTOR - // Destroy inspector agent before erasing the context. The inspector - // destructor depends on the context still being accessible. - inspector_agent_.reset(); -#endif - - context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, - nullptr); -#define V(PropertyName, TypeName) PropertyName ## _.Reset(); - ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) -#undef V - - delete[] heap_statistics_buffer_; - delete[] heap_space_statistics_buffer_; - delete[] http_parser_buffer_; -} - inline v8::Isolate* Environment::isolate() const { return isolate_; } diff --git a/src/env.cc b/src/env.cc index 60a00e288e4777..1562caf0a8cbf2 100644 --- a/src/env.cc +++ b/src/env.cc @@ -77,6 +77,76 @@ IsolateData::~IsolateData() { platform_->UnregisterIsolate(this); } +Environment::Environment(IsolateData* isolate_data, + Local context) + : isolate_(context->GetIsolate()), + isolate_data_(isolate_data), + timer_base_(uv_now(isolate_data->event_loop())), + using_domains_(false), + printed_error_(false), + trace_sync_io_(false), + abort_on_uncaught_exception_(false), + makecallback_cntr_(0), + scheduled_immediate_count_(isolate_, 1), +#if HAVE_INSPECTOR + inspector_agent_(new inspector::Agent(this)), +#endif + handle_cleanup_waiting_(0), + http_parser_buffer_(nullptr), + fs_stats_field_array_(nullptr), + context_(context->GetIsolate(), context) { + // We'll be creating new objects so make sure we've entered the context. + v8::HandleScope handle_scope(isolate()); + v8::Context::Scope context_scope(context); + set_as_external(v8::External::New(isolate(), this)); + + v8::Local null = v8::Null(isolate()); + v8::Local binding_cache_object = v8::Object::New(isolate()); + CHECK(binding_cache_object->SetPrototype(context, null).FromJust()); + set_binding_cache_object(binding_cache_object); + + v8::Local internal_binding_cache_object = + v8::Object::New(isolate()); + CHECK(internal_binding_cache_object->SetPrototype(context, null).FromJust()); + set_internal_binding_cache_object(internal_binding_cache_object); + + set_module_load_list_array(v8::Array::New(isolate())); + + AssignToContext(context); + + destroy_async_id_list_.reserve(512); + performance_state_.reset(new performance::performance_state(isolate())); + performance_state_->milestones[ + performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] = + PERFORMANCE_NOW(); + performance_state_->milestones[ + performance::NODE_PERFORMANCE_MILESTONE_NODE_START] = + performance::performance_node_start; + performance_state_->milestones[ + performance::NODE_PERFORMANCE_MILESTONE_V8_START] = + performance::performance_v8_start; +} + +Environment::~Environment() { + v8::HandleScope handle_scope(isolate()); + +#if HAVE_INSPECTOR + // Destroy inspector agent before erasing the context. The inspector + // destructor depends on the context still being accessible. + inspector_agent_.reset(); +#endif + + context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, + nullptr); +#define V(PropertyName, TypeName) PropertyName ## _.Reset(); + ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) +#undef V + + delete[] heap_statistics_buffer_; + delete[] heap_space_statistics_buffer_; + delete[] http_parser_buffer_; +} + void Environment::Start(int argc, const char* const* argv, int exec_argc, diff --git a/src/env.h b/src/env.h index 3f831e02a060ac..076dbf66b7c59f 100644 --- a/src/env.h +++ b/src/env.h @@ -547,8 +547,8 @@ class Environment { static inline Environment* GetCurrent( const v8::PropertyCallbackInfo& info); - inline Environment(IsolateData* isolate_data, v8::Local context); - inline ~Environment(); + Environment(IsolateData* isolate_data, v8::Local context); + ~Environment(); void Start(int argc, const char* const* argv,