1515
1616namespace node {
1717
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-
4018// Create string properties as internalized one byte strings.
4119//
4220// Internalized because it makes property lookups a little faster and because
@@ -46,9 +24,8 @@ inline void IsolateData::Put() {
4624//
4725// One byte because our strings are ASCII and we can safely skip V8's UTF-8
4826// 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+ :
5229#define V (PropertyName, StringValue ) \
5330 PropertyName ## _( \
5431 isolate, \
@@ -71,16 +48,12 @@ inline IsolateData::IsolateData(v8::Isolate* isolate, uv_loop_t* loop)
7148 sizeof(StringValue) - 1).ToLocalChecked()),
7249 PER_ISOLATE_STRING_PROPERTIES(V)
7350#undef V
74- ref_count_ ( 0 ) {}
51+ isolate_ (isolate), event_loop_(event_loop ) {}
7552
7653inline uv_loop_t * IsolateData::event_loop () const {
7754 return event_loop_;
7855}
7956
80- inline v8::Isolate* IsolateData::isolate () const {
81- return isolate_;
82- }
83-
8457inline Environment::AsyncHooks::AsyncHooks () {
8558 for (int i = 0 ; i < kFieldsCount ; i++) fields_[i] = 0 ;
8659}
@@ -176,9 +149,9 @@ inline void Environment::ArrayBufferAllocatorInfo::reset_fill_flag() {
176149 fields_[kNoZeroFill ] = 0 ;
177150}
178151
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 );
182155 env->AssignToContext (context);
183156 return env;
184157}
@@ -212,11 +185,11 @@ inline Environment* Environment::GetCurrent(
212185 return static_cast <Environment*>(data.As <v8::External>()->Value ());
213186}
214187
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 )
217190 : 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 () )),
220193 using_domains_(false ),
221194 printed_error_(false ),
222195 trace_sync_io_(false ),
@@ -253,7 +226,6 @@ inline Environment::~Environment() {
253226#define V (PropertyName, TypeName ) PropertyName ## _.Reset();
254227 ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES (V)
255228#undef V
256- isolate_data ()->Put ();
257229
258230 delete[] heap_statistics_buffer_;
259231 delete[] heap_space_statistics_buffer_;
@@ -541,9 +513,9 @@ inline v8::Local<v8::Object> Environment::NewInternalFieldObject() {
541513#define VS (PropertyName, StringValue ) V(v8::String, PropertyName, StringValue)
542514#define V (TypeName, PropertyName, StringValue ) \
543515 inline \
544- v8::Local<TypeName> IsolateData::PropertyName () const { \
516+ v8::Local<TypeName> IsolateData::PropertyName (v8::Isolate* isolate ) const { \
545517 /* 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); \
547519 }
548520 PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (VP)
549521 PER_ISOLATE_STRING_PROPERTIES(VS)
@@ -555,7 +527,7 @@ inline v8::Local<v8::Object> Environment::NewInternalFieldObject() {
555527#define VS (PropertyName, StringValue ) V(v8::String, PropertyName, StringValue)
556528#define V (TypeName, PropertyName, StringValue ) \
557529 inline v8::Local<TypeName> Environment::PropertyName () const { \
558- return isolate_data ()->PropertyName (); \
530+ return isolate_data ()->PropertyName (isolate ()); \
559531 }
560532 PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (VP)
561533 PER_ISOLATE_STRING_PROPERTIES(VS)
0 commit comments