Skip to content

Commit

Permalink
Revert "src: move IsolateData out of Environment"
Browse files Browse the repository at this point in the history
This reverts commit 0301ce9.

nodejs#7082 was landed too fast and did
not have sufficient review time.

That PR also broke some things (testcases will follow separately).
  • Loading branch information
ChALkeR committed Jun 1, 2016
1 parent 2b14127 commit df724e2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 50 deletions.
20 changes: 11 additions & 9 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

namespace node {

inline IsolateData* IsolateData::Get(v8::Isolate* isolate) {
inline Environment::IsolateData* Environment::IsolateData::Get(
v8::Isolate* isolate) {
return static_cast<IsolateData*>(isolate->GetData(kIsolateSlot));
}

inline IsolateData* IsolateData::GetOrCreate(v8::Isolate* isolate,
uv_loop_t* loop) {
inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(
v8::Isolate* isolate, uv_loop_t* loop) {
IsolateData* isolate_data = Get(isolate);
if (isolate_data == nullptr) {
isolate_data = new IsolateData(isolate, loop);
Expand All @@ -30,7 +31,7 @@ inline IsolateData* IsolateData::GetOrCreate(v8::Isolate* isolate,
return isolate_data;
}

inline void IsolateData::Put() {
inline void Environment::IsolateData::Put() {
if (--ref_count_ == 0) {
isolate()->SetData(kIsolateSlot, nullptr);
delete this;
Expand All @@ -46,7 +47,8 @@ inline void 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 IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* loop)
inline Environment::IsolateData::IsolateData(v8::Isolate* isolate,
uv_loop_t* loop)
: event_loop_(loop),
isolate_(isolate),
#define V(PropertyName, StringValue) \
Expand All @@ -73,11 +75,11 @@ inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* loop)
#undef V
ref_count_(0) {}

inline uv_loop_t* IsolateData::event_loop() const {
inline uv_loop_t* Environment::IsolateData::event_loop() const {
return event_loop_;
}

inline v8::Isolate* IsolateData::isolate() const {
inline v8::Isolate* Environment::IsolateData::isolate() const {
return isolate_;
}

Expand Down Expand Up @@ -430,7 +432,7 @@ inline ares_task_list* Environment::cares_task_list() {
return &cares_task_list_;
}

inline IsolateData* Environment::isolate_data() const {
inline Environment::IsolateData* Environment::isolate_data() const {
return isolate_data_;
}

Expand Down Expand Up @@ -541,7 +543,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> IsolateData::PropertyName() const { \
v8::Local<TypeName> Environment::IsolateData::PropertyName() const { \
/* Strings are immutable so casting away const-ness here is okay. */ \
return const_cast<IsolateData*>(this)->PropertyName ## _.Get(isolate()); \
}
Expand Down
85 changes: 44 additions & 41 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,47 +302,6 @@ 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 {
Expand Down Expand Up @@ -609,6 +568,9 @@ 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;
Expand Down Expand Up @@ -653,6 +615,47 @@ 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);
};

Expand Down

0 comments on commit df724e2

Please sign in to comment.