15
15
16
16
namespace node {
17
17
18
- inline IsolateData* IsolateData::Get (v8::Isolate* isolate) {
19
- return static_cast <IsolateData*>(isolate->GetData (kIsolateSlot ));
20
- }
21
-
22
- inline IsolateData* IsolateData::GetOrCreate (v8::Isolate* isolate,
23
- uv_loop_t * loop) {
24
- IsolateData* isolate_data = Get (isolate);
25
- if (isolate_data == nullptr ) {
26
- isolate_data = new IsolateData (isolate, loop);
27
- isolate->SetData (kIsolateSlot , isolate_data);
28
- }
29
- isolate_data->ref_count_ += 1 ;
30
- return isolate_data;
31
- }
32
-
33
- inline void IsolateData::Put () {
34
- if (--ref_count_ == 0 ) {
35
- isolate ()->SetData (kIsolateSlot , nullptr );
36
- delete this ;
37
- }
38
- }
39
-
40
18
// Create string properties as internalized one byte strings.
41
19
//
42
20
// Internalized because it makes property lookups a little faster and because
@@ -46,9 +24,8 @@ inline void IsolateData::Put() {
46
24
//
47
25
// One byte because our strings are ASCII and we can safely skip V8's UTF-8
48
26
// 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
- : event_loop_(loop),
51
- isolate_(isolate),
27
+ inline IsolateData::IsolateData (v8::Isolate* isolate, uv_loop_t * event_loop)
28
+ :
52
29
#define V (PropertyName, StringValue ) \
53
30
PropertyName ## _( \
54
31
isolate, \
@@ -71,16 +48,12 @@ inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* loop)
71
48
sizeof(StringValue) - 1).ToLocalChecked()),
72
49
PER_ISOLATE_STRING_PROPERTIES(V)
73
50
#undef V
74
- ref_count_ ( 0 ) {}
51
+ isolate_ (isolate), event_loop_(event_loop ) {}
75
52
76
53
inline uv_loop_t * IsolateData::event_loop () const {
77
54
return event_loop_;
78
55
}
79
56
80
- inline v8::Isolate* IsolateData::isolate () const {
81
- return isolate_;
82
- }
83
-
84
57
inline Environment::AsyncHooks::AsyncHooks () {
85
58
for (int i = 0 ; i < kFieldsCount ; i++) fields_[i] = 0 ;
86
59
}
@@ -176,9 +149,9 @@ inline void Environment::ArrayBufferAllocatorInfo::reset_fill_flag() {
176
149
fields_[kNoZeroFill ] = 0 ;
177
150
}
178
151
179
- inline Environment* Environment::New (v8::Local<v8::Context> context ,
180
- uv_loop_t * loop ) {
181
- Environment* env = new Environment (context, loop );
152
+ inline Environment* Environment::New (IsolateData* isolate_data ,
153
+ v8::Local<v8::Context> context ) {
154
+ Environment* env = new Environment (isolate_data, context );
182
155
env->AssignToContext (context);
183
156
return env;
184
157
}
@@ -212,11 +185,11 @@ inline Environment* Environment::GetCurrent(
212
185
return static_cast <Environment*>(data.As <v8::External>()->Value ());
213
186
}
214
187
215
- inline Environment::Environment (v8::Local<v8::Context> context ,
216
- uv_loop_t * loop )
188
+ inline Environment::Environment (IsolateData* isolate_data ,
189
+ v8::Local<v8::Context> context )
217
190
: isolate_(context->GetIsolate ()),
218
- isolate_data_(IsolateData::GetOrCreate(context-> GetIsolate (), loop) ),
219
- timer_base_(uv_now(loop )),
191
+ isolate_data_(isolate_data ),
192
+ timer_base_(uv_now(isolate_data-> event_loop () )),
220
193
using_domains_(false ),
221
194
printed_error_(false ),
222
195
trace_sync_io_(false ),
@@ -253,7 +226,6 @@ inline Environment::~Environment() {
253
226
#define V (PropertyName, TypeName ) PropertyName ## _.Reset();
254
227
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES (V)
255
228
#undef V
256
- isolate_data ()->Put ();
257
229
258
230
delete[] heap_statistics_buffer_;
259
231
delete[] heap_space_statistics_buffer_;
@@ -541,9 +513,9 @@ inline v8::Local<v8::Object> Environment::NewInternalFieldObject() {
541
513
#define VS (PropertyName, StringValue ) V(v8::String, PropertyName, StringValue)
542
514
#define V (TypeName, PropertyName, StringValue ) \
543
515
inline \
544
- v8::Local<TypeName> IsolateData::PropertyName () const { \
516
+ v8::Local<TypeName> IsolateData::PropertyName (v8::Isolate* isolate ) const { \
545
517
/* Strings are immutable so casting away const-ness here is okay. */ \
546
- return const_cast <IsolateData*>(this )->PropertyName ## _.Get (isolate ()); \
518
+ return const_cast <IsolateData*>(this )->PropertyName ## _.Get (isolate); \
547
519
}
548
520
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (VP)
549
521
PER_ISOLATE_STRING_PROPERTIES(VS)
@@ -555,7 +527,7 @@ inline v8::Local<v8::Object> Environment::NewInternalFieldObject() {
555
527
#define VS (PropertyName, StringValue ) V(v8::String, PropertyName, StringValue)
556
528
#define V (TypeName, PropertyName, StringValue ) \
557
529
inline v8::Local<TypeName> Environment::PropertyName () const { \
558
- return isolate_data ()->PropertyName (); \
530
+ return isolate_data ()->PropertyName (isolate ()); \
559
531
}
560
532
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (VP)
561
533
PER_ISOLATE_STRING_PROPERTIES(VS)
0 commit comments