@@ -44,7 +44,7 @@ First we create a file `hello.cc`:
4444 using namespace v8;
4545
4646 void Method(const FunctionCallbackInfo<Value>& args) {
47- Isolate* isolate = Isolate::GetCurrent ();
47+ Isolate* isolate = args.GetIsolate ();
4848 HandleScope scope(isolate);
4949 args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
5050 }
@@ -145,7 +145,7 @@ function calls and return a result. This is the main and only needed source
145145 using namespace v8;
146146
147147 void Add(const FunctionCallbackInfo<Value>& args) {
148- Isolate* isolate = Isolate::GetCurrent ();
148+ Isolate* isolate = args.GetIsolate ();
149149 HandleScope scope(isolate);
150150
151151 if (args.Length() < 2) {
@@ -191,7 +191,7 @@ there. Here's `addon.cc`:
191191 using namespace v8;
192192
193193 void RunCallback(const FunctionCallbackInfo<Value>& args) {
194- Isolate* isolate = Isolate::GetCurrent ();
194+ Isolate* isolate = args.GetIsolate ();
195195 HandleScope scope(isolate);
196196
197197 Local<Function> cb = Local<Function>::Cast(args[0]);
@@ -233,7 +233,7 @@ the string passed to `createObject()`:
233233 using namespace v8;
234234
235235 void CreateObject(const FunctionCallbackInfo<Value>& args) {
236- Isolate* isolate = Isolate::GetCurrent ();
236+ Isolate* isolate = args.GetIsolate ();
237237 HandleScope scope(isolate);
238238
239239 Local<Object> obj = Object::New(isolate);
@@ -269,13 +269,13 @@ wraps a C++ function:
269269 using namespace v8;
270270
271271 void MyFunction(const FunctionCallbackInfo<Value>& args) {
272- Isolate* isolate = Isolate::GetCurrent ();
272+ Isolate* isolate = args.GetIsolate ();
273273 HandleScope scope(isolate);
274274 args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world"));
275275 }
276276
277277 void CreateFunction(const FunctionCallbackInfo<Value>& args) {
278- Isolate* isolate = Isolate::GetCurrent ();
278+ Isolate* isolate = args.GetIsolate ();
279279 HandleScope scope(isolate);
280280
281281 Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
@@ -363,7 +363,7 @@ prototype:
363363 }
364364
365365 void MyObject::Init(Handle<Object> exports) {
366- Isolate* isolate = Isolate::GetCurrent ();
366+ Isolate* isolate = exports->GetIsolate ();
367367
368368 // Prepare constructor template
369369 Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
@@ -379,7 +379,7 @@ prototype:
379379 }
380380
381381 void MyObject::New(const FunctionCallbackInfo<Value>& args) {
382- Isolate* isolate = Isolate::GetCurrent ();
382+ Isolate* isolate = args.GetIsolate ();
383383 HandleScope scope(isolate);
384384
385385 if (args.IsConstructCall()) {
@@ -398,7 +398,7 @@ prototype:
398398 }
399399
400400 void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
401- Isolate* isolate = Isolate::GetCurrent ();
401+ Isolate* isolate = args.GetIsolate ();
402402 HandleScope scope(isolate);
403403
404404 MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
@@ -435,13 +435,13 @@ Let's register our `createObject` method in `addon.cc`:
435435 using namespace v8;
436436
437437 void CreateObject(const FunctionCallbackInfo<Value>& args) {
438- Isolate* isolate = Isolate::GetCurrent ();
438+ Isolate* isolate = args.GetIsolate ();
439439 HandleScope scope(isolate);
440440 MyObject::NewInstance(args);
441441 }
442442
443443 void InitAll(Handle<Object> exports, Handle<Object> module) {
444- MyObject::Init();
444+ MyObject::Init(exports->GetIsolate() );
445445
446446 NODE_SET_METHOD(module, "exports", CreateObject);
447447 }
@@ -460,7 +460,7 @@ care of instantiating the object (i.e. it does the job of `new` in JavaScript):
460460
461461 class MyObject : public node::ObjectWrap {
462462 public:
463- static void Init();
463+ static void Init(v8::Isolate* isolate );
464464 static void NewInstance(const v8::FunctionCallbackInfo<v8::Value>& args);
465465
466466 private:
@@ -491,8 +491,7 @@ The implementation is similar to the above in `myobject.cc`:
491491 MyObject::~MyObject() {
492492 }
493493
494- void MyObject::Init() {
495- Isolate* isolate = Isolate::GetCurrent();
494+ void MyObject::Init(Isolate* isolate) {
496495 // Prepare constructor template
497496 Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
498497 tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
@@ -505,7 +504,7 @@ The implementation is similar to the above in `myobject.cc`:
505504 }
506505
507506 void MyObject::New(const FunctionCallbackInfo<Value>& args) {
508- Isolate* isolate = Isolate::GetCurrent ();
507+ Isolate* isolate = args.GetIsolate ();
509508 HandleScope scope(isolate);
510509
511510 if (args.IsConstructCall()) {
@@ -524,7 +523,7 @@ The implementation is similar to the above in `myobject.cc`:
524523 }
525524
526525 void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
527- Isolate* isolate = Isolate::GetCurrent ();
526+ Isolate* isolate = args.GetIsolate ();
528527 HandleScope scope(isolate);
529528
530529 const unsigned argc = 1;
@@ -536,7 +535,7 @@ The implementation is similar to the above in `myobject.cc`:
536535 }
537536
538537 void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
539- Isolate* isolate = Isolate::GetCurrent ();
538+ Isolate* isolate = args.GetIsolate ();
540539 HandleScope scope(isolate);
541540
542541 MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
@@ -576,13 +575,13 @@ In the following `addon.cc` we introduce a function `add()` that can take on two
576575 using namespace v8;
577576
578577 void CreateObject(const FunctionCallbackInfo<Value>& args) {
579- Isolate* isolate = Isolate::GetCurrent ();
578+ Isolate* isolate = args.GetIsolate ();
580579 HandleScope scope(isolate);
581580 MyObject::NewInstance(args);
582581 }
583582
584583 void Add(const FunctionCallbackInfo<Value>& args) {
585- Isolate* isolate = Isolate::GetCurrent ();
584+ Isolate* isolate = args.GetIsolate ();
586585 HandleScope scope(isolate);
587586
588587 MyObject* obj1 = node::ObjectWrap::Unwrap<MyObject>(
@@ -595,7 +594,7 @@ In the following `addon.cc` we introduce a function `add()` that can take on two
595594 }
596595
597596 void InitAll(Handle<Object> exports) {
598- MyObject::Init();
597+ MyObject::Init(exports->GetIsolate() );
599598
600599 NODE_SET_METHOD(exports, "createObject", CreateObject);
601600 NODE_SET_METHOD(exports, "add", Add);
@@ -615,7 +614,7 @@ can probe private values after unwrapping the object:
615614
616615 class MyObject : public node::ObjectWrap {
617616 public:
618- static void Init();
617+ static void Init(v8::Isolate* isolate );
619618 static void NewInstance(const v8::FunctionCallbackInfo<v8::Value>& args);
620619 inline double value() const { return value_; }
621620
@@ -646,9 +645,7 @@ The implementation of `myobject.cc` is similar as before:
646645 MyObject::~MyObject() {
647646 }
648647
649- void MyObject::Init() {
650- Isolate* isolate = Isolate::GetCurrent();
651-
648+ void MyObject::Init(Isolate* isolate) {
652649 // Prepare constructor template
653650 Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
654651 tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
@@ -658,7 +655,7 @@ The implementation of `myobject.cc` is similar as before:
658655 }
659656
660657 void MyObject::New(const FunctionCallbackInfo<Value>& args) {
661- Isolate* isolate = Isolate::GetCurrent ();
658+ Isolate* isolate = args.GetIsolate ();
662659 HandleScope scope(isolate);
663660
664661 if (args.IsConstructCall()) {
@@ -677,7 +674,7 @@ The implementation of `myobject.cc` is similar as before:
677674 }
678675
679676 void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
680- Isolate* isolate = Isolate::GetCurrent ();
677+ Isolate* isolate = args.GetIsolate ();
681678 HandleScope scope(isolate);
682679
683680 const unsigned argc = 1;
0 commit comments