Skip to content

Commit df724e2

Browse files
committed
Revert "src: move IsolateData out of Environment"
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).
1 parent 2b14127 commit df724e2

File tree

2 files changed

+55
-50
lines changed

2 files changed

+55
-50
lines changed

src/env-inl.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
namespace node {
1717

18-
inline IsolateData* IsolateData::Get(v8::Isolate* isolate) {
18+
inline Environment::IsolateData* Environment::IsolateData::Get(
19+
v8::Isolate* isolate) {
1920
return static_cast<IsolateData*>(isolate->GetData(kIsolateSlot));
2021
}
2122

22-
inline IsolateData* IsolateData::GetOrCreate(v8::Isolate* isolate,
23-
uv_loop_t* loop) {
23+
inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(
24+
v8::Isolate* isolate, uv_loop_t* loop) {
2425
IsolateData* isolate_data = Get(isolate);
2526
if (isolate_data == nullptr) {
2627
isolate_data = new IsolateData(isolate, loop);
@@ -30,7 +31,7 @@ inline IsolateData* IsolateData::GetOrCreate(v8::Isolate* isolate,
3031
return isolate_data;
3132
}
3233

33-
inline void IsolateData::Put() {
34+
inline void Environment::IsolateData::Put() {
3435
if (--ref_count_ == 0) {
3536
isolate()->SetData(kIsolateSlot, nullptr);
3637
delete this;
@@ -46,7 +47,8 @@ inline void IsolateData::Put() {
4647
//
4748
// One byte because our strings are ASCII and we can safely skip V8's UTF-8
4849
// decoding step. It's a one-time cost, but why pay it when you don't have to?
49-
inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* loop)
50+
inline Environment::IsolateData::IsolateData(v8::Isolate* isolate,
51+
uv_loop_t* loop)
5052
: event_loop_(loop),
5153
isolate_(isolate),
5254
#define V(PropertyName, StringValue) \
@@ -73,11 +75,11 @@ inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* loop)
7375
#undef V
7476
ref_count_(0) {}
7577

76-
inline uv_loop_t* IsolateData::event_loop() const {
78+
inline uv_loop_t* Environment::IsolateData::event_loop() const {
7779
return event_loop_;
7880
}
7981

80-
inline v8::Isolate* IsolateData::isolate() const {
82+
inline v8::Isolate* Environment::IsolateData::isolate() const {
8183
return isolate_;
8284
}
8385

@@ -430,7 +432,7 @@ inline ares_task_list* Environment::cares_task_list() {
430432
return &cares_task_list_;
431433
}
432434

433-
inline IsolateData* Environment::isolate_data() const {
435+
inline Environment::IsolateData* Environment::isolate_data() const {
434436
return isolate_data_;
435437
}
436438

@@ -541,7 +543,7 @@ inline v8::Local<v8::Object> Environment::NewInternalFieldObject() {
541543
#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue)
542544
#define V(TypeName, PropertyName, StringValue) \
543545
inline \
544-
v8::Local<TypeName> IsolateData::PropertyName() const { \
546+
v8::Local<TypeName> Environment::IsolateData::PropertyName() const { \
545547
/* Strings are immutable so casting away const-ness here is okay. */ \
546548
return const_cast<IsolateData*>(this)->PropertyName ## _.Get(isolate()); \
547549
}

src/env.h

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -302,47 +302,6 @@ struct ares_task_t {
302302

303303
RB_HEAD(ares_task_list, ares_task_t);
304304

305-
class IsolateData {
306-
public:
307-
static inline IsolateData* GetOrCreate(v8::Isolate* isolate, uv_loop_t* loop);
308-
inline void Put();
309-
inline uv_loop_t* event_loop() const;
310-
311-
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName, StringValue)
312-
#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue)
313-
#define V(TypeName, PropertyName, StringValue) \
314-
inline v8::Local<TypeName> PropertyName() const;
315-
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
316-
PER_ISOLATE_STRING_PROPERTIES(VS)
317-
#undef V
318-
#undef VS
319-
#undef VP
320-
321-
private:
322-
static const int kIsolateSlot = NODE_ISOLATE_SLOT;
323-
324-
inline static IsolateData* Get(v8::Isolate* isolate);
325-
inline explicit IsolateData(v8::Isolate* isolate, uv_loop_t* loop);
326-
inline v8::Isolate* isolate() const;
327-
328-
uv_loop_t* const event_loop_;
329-
v8::Isolate* const isolate_;
330-
331-
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName, StringValue)
332-
#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue)
333-
#define V(TypeName, PropertyName, StringValue) \
334-
v8::Eternal<TypeName> PropertyName ## _;
335-
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
336-
PER_ISOLATE_STRING_PROPERTIES(VS)
337-
#undef V
338-
#undef VS
339-
#undef VP
340-
341-
unsigned int ref_count_;
342-
343-
DISALLOW_COPY_AND_ASSIGN(IsolateData);
344-
};
345-
346305
class Environment {
347306
public:
348307
class AsyncHooks {
@@ -609,6 +568,9 @@ class Environment {
609568
static const int kContextEmbedderDataIndex = NODE_CONTEXT_EMBEDDER_DATA_INDEX;
610569

611570
private:
571+
static const int kIsolateSlot = NODE_ISOLATE_SLOT;
572+
573+
class IsolateData;
612574
inline Environment(v8::Local<v8::Context> context, uv_loop_t* loop);
613575
inline ~Environment();
614576
inline IsolateData* isolate_data() const;
@@ -653,6 +615,47 @@ class Environment {
653615
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
654616
#undef V
655617

618+
// Per-thread, reference-counted singleton.
619+
class IsolateData {
620+
public:
621+
static inline IsolateData* GetOrCreate(v8::Isolate* isolate,
622+
uv_loop_t* loop);
623+
inline void Put();
624+
inline uv_loop_t* event_loop() const;
625+
626+
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName, StringValue)
627+
#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue)
628+
#define V(TypeName, PropertyName, StringValue) \
629+
inline v8::Local<TypeName> PropertyName() const;
630+
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
631+
PER_ISOLATE_STRING_PROPERTIES(VS)
632+
#undef V
633+
#undef VS
634+
#undef VP
635+
636+
private:
637+
inline static IsolateData* Get(v8::Isolate* isolate);
638+
inline explicit IsolateData(v8::Isolate* isolate, uv_loop_t* loop);
639+
inline v8::Isolate* isolate() const;
640+
641+
uv_loop_t* const event_loop_;
642+
v8::Isolate* const isolate_;
643+
644+
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName, StringValue)
645+
#define VS(PropertyName, StringValue) V(v8::String, PropertyName, StringValue)
646+
#define V(TypeName, PropertyName, StringValue) \
647+
v8::Eternal<TypeName> PropertyName ## _;
648+
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(VP)
649+
PER_ISOLATE_STRING_PROPERTIES(VS)
650+
#undef V
651+
#undef VS
652+
#undef VP
653+
654+
unsigned int ref_count_;
655+
656+
DISALLOW_COPY_AND_ASSIGN(IsolateData);
657+
};
658+
656659
DISALLOW_COPY_AND_ASSIGN(Environment);
657660
};
658661

0 commit comments

Comments
 (0)