Browse Source

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 <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
v7.x
Ben Noordhuis 9 years ago
parent
commit
0301ce9f55
  1. 20
      src/env-inl.h
  2. 85
      src/env.h

20
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<IsolateData*>(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<v8::Object> Environment::NewInternalFieldObject() {
#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue)
#define V(TypeName, PropertyName, StringValue) \
inline \
v8::Local<TypeName> Environment::IsolateData::PropertyName() const { \
v8::Local<TypeName> IsolateData::PropertyName() const { \
/* Strings are immutable so casting away const-ness here is okay. */ \
return const_cast<IsolateData*>(this)->PropertyName ## _.Get(isolate()); \
}

85
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<TypeName> 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<TypeName> 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<v8::Context> 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<TypeName> 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<TypeName> 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);
};

Loading…
Cancel
Save