From 0301ce9f55d84c9a828b9e8571ab8ca0bd85b51f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 31 May 2016 14:29:22 +0200 Subject: [PATCH] src: move IsolateData out of Environment A follow-up commit is going to make IsolateData creation explicit. In order for that to work, it needs to move out of Environment. PR-URL: https://github.com/nodejs/node/pull/7082 Reviewed-By: James M Snell Reviewed-By: Trevor Norris --- src/env-inl.h | 20 ++++++------ src/env.h | 85 +++++++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 55 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 97e1ba8f76..a8a7d02552 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -15,13 +15,12 @@ namespace node { -inline Environment::IsolateData* Environment::IsolateData::Get( - v8::Isolate* isolate) { +inline IsolateData* IsolateData::Get(v8::Isolate* isolate) { return static_cast(isolate->GetData(kIsolateSlot)); } -inline Environment::IsolateData* Environment::IsolateData::GetOrCreate( - v8::Isolate* isolate, uv_loop_t* loop) { +inline IsolateData* IsolateData::GetOrCreate(v8::Isolate* isolate, + uv_loop_t* loop) { IsolateData* isolate_data = Get(isolate); if (isolate_data == nullptr) { isolate_data = new IsolateData(isolate, loop); @@ -31,7 +30,7 @@ inline Environment::IsolateData* Environment::IsolateData::GetOrCreate( return isolate_data; } -inline void Environment::IsolateData::Put() { +inline void IsolateData::Put() { if (--ref_count_ == 0) { isolate()->SetData(kIsolateSlot, nullptr); delete this; @@ -47,8 +46,7 @@ inline void Environment::IsolateData::Put() { // // One byte because our strings are ASCII and we can safely skip V8's UTF-8 // decoding step. It's a one-time cost, but why pay it when you don't have to? -inline Environment::IsolateData::IsolateData(v8::Isolate* isolate, - uv_loop_t* loop) +inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* loop) : event_loop_(loop), isolate_(isolate), #define V(PropertyName, StringValue) \ @@ -75,11 +73,11 @@ inline Environment::IsolateData::IsolateData(v8::Isolate* isolate, #undef V ref_count_(0) {} -inline uv_loop_t* Environment::IsolateData::event_loop() const { +inline uv_loop_t* IsolateData::event_loop() const { return event_loop_; } -inline v8::Isolate* Environment::IsolateData::isolate() const { +inline v8::Isolate* IsolateData::isolate() const { return isolate_; } @@ -432,7 +430,7 @@ inline ares_task_list* Environment::cares_task_list() { return &cares_task_list_; } -inline Environment::IsolateData* Environment::isolate_data() const { +inline IsolateData* Environment::isolate_data() const { return isolate_data_; } @@ -543,7 +541,7 @@ inline v8::Local Environment::NewInternalFieldObject() { #define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue) #define V(TypeName, PropertyName, StringValue) \ inline \ - v8::Local Environment::IsolateData::PropertyName() const { \ + v8::Local IsolateData::PropertyName() const { \ /* Strings are immutable so casting away const-ness here is okay. */ \ return const_cast(this)->PropertyName ## _.Get(isolate()); \ } diff --git a/src/env.h b/src/env.h index 4c310c8831..bbbd3f4b36 100644 --- a/src/env.h +++ b/src/env.h @@ -302,6 +302,47 @@ struct ares_task_t { RB_HEAD(ares_task_list, ares_task_t); +class IsolateData { + public: + static inline IsolateData* GetOrCreate(v8::Isolate* isolate, uv_loop_t* loop); + inline void Put(); + inline uv_loop_t* event_loop() const; + +#define VP(PropertyName, StringValue) V(v8::Private, PropertyName, StringValue) +#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue) +#define V(TypeName, PropertyName, StringValue) \ + inline v8::Local PropertyName() const; + PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) + PER_ISOLATE_STRING_PROPERTIES(VS) +#undef V +#undef VS +#undef VP + + private: + static const int kIsolateSlot = NODE_ISOLATE_SLOT; + + inline static IsolateData* Get(v8::Isolate* isolate); + inline explicit IsolateData(v8::Isolate* isolate, uv_loop_t* loop); + inline v8::Isolate* isolate() const; + + uv_loop_t* const event_loop_; + v8::Isolate* const isolate_; + +#define VP(PropertyName, StringValue) V(v8::Private, PropertyName, StringValue) +#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue) +#define V(TypeName, PropertyName, StringValue) \ + v8::Eternal PropertyName ## _; + PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) + PER_ISOLATE_STRING_PROPERTIES(VS) +#undef V +#undef VS +#undef VP + + unsigned int ref_count_; + + DISALLOW_COPY_AND_ASSIGN(IsolateData); +}; + class Environment { public: class AsyncHooks { @@ -568,9 +609,6 @@ class Environment { static const int kContextEmbedderDataIndex = NODE_CONTEXT_EMBEDDER_DATA_INDEX; private: - static const int kIsolateSlot = NODE_ISOLATE_SLOT; - - class IsolateData; inline Environment(v8::Local context, uv_loop_t* loop); inline ~Environment(); inline IsolateData* isolate_data() const; @@ -615,47 +653,6 @@ class Environment { ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) #undef V - // Per-thread, reference-counted singleton. - class IsolateData { - public: - static inline IsolateData* GetOrCreate(v8::Isolate* isolate, - uv_loop_t* loop); - inline void Put(); - inline uv_loop_t* event_loop() const; - -#define VP(PropertyName, StringValue) V(v8::Private, PropertyName, StringValue) -#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue) -#define V(TypeName, PropertyName, StringValue) \ - inline v8::Local PropertyName() const; - PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) - PER_ISOLATE_STRING_PROPERTIES(VS) -#undef V -#undef VS -#undef VP - - private: - inline static IsolateData* Get(v8::Isolate* isolate); - inline explicit IsolateData(v8::Isolate* isolate, uv_loop_t* loop); - inline v8::Isolate* isolate() const; - - uv_loop_t* const event_loop_; - v8::Isolate* const isolate_; - -#define VP(PropertyName, StringValue) V(v8::Private, PropertyName, StringValue) -#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue) -#define V(TypeName, PropertyName, StringValue) \ - v8::Eternal PropertyName ## _; - PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP) - PER_ISOLATE_STRING_PROPERTIES(VS) -#undef V -#undef VS -#undef VP - - unsigned int ref_count_; - - DISALLOW_COPY_AND_ASSIGN(IsolateData); - }; - DISALLOW_COPY_AND_ASSIGN(Environment); };