mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 06:08:35 +00:00
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>
This commit is contained in:
parent
e4b78c6fd1
commit
0301ce9f55
@ -15,13 +15,12 @@
|
|||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
inline Environment::IsolateData* Environment::IsolateData::Get(
|
inline IsolateData* IsolateData::Get(v8::Isolate* isolate) {
|
||||||
v8::Isolate* isolate) {
|
|
||||||
return static_cast<IsolateData*>(isolate->GetData(kIsolateSlot));
|
return static_cast<IsolateData*>(isolate->GetData(kIsolateSlot));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(
|
inline IsolateData* IsolateData::GetOrCreate(v8::Isolate* isolate,
|
||||||
v8::Isolate* isolate, uv_loop_t* loop) {
|
uv_loop_t* loop) {
|
||||||
IsolateData* isolate_data = Get(isolate);
|
IsolateData* isolate_data = Get(isolate);
|
||||||
if (isolate_data == nullptr) {
|
if (isolate_data == nullptr) {
|
||||||
isolate_data = new IsolateData(isolate, loop);
|
isolate_data = new IsolateData(isolate, loop);
|
||||||
@ -31,7 +30,7 @@ inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(
|
|||||||
return isolate_data;
|
return isolate_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Environment::IsolateData::Put() {
|
inline void IsolateData::Put() {
|
||||||
if (--ref_count_ == 0) {
|
if (--ref_count_ == 0) {
|
||||||
isolate()->SetData(kIsolateSlot, nullptr);
|
isolate()->SetData(kIsolateSlot, nullptr);
|
||||||
delete this;
|
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
|
// 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?
|
// 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,
|
inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* loop)
|
||||||
uv_loop_t* loop)
|
|
||||||
: event_loop_(loop),
|
: event_loop_(loop),
|
||||||
isolate_(isolate),
|
isolate_(isolate),
|
||||||
#define V(PropertyName, StringValue) \
|
#define V(PropertyName, StringValue) \
|
||||||
@ -75,11 +73,11 @@ inline Environment::IsolateData::IsolateData(v8::Isolate* isolate,
|
|||||||
#undef V
|
#undef V
|
||||||
ref_count_(0) {}
|
ref_count_(0) {}
|
||||||
|
|
||||||
inline uv_loop_t* Environment::IsolateData::event_loop() const {
|
inline uv_loop_t* IsolateData::event_loop() const {
|
||||||
return event_loop_;
|
return event_loop_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline v8::Isolate* Environment::IsolateData::isolate() const {
|
inline v8::Isolate* IsolateData::isolate() const {
|
||||||
return isolate_;
|
return isolate_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +430,7 @@ inline ares_task_list* Environment::cares_task_list() {
|
|||||||
return &cares_task_list_;
|
return &cares_task_list_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Environment::IsolateData* Environment::isolate_data() const {
|
inline IsolateData* Environment::isolate_data() const {
|
||||||
return isolate_data_;
|
return isolate_data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,7 +541,7 @@ inline v8::Local<v8::Object> Environment::NewInternalFieldObject() {
|
|||||||
#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue)
|
#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue)
|
||||||
#define V(TypeName, PropertyName, StringValue) \
|
#define V(TypeName, PropertyName, StringValue) \
|
||||||
inline \
|
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. */ \
|
/* Strings are immutable so casting away const-ness here is okay. */ \
|
||||||
return const_cast<IsolateData*>(this)->PropertyName ## _.Get(isolate()); \
|
return const_cast<IsolateData*>(this)->PropertyName ## _.Get(isolate()); \
|
||||||
}
|
}
|
||||||
|
85
src/env.h
85
src/env.h
@ -302,6 +302,47 @@ struct ares_task_t {
|
|||||||
|
|
||||||
RB_HEAD(ares_task_list, 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 {
|
class Environment {
|
||||||
public:
|
public:
|
||||||
class AsyncHooks {
|
class AsyncHooks {
|
||||||
@ -568,9 +609,6 @@ class Environment {
|
|||||||
static const int kContextEmbedderDataIndex = NODE_CONTEXT_EMBEDDER_DATA_INDEX;
|
static const int kContextEmbedderDataIndex = NODE_CONTEXT_EMBEDDER_DATA_INDEX;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int kIsolateSlot = NODE_ISOLATE_SLOT;
|
|
||||||
|
|
||||||
class IsolateData;
|
|
||||||
inline Environment(v8::Local<v8::Context> context, uv_loop_t* loop);
|
inline Environment(v8::Local<v8::Context> context, uv_loop_t* loop);
|
||||||
inline ~Environment();
|
inline ~Environment();
|
||||||
inline IsolateData* isolate_data() const;
|
inline IsolateData* isolate_data() const;
|
||||||
@ -615,47 +653,6 @@ class Environment {
|
|||||||
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
|
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
|
||||||
#undef 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);
|
DISALLOW_COPY_AND_ASSIGN(Environment);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user