@@ -44,7 +44,7 @@ First we create a file `hello.cc`:
44
44
using namespace v8;
45
45
46
46
void Method(const FunctionCallbackInfo<Value>& args) {
47
- Isolate* isolate = Isolate::GetCurrent ();
47
+ Isolate* isolate = args.GetIsolate ();
48
48
HandleScope scope(isolate);
49
49
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
50
50
}
@@ -145,7 +145,7 @@ function calls and return a result. This is the main and only needed source
145
145
using namespace v8;
146
146
147
147
void Add(const FunctionCallbackInfo<Value>& args) {
148
- Isolate* isolate = Isolate::GetCurrent ();
148
+ Isolate* isolate = args.GetIsolate ();
149
149
HandleScope scope(isolate);
150
150
151
151
if (args.Length() < 2) {
@@ -191,7 +191,7 @@ there. Here's `addon.cc`:
191
191
using namespace v8;
192
192
193
193
void RunCallback(const FunctionCallbackInfo<Value>& args) {
194
- Isolate* isolate = Isolate::GetCurrent ();
194
+ Isolate* isolate = args.GetIsolate ();
195
195
HandleScope scope(isolate);
196
196
197
197
Local<Function> cb = Local<Function>::Cast(args[0]);
@@ -233,7 +233,7 @@ the string passed to `createObject()`:
233
233
using namespace v8;
234
234
235
235
void CreateObject(const FunctionCallbackInfo<Value>& args) {
236
- Isolate* isolate = Isolate::GetCurrent ();
236
+ Isolate* isolate = args.GetIsolate ();
237
237
HandleScope scope(isolate);
238
238
239
239
Local<Object> obj = Object::New(isolate);
@@ -269,13 +269,13 @@ wraps a C++ function:
269
269
using namespace v8;
270
270
271
271
void MyFunction(const FunctionCallbackInfo<Value>& args) {
272
- Isolate* isolate = Isolate::GetCurrent ();
272
+ Isolate* isolate = args.GetIsolate ();
273
273
HandleScope scope(isolate);
274
274
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world"));
275
275
}
276
276
277
277
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
278
- Isolate* isolate = Isolate::GetCurrent ();
278
+ Isolate* isolate = args.GetIsolate ();
279
279
HandleScope scope(isolate);
280
280
281
281
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
@@ -363,7 +363,7 @@ prototype:
363
363
}
364
364
365
365
void MyObject::Init(Handle<Object> exports) {
366
- Isolate* isolate = Isolate::GetCurrent ();
366
+ Isolate* isolate = exports->GetIsolate ();
367
367
368
368
// Prepare constructor template
369
369
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
@@ -379,7 +379,7 @@ prototype:
379
379
}
380
380
381
381
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
382
- Isolate* isolate = Isolate::GetCurrent ();
382
+ Isolate* isolate = args.GetIsolate ();
383
383
HandleScope scope(isolate);
384
384
385
385
if (args.IsConstructCall()) {
@@ -398,7 +398,7 @@ prototype:
398
398
}
399
399
400
400
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
401
- Isolate* isolate = Isolate::GetCurrent ();
401
+ Isolate* isolate = args.GetIsolate ();
402
402
HandleScope scope(isolate);
403
403
404
404
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
@@ -435,13 +435,13 @@ Let's register our `createObject` method in `addon.cc`:
435
435
using namespace v8;
436
436
437
437
void CreateObject(const FunctionCallbackInfo<Value>& args) {
438
- Isolate* isolate = Isolate::GetCurrent ();
438
+ Isolate* isolate = args.GetIsolate ();
439
439
HandleScope scope(isolate);
440
440
MyObject::NewInstance(args);
441
441
}
442
442
443
443
void InitAll(Handle<Object> exports, Handle<Object> module) {
444
- MyObject::Init();
444
+ MyObject::Init(exports->GetIsolate() );
445
445
446
446
NODE_SET_METHOD(module, "exports", CreateObject);
447
447
}
@@ -460,7 +460,7 @@ care of instantiating the object (i.e. it does the job of `new` in JavaScript):
460
460
461
461
class MyObject : public node::ObjectWrap {
462
462
public:
463
- static void Init();
463
+ static void Init(v8::Isolate* isolate );
464
464
static void NewInstance(const v8::FunctionCallbackInfo<v8::Value>& args);
465
465
466
466
private:
@@ -491,8 +491,7 @@ The implementation is similar to the above in `myobject.cc`:
491
491
MyObject::~MyObject() {
492
492
}
493
493
494
- void MyObject::Init() {
495
- Isolate* isolate = Isolate::GetCurrent();
494
+ void MyObject::Init(Isolate* isolate) {
496
495
// Prepare constructor template
497
496
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
498
497
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
@@ -505,7 +504,7 @@ The implementation is similar to the above in `myobject.cc`:
505
504
}
506
505
507
506
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
508
- Isolate* isolate = Isolate::GetCurrent ();
507
+ Isolate* isolate = args.GetIsolate ();
509
508
HandleScope scope(isolate);
510
509
511
510
if (args.IsConstructCall()) {
@@ -524,7 +523,7 @@ The implementation is similar to the above in `myobject.cc`:
524
523
}
525
524
526
525
void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
527
- Isolate* isolate = Isolate::GetCurrent ();
526
+ Isolate* isolate = args.GetIsolate ();
528
527
HandleScope scope(isolate);
529
528
530
529
const unsigned argc = 1;
@@ -536,7 +535,7 @@ The implementation is similar to the above in `myobject.cc`:
536
535
}
537
536
538
537
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
539
- Isolate* isolate = Isolate::GetCurrent ();
538
+ Isolate* isolate = args.GetIsolate ();
540
539
HandleScope scope(isolate);
541
540
542
541
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
576
575
using namespace v8;
577
576
578
577
void CreateObject(const FunctionCallbackInfo<Value>& args) {
579
- Isolate* isolate = Isolate::GetCurrent ();
578
+ Isolate* isolate = args.GetIsolate ();
580
579
HandleScope scope(isolate);
581
580
MyObject::NewInstance(args);
582
581
}
583
582
584
583
void Add(const FunctionCallbackInfo<Value>& args) {
585
- Isolate* isolate = Isolate::GetCurrent ();
584
+ Isolate* isolate = args.GetIsolate ();
586
585
HandleScope scope(isolate);
587
586
588
587
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
595
594
}
596
595
597
596
void InitAll(Handle<Object> exports) {
598
- MyObject::Init();
597
+ MyObject::Init(exports->GetIsolate() );
599
598
600
599
NODE_SET_METHOD(exports, "createObject", CreateObject);
601
600
NODE_SET_METHOD(exports, "add", Add);
@@ -615,7 +614,7 @@ can probe private values after unwrapping the object:
615
614
616
615
class MyObject : public node::ObjectWrap {
617
616
public:
618
- static void Init();
617
+ static void Init(v8::Isolate* isolate );
619
618
static void NewInstance(const v8::FunctionCallbackInfo<v8::Value>& args);
620
619
inline double value() const { return value_; }
621
620
@@ -646,9 +645,7 @@ The implementation of `myobject.cc` is similar as before:
646
645
MyObject::~MyObject() {
647
646
}
648
647
649
- void MyObject::Init() {
650
- Isolate* isolate = Isolate::GetCurrent();
651
-
648
+ void MyObject::Init(Isolate* isolate) {
652
649
// Prepare constructor template
653
650
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
654
651
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
@@ -658,7 +655,7 @@ The implementation of `myobject.cc` is similar as before:
658
655
}
659
656
660
657
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
661
- Isolate* isolate = Isolate::GetCurrent ();
658
+ Isolate* isolate = args.GetIsolate ();
662
659
HandleScope scope(isolate);
663
660
664
661
if (args.IsConstructCall()) {
@@ -677,7 +674,7 @@ The implementation of `myobject.cc` is similar as before:
677
674
}
678
675
679
676
void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
680
- Isolate* isolate = Isolate::GetCurrent ();
677
+ Isolate* isolate = args.GetIsolate ();
681
678
HandleScope scope(isolate);
682
679
683
680
const unsigned argc = 1;
0 commit comments