Skip to content

Commit 2f1b783

Browse files
committed
doc: remove unnecessary v8::HandleScopes
Remove unnecessary v8::HandleScope uses from the addons documentation. C++ API callbacks run in an implicit v8::HandleScope, there is no need to declare one in the callback function. PR-URL: #1125 Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 409d413 commit 2f1b783

File tree

1 file changed

+0
-19
lines changed

1 file changed

+0
-19
lines changed

doc/api/addons.markdown

-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ First we create a file `hello.cc`:
4545

4646
void Method(const FunctionCallbackInfo<Value>& args) {
4747
Isolate* isolate = args.GetIsolate();
48-
HandleScope scope(isolate);
4948
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
5049
}
5150

@@ -146,7 +145,6 @@ function calls and return a result. This is the main and only needed source
146145

147146
void Add(const FunctionCallbackInfo<Value>& args) {
148147
Isolate* isolate = args.GetIsolate();
149-
HandleScope scope(isolate);
150148

151149
if (args.Length() < 2) {
152150
isolate->ThrowException(Exception::TypeError(
@@ -192,8 +190,6 @@ there. Here's `addon.cc`:
192190

193191
void RunCallback(const FunctionCallbackInfo<Value>& args) {
194192
Isolate* isolate = args.GetIsolate();
195-
HandleScope scope(isolate);
196-
197193
Local<Function> cb = Local<Function>::Cast(args[0]);
198194
const unsigned argc = 1;
199195
Local<Value> argv[argc] = { String::NewFromUtf8(isolate, "hello world") };
@@ -234,7 +230,6 @@ the string passed to `createObject()`:
234230

235231
void CreateObject(const FunctionCallbackInfo<Value>& args) {
236232
Isolate* isolate = args.GetIsolate();
237-
HandleScope scope(isolate);
238233

239234
Local<Object> obj = Object::New(isolate);
240235
obj->Set(String::NewFromUtf8(isolate, "msg"), args[0]->ToString());
@@ -270,13 +265,11 @@ wraps a C++ function:
270265

271266
void MyFunction(const FunctionCallbackInfo<Value>& args) {
272267
Isolate* isolate = args.GetIsolate();
273-
HandleScope scope(isolate);
274268
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world"));
275269
}
276270

277271
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
278272
Isolate* isolate = args.GetIsolate();
279-
HandleScope scope(isolate);
280273

281274
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, MyFunction);
282275
Local<Function> fn = tpl->GetFunction();
@@ -380,7 +373,6 @@ prototype:
380373

381374
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
382375
Isolate* isolate = args.GetIsolate();
383-
HandleScope scope(isolate);
384376

385377
if (args.IsConstructCall()) {
386378
// Invoked as constructor: `new MyObject(...)`
@@ -399,7 +391,6 @@ prototype:
399391

400392
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
401393
Isolate* isolate = args.GetIsolate();
402-
HandleScope scope(isolate);
403394

404395
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
405396
obj->value_ += 1;
@@ -435,8 +426,6 @@ Let's register our `createObject` method in `addon.cc`:
435426
using namespace v8;
436427

437428
void CreateObject(const FunctionCallbackInfo<Value>& args) {
438-
Isolate* isolate = args.GetIsolate();
439-
HandleScope scope(isolate);
440429
MyObject::NewInstance(args);
441430
}
442431

@@ -505,7 +494,6 @@ The implementation is similar to the above in `myobject.cc`:
505494

506495
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
507496
Isolate* isolate = args.GetIsolate();
508-
HandleScope scope(isolate);
509497

510498
if (args.IsConstructCall()) {
511499
// Invoked as constructor: `new MyObject(...)`
@@ -524,7 +512,6 @@ The implementation is similar to the above in `myobject.cc`:
524512

525513
void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
526514
Isolate* isolate = args.GetIsolate();
527-
HandleScope scope(isolate);
528515

529516
const unsigned argc = 1;
530517
Handle<Value> argv[argc] = { args[0] };
@@ -536,7 +523,6 @@ The implementation is similar to the above in `myobject.cc`:
536523

537524
void MyObject::PlusOne(const FunctionCallbackInfo<Value>& args) {
538525
Isolate* isolate = args.GetIsolate();
539-
HandleScope scope(isolate);
540526

541527
MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder());
542528
obj->value_ += 1;
@@ -575,14 +561,11 @@ In the following `addon.cc` we introduce a function `add()` that can take on two
575561
using namespace v8;
576562

577563
void CreateObject(const FunctionCallbackInfo<Value>& args) {
578-
Isolate* isolate = args.GetIsolate();
579-
HandleScope scope(isolate);
580564
MyObject::NewInstance(args);
581565
}
582566

583567
void Add(const FunctionCallbackInfo<Value>& args) {
584568
Isolate* isolate = args.GetIsolate();
585-
HandleScope scope(isolate);
586569

587570
MyObject* obj1 = node::ObjectWrap::Unwrap<MyObject>(
588571
args[0]->ToObject());
@@ -656,7 +639,6 @@ The implementation of `myobject.cc` is similar as before:
656639

657640
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
658641
Isolate* isolate = args.GetIsolate();
659-
HandleScope scope(isolate);
660642

661643
if (args.IsConstructCall()) {
662644
// Invoked as constructor: `new MyObject(...)`
@@ -675,7 +657,6 @@ The implementation of `myobject.cc` is similar as before:
675657

676658
void MyObject::NewInstance(const FunctionCallbackInfo<Value>& args) {
677659
Isolate* isolate = args.GetIsolate();
678-
HandleScope scope(isolate);
679660

680661
const unsigned argc = 1;
681662
Handle<Value> argv[argc] = { args[0] };

0 commit comments

Comments
 (0)