diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-03-06 19:05:42 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-03-11 04:01:51 +0100 |
commit | e0bd2f31e584d8b188148084f97e80bc1573e555 (patch) | |
tree | 87ca441af0b47b67a8809a608450bdc9f73e4b29 /src/env.cc | |
parent | f96bd54dd54c66970e8d268503fc77803cb9dbfc (diff) | |
download | android-node-v8-e0bd2f31e584d8b188148084f97e80bc1573e555.tar.gz android-node-v8-e0bd2f31e584d8b188148084f97e80bc1573e555.tar.bz2 android-node-v8-e0bd2f31e584d8b188148084f97e80bc1573e555.zip |
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src/env.cc')
-rw-r--r-- | src/env.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc index f02cb36fe5..6e090679c2 100644 --- a/src/env.cc +++ b/src/env.cc @@ -85,6 +85,66 @@ void InitThreadLocalOnce() { CHECK_EQ(0, uv_key_create(&Environment::thread_local_env)); } +Environment::Environment(IsolateData* isolate_data, + Local<Context> context) + : isolate_(context->GetIsolate()), + isolate_data_(isolate_data), + immediate_info_(context->GetIsolate()), + tick_info_(context->GetIsolate()), + timer_base_(uv_now(isolate_data->event_loop())), + printed_error_(false), + trace_sync_io_(false), + abort_on_uncaught_exception_(false), + emit_napi_warning_(true), + makecallback_cntr_(0), + should_abort_on_uncaught_toggle_(isolate_, 1), +#if HAVE_INSPECTOR + inspector_agent_(new inspector::Agent(this)), +#endif + handle_cleanup_waiting_(0), + http_parser_buffer_(nullptr), + fs_stats_field_array_(isolate_, kFsStatsFieldsLength), + 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)); + + AssignToContext(context, ContextInfo("")); + + 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; + + // By default, always abort when --abort-on-uncaught-exception was passed. + should_abort_on_uncaught_toggle_[0] = 1; +} + +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( + ContextEmbedderIndex::kEnvironment, nullptr); + + 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, |