@@ -45,7 +45,6 @@ First we create a file `hello.cc`:
45
45
46
46
void Method(const FunctionCallbackInfo<Value>& args) {
47
47
Isolate* isolate = args.GetIsolate();
48
- HandleScope scope(isolate);
49
48
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
50
49
}
51
50
@@ -146,7 +145,6 @@ function calls and return a result. This is the main and only needed source
146
145
147
146
void Add(const FunctionCallbackInfo<Value>& args) {
148
147
Isolate* isolate = args.GetIsolate();
149
- HandleScope scope(isolate);
150
148
151
149
if (args.Length() < 2) {
152
150
isolate->ThrowException(Exception::TypeError(
@@ -192,8 +190,6 @@ there. Here's `addon.cc`:
192
190
193
191
void RunCallback(const FunctionCallbackInfo<Value>& args) {
194
192
Isolate* isolate = args.GetIsolate();
195
- HandleScope scope(isolate);
196
-
197
193
Local<Function> cb = Local<Function>::Cast(args[0]);
198
194
const unsigned argc = 1;
199
195
Local<Value> argv[argc] = { String::NewFromUtf8(isolate, "hello world") };
@@ -234,7 +230,6 @@ the string passed to `createObject()`:
234
230
235
231
void CreateObject(const FunctionCallbackInfo<Value>& args) {
236
232
Isolate* isolate = args.GetIsolate();
237
- HandleScope scope(isolate);
238
233
239
234
Local<Object> obj = Object::New(isolate);
240
235
obj->Set(String::NewFromUtf8(isolate, "msg"), args[0]->ToString());
@@ -270,13 +265,11 @@ wraps a C++ function:
270
265
271
266
void MyFunction(const FunctionCallbackInfo<Value>& args) {
272
267
Isolate* isolate = args.GetIsolate();
273
- HandleScope scope(isolate);
274
268
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world"));
275
269
}
276
270
277
271
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
278
272
Isolate* isolate = args.GetIsolate();
279
- HandleScope scope(isolate);
280
273
281
274
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
282
275
Local<Function> fn = tpl->GetFunction();
@@ -380,7 +373,6 @@ prototype:
380
373
381
374
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
382
375
Isolate* isolate = args.GetIsolate();
383
- HandleScope scope(isolate);
384
376
385
377
if (args.IsConstructCall()) {
386
378
// Invoked as constructor: `new MyObject(...)`
@@ -399,7 +391,6 @@ prototype:
399
391
400
392
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
401
393
Isolate* isolate = args.GetIsolate();
402
- HandleScope scope(isolate);
403
394
404
395
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
405
396
obj->value_ += 1;
@@ -435,8 +426,6 @@ Let's register our `createObject` method in `addon.cc`:
435
426
using namespace v8;
436
427
437
428
void CreateObject(const FunctionCallbackInfo<Value>& args) {
438
- Isolate* isolate = args.GetIsolate();
439
- HandleScope scope(isolate);
440
429
MyObject::NewInstance(args);
441
430
}
442
431
@@ -505,7 +494,6 @@ The implementation is similar to the above in `myobject.cc`:
505
494
506
495
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
507
496
Isolate* isolate = args.GetIsolate();
508
- HandleScope scope(isolate);
509
497
510
498
if (args.IsConstructCall()) {
511
499
// Invoked as constructor: `new MyObject(...)`
@@ -524,7 +512,6 @@ The implementation is similar to the above in `myobject.cc`:
524
512
525
513
void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
526
514
Isolate* isolate = args.GetIsolate();
527
- HandleScope scope(isolate);
528
515
529
516
const unsigned argc = 1;
530
517
Handle<Value> argv[argc] = { args[0] };
@@ -536,7 +523,6 @@ The implementation is similar to the above in `myobject.cc`:
536
523
537
524
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
538
525
Isolate* isolate = args.GetIsolate();
539
- HandleScope scope(isolate);
540
526
541
527
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
542
528
obj->value_ += 1;
@@ -575,14 +561,11 @@ In the following `addon.cc` we introduce a function `add()` that can take on two
575
561
using namespace v8;
576
562
577
563
void CreateObject(const FunctionCallbackInfo<Value>& args) {
578
- Isolate* isolate = args.GetIsolate();
579
- HandleScope scope(isolate);
580
564
MyObject::NewInstance(args);
581
565
}
582
566
583
567
void Add(const FunctionCallbackInfo<Value>& args) {
584
568
Isolate* isolate = args.GetIsolate();
585
- HandleScope scope(isolate);
586
569
587
570
MyObject* obj1 = node::ObjectWrap::Unwrap<MyObject>(
588
571
args[0]->ToObject());
@@ -656,7 +639,6 @@ The implementation of `myobject.cc` is similar as before:
656
639
657
640
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
658
641
Isolate* isolate = args.GetIsolate();
659
- HandleScope scope(isolate);
660
642
661
643
if (args.IsConstructCall()) {
662
644
// Invoked as constructor: `new MyObject(...)`
@@ -675,7 +657,6 @@ The implementation of `myobject.cc` is similar as before:
675
657
676
658
void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
677
659
Isolate* isolate = args.GetIsolate();
678
- HandleScope scope(isolate);
679
660
680
661
const unsigned argc = 1;
681
662
Handle<Value> argv[argc] = { args[0] };
0 commit comments