Skip to content

Commit 97585b0

Browse files
bnoordhuisindutny
authored andcommitted
src: remove unnecessary HandleScopes
API callback functions don't need to create a v8::HandleScope instance because V8 already creates one in the JS->C++ adapter frame. PR-URL: node-forward/node#16 Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent b2e5199 commit 97585b0

26 files changed

Lines changed: 0 additions & 386 deletions

src/cares_wrap.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,6 @@ class GetHostByNameWrap: public QueryWrap {
841841

842842
template <class Wrap>
843843
static void Query(const FunctionCallbackInfo<Value>& args) {
844-
HandleScope handle_scope(args.GetIsolate());
845844
Environment* env = Environment::GetCurrent(args.GetIsolate());
846845

847846
assert(!args.IsConstructCall());
@@ -992,7 +991,6 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,
992991

993992
static void IsIP(const FunctionCallbackInfo<Value>& args) {
994993
Environment* env = Environment::GetCurrent(args.GetIsolate());
995-
HandleScope scope(env->isolate());
996994

997995
node::Utf8Value ip(args[0]);
998996
char address_buffer[sizeof(struct in6_addr)];
@@ -1008,7 +1006,6 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) {
10081006

10091007

10101008
static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
1011-
HandleScope handle_scope(args.GetIsolate());
10121009
Environment* env = Environment::GetCurrent(args.GetIsolate());
10131010

10141011
assert(args[0]->IsObject());
@@ -1062,7 +1059,6 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
10621059

10631060
static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
10641061
Environment* env = Environment::GetCurrent(args.GetIsolate());
1065-
HandleScope handle_scope(env->isolate());
10661062

10671063
CHECK(args[0]->IsObject());
10681064
CHECK(args[1]->IsString());
@@ -1094,7 +1090,6 @@ static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
10941090

10951091

10961092
static void GetServers(const FunctionCallbackInfo<Value>& args) {
1097-
HandleScope handle_scope(args.GetIsolate());
10981093
Environment* env = Environment::GetCurrent(args.GetIsolate());
10991094

11001095
Local<Array> server_array = Array::New(env->isolate());
@@ -1124,7 +1119,6 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
11241119

11251120

11261121
static void SetServers(const FunctionCallbackInfo<Value>& args) {
1127-
HandleScope handle_scope(args.GetIsolate());
11281122
Environment* env = Environment::GetCurrent(args.GetIsolate());
11291123

11301124
assert(args[0]->IsArray());
@@ -1194,7 +1188,6 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
11941188

11951189
static void StrError(const FunctionCallbackInfo<Value>& args) {
11961190
Environment* env = Environment::GetCurrent(args.GetIsolate());
1197-
HandleScope scope(env->isolate());
11981191
const char* errmsg = ares_strerror(args[0]->Int32Value());
11991192
args.GetReturnValue().Set(OneByteString(env->isolate(), errmsg));
12001193
}

src/fs_event_wrap.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,13 @@ void FSEventWrap::Initialize(Handle<Object> target,
9696

9797
void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) {
9898
assert(args.IsConstructCall());
99-
HandleScope handle_scope(args.GetIsolate());
10099
Environment* env = Environment::GetCurrent(args.GetIsolate());
101100
new FSEventWrap(env, args.This());
102101
}
103102

104103

105104
void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
106105
Environment* env = Environment::GetCurrent(args.GetIsolate());
107-
HandleScope scope(env->isolate());
108106

109107
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder());
110108

@@ -186,9 +184,6 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
186184

187185

188186
void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
189-
Environment* env = Environment::GetCurrent(args.GetIsolate());
190-
HandleScope scope(env->isolate());
191-
192187
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder());
193188

194189
if (wrap == NULL || wrap->initialized_ == false)

src/handle_wrap.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ using v8::Value;
4141

4242

4343
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
44-
Environment* env = Environment::GetCurrent(args.GetIsolate());
45-
HandleScope scope(env->isolate());
46-
4744
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());
4845

4946
if (wrap != NULL && wrap->handle__ != NULL) {
@@ -54,9 +51,6 @@ void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
5451

5552

5653
void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
57-
Environment* env = Environment::GetCurrent(args.GetIsolate());
58-
HandleScope scope(env->isolate());
59-
6054
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());
6155

6256
if (wrap != NULL && wrap->handle__ != NULL) {
@@ -68,7 +62,6 @@ void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
6862

6963
void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
7064
Environment* env = Environment::GetCurrent(args.GetIsolate());
71-
HandleScope scope(env->isolate());
7265

7366
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());
7467

src/node.cc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
909909

910910

911911
void SetupAsyncListener(const FunctionCallbackInfo<Value>& args) {
912-
HandleScope handle_scope(args.GetIsolate());
913912
Environment* env = Environment::GetCurrent(args.GetIsolate());
914913

915914
assert(args[0]->IsObject());
@@ -979,7 +978,6 @@ void RunMicrotasks(const FunctionCallbackInfo<Value>& args) {
979978

980979

981980
void SetupNextTick(const FunctionCallbackInfo<Value>& args) {
982-
HandleScope handle_scope(args.GetIsolate());
983981
Environment* env = Environment::GetCurrent(args.GetIsolate());
984982

985983
assert(args[0]->IsObject());
@@ -1552,7 +1550,6 @@ static Local<Value> ExecuteString(Environment* env,
15521550

15531551
static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
15541552
Environment* env = Environment::GetCurrent(args.GetIsolate());
1555-
HandleScope scope(env->isolate());
15561553

15571554
Local<Array> ary = Array::New(args.GetIsolate());
15581555
QUEUE* q = NULL;
@@ -1573,7 +1570,6 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
15731570
// implemented here for consistency with GetActiveRequests().
15741571
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
15751572
Environment* env = Environment::GetCurrent(args.GetIsolate());
1576-
HandleScope scope(env->isolate());
15771573

15781574
Local<Array> ary = Array::New(env->isolate());
15791575
QUEUE* q = NULL;
@@ -1603,7 +1599,6 @@ static void Abort(const FunctionCallbackInfo<Value>& args) {
16031599

16041600
static void Chdir(const FunctionCallbackInfo<Value>& args) {
16051601
Environment* env = Environment::GetCurrent(args.GetIsolate());
1606-
HandleScope scope(env->isolate());
16071602

16081603
if (args.Length() != 1 || !args[0]->IsString()) {
16091604
// FIXME(bnoordhuis) ThrowTypeError?
@@ -1620,7 +1615,6 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
16201615

16211616
static void Cwd(const FunctionCallbackInfo<Value>& args) {
16221617
Environment* env = Environment::GetCurrent(args.GetIsolate());
1623-
HandleScope scope(env->isolate());
16241618
#ifdef _WIN32
16251619
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
16261620
char buf[MAX_PATH * 4];
@@ -1644,7 +1638,6 @@ static void Cwd(const FunctionCallbackInfo<Value>& args) {
16441638

16451639
static void Umask(const FunctionCallbackInfo<Value>& args) {
16461640
Environment* env = Environment::GetCurrent(args.GetIsolate());
1647-
HandleScope scope(env->isolate());
16481641
uint32_t old;
16491642

16501643
if (args.Length() < 1 || args[0]->IsUndefined()) {
@@ -1793,7 +1786,6 @@ static void GetGid(const FunctionCallbackInfo<Value>& args) {
17931786

17941787
static void SetGid(const FunctionCallbackInfo<Value>& args) {
17951788
Environment* env = Environment::GetCurrent(args.GetIsolate());
1796-
HandleScope scope(env->isolate());
17971789

17981790
if (!args[0]->IsUint32() && !args[0]->IsString()) {
17991791
return env->ThrowTypeError("setgid argument must be a number or a string");
@@ -1813,7 +1805,6 @@ static void SetGid(const FunctionCallbackInfo<Value>& args) {
18131805

18141806
static void SetUid(const FunctionCallbackInfo<Value>& args) {
18151807
Environment* env = Environment::GetCurrent(args.GetIsolate());
1816-
HandleScope scope(env->isolate());
18171808

18181809
if (!args[0]->IsUint32() && !args[0]->IsString()) {
18191810
return env->ThrowTypeError("setuid argument must be a number or a string");
@@ -1833,7 +1824,6 @@ static void SetUid(const FunctionCallbackInfo<Value>& args) {
18331824

18341825
static void GetGroups(const FunctionCallbackInfo<Value>& args) {
18351826
Environment* env = Environment::GetCurrent(args.GetIsolate());
1836-
HandleScope scope(env->isolate());
18371827

18381828
int ngroups = getgroups(0, NULL);
18391829

@@ -1872,7 +1862,6 @@ static void GetGroups(const FunctionCallbackInfo<Value>& args) {
18721862

18731863
static void SetGroups(const FunctionCallbackInfo<Value>& args) {
18741864
Environment* env = Environment::GetCurrent(args.GetIsolate());
1875-
HandleScope scope(env->isolate());
18761865

18771866
if (!args[0]->IsArray()) {
18781867
return env->ThrowTypeError("argument 1 must be an array");
@@ -1904,7 +1893,6 @@ static void SetGroups(const FunctionCallbackInfo<Value>& args) {
19041893

19051894
static void InitGroups(const FunctionCallbackInfo<Value>& args) {
19061895
Environment* env = Environment::GetCurrent(args.GetIsolate());
1907-
HandleScope scope(env->isolate());
19081896

19091897
if (!args[0]->IsUint32() && !args[0]->IsString()) {
19101898
return env->ThrowTypeError("argument 1 must be a number or a string");
@@ -1954,15 +1942,12 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {
19541942

19551943

19561944
void Exit(const FunctionCallbackInfo<Value>& args) {
1957-
Environment* env = Environment::GetCurrent(args.GetIsolate());
1958-
HandleScope scope(env->isolate());
19591945
exit(args[0]->Int32Value());
19601946
}
19611947

19621948

19631949
static void Uptime(const FunctionCallbackInfo<Value>& args) {
19641950
Environment* env = Environment::GetCurrent(args.GetIsolate());
1965-
HandleScope scope(env->isolate());
19661951
double uptime;
19671952

19681953
uv_update_time(env->event_loop());
@@ -1974,7 +1959,6 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {
19741959

19751960
void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
19761961
Environment* env = Environment::GetCurrent(args.GetIsolate());
1977-
HandleScope scope(env->isolate());
19781962

19791963
size_t rss;
19801964
int err = uv_resident_set_memory(&rss);
@@ -2002,7 +1986,6 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
20021986

20031987
void Kill(const FunctionCallbackInfo<Value>& args) {
20041988
Environment* env = Environment::GetCurrent(args.GetIsolate());
2005-
HandleScope scope(env->isolate());
20061989

20071990
if (args.Length() != 2) {
20081991
return env->ThrowError("Bad argument.");
@@ -2024,7 +2007,6 @@ void Kill(const FunctionCallbackInfo<Value>& args) {
20242007
// Pass in an Array from a previous hrtime() call to instead get a time diff.
20252008
void Hrtime(const FunctionCallbackInfo<Value>& args) {
20262009
Environment* env = Environment::GetCurrent(args.GetIsolate());
2027-
HandleScope scope(env->isolate());
20282010

20292011
uint64_t t = uv_hrtime();
20302012

@@ -2079,7 +2061,6 @@ typedef void (UV_DYNAMIC* extInit)(Handle<Object> exports);
20792061
// when two contexts try to load the same shared object. Maybe have a shadow
20802062
// cache that's a plain C list or hash table that's shared across contexts?
20812063
void DLOpen(const FunctionCallbackInfo<Value>& args) {
2082-
HandleScope handle_scope(args.GetIsolate());
20832064
Environment* env = Environment::GetCurrent(args.GetIsolate());
20842065
struct node_module* mp;
20852066
uv_lib_t lib;
@@ -2223,7 +2204,6 @@ void OnMessage(Handle<Message> message, Handle<Value> error) {
22232204

22242205

22252206
static void Binding(const FunctionCallbackInfo<Value>& args) {
2226-
HandleScope handle_scope(args.GetIsolate());
22272207
Environment* env = Environment::GetCurrent(args.GetIsolate());
22282208

22292209
Local<String> module = args[0]->ToString();
@@ -2528,7 +2508,6 @@ static void DebugEnd(const FunctionCallbackInfo<Value>& args);
25282508

25292509
void NeedImmediateCallbackGetter(Local<String> property,
25302510
const PropertyCallbackInfo<Value>& info) {
2531-
HandleScope handle_scope(info.GetIsolate());
25322511
Environment* env = Environment::GetCurrent(info.GetIsolate());
25332512
const uv_check_t* immediate_check_handle = env->immediate_check_handle();
25342513
bool active = uv_is_active(
@@ -2589,14 +2568,12 @@ void StopProfilerIdleNotifier(Environment* env) {
25892568

25902569

25912570
void StartProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
2592-
HandleScope handle_scope(args.GetIsolate());
25932571
Environment* env = Environment::GetCurrent(args.GetIsolate());
25942572
StartProfilerIdleNotifier(env);
25952573
}
25962574

25972575

25982576
void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
2599-
HandleScope handle_scope(args.GetIsolate());
26002577
Environment* env = Environment::GetCurrent(args.GetIsolate());
26012578
StopProfilerIdleNotifier(env);
26022579
}
@@ -2847,7 +2824,6 @@ static void SignalExit(int signo) {
28472824
// function, it is useful to bypass JavaScript entirely.
28482825
static void RawDebug(const FunctionCallbackInfo<Value>& args) {
28492826
Environment* env = Environment::GetCurrent(args.GetIsolate());
2850-
HandleScope scope(env->isolate());
28512827

28522828
assert(args.Length() == 1 && args[0]->IsString() &&
28532829
"must be called with a single string");
@@ -3217,7 +3193,6 @@ static void RegisterSignalHandler(int signal,
32173193

32183194
void DebugProcess(const FunctionCallbackInfo<Value>& args) {
32193195
Environment* env = Environment::GetCurrent(args.GetIsolate());
3220-
HandleScope scope(env->isolate());
32213196

32223197
if (args.Length() != 1) {
32233198
return env->ThrowError("Invalid number of arguments.");
@@ -3306,7 +3281,6 @@ static int RegisterDebugSignalHandler() {
33063281
static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
33073282
Isolate* isolate = args.GetIsolate();
33083283
Environment* env = Environment::GetCurrent(isolate);
3309-
HandleScope scope(isolate);
33103284
DWORD pid;
33113285
HANDLE process = NULL;
33123286
HANDLE thread = NULL;

src/node_buffer.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ Local<Object> Use(Environment* env, char* data, uint32_t length) {
257257
template <encoding encoding>
258258
void StringSlice(const FunctionCallbackInfo<Value>& args) {
259259
Environment* env = Environment::GetCurrent(args.GetIsolate());
260-
HandleScope scope(env->isolate());
261260

262261
ARGS_THIS(args.This())
263262
SLICE_START_END(args[0], args[1], obj_length)
@@ -300,7 +299,6 @@ void Base64Slice(const FunctionCallbackInfo<Value>& args) {
300299
// bytesCopied = buffer.copy(target[, targetStart][, sourceStart][, sourceEnd]);
301300
void Copy(const FunctionCallbackInfo<Value> &args) {
302301
Environment* env = Environment::GetCurrent(args.GetIsolate());
303-
HandleScope scope(env->isolate());
304302

305303
Local<Object> target = args[0]->ToObject();
306304

@@ -381,7 +379,6 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
381379
template <encoding encoding>
382380
void StringWrite(const FunctionCallbackInfo<Value>& args) {
383381
Environment* env = Environment::GetCurrent(args.GetIsolate());
384-
HandleScope scope(env->isolate());
385382

386383
ARGS_THIS(args.This())
387384

@@ -546,7 +543,6 @@ void WriteDoubleBE(const FunctionCallbackInfo<Value>& args) {
546543

547544
void ByteLength(const FunctionCallbackInfo<Value> &args) {
548545
Environment* env = Environment::GetCurrent(args.GetIsolate());
549-
HandleScope scope(env->isolate());
550546

551547
if (!args[0]->IsString())
552548
return env->ThrowTypeError("Argument must be a string");
@@ -595,7 +591,6 @@ void Compare(const FunctionCallbackInfo<Value> &args) {
595591
// pass Buffer object to load prototype methods
596592
void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
597593
Environment* env = Environment::GetCurrent(args.GetIsolate());
598-
HandleScope scope(env->isolate());
599594

600595
assert(args[0]->IsFunction());
601596

src/node_contextify.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ class ContextifyContext {
253253

254254

255255
static void RunInDebugContext(const FunctionCallbackInfo<Value>& args) {
256-
HandleScope scope(args.GetIsolate());
257256
Local<String> script_source(args[0]->ToString());
258257
if (script_source.IsEmpty())
259258
return; // Exception pending.
@@ -267,7 +266,6 @@ class ContextifyContext {
267266

268267
static void MakeContext(const FunctionCallbackInfo<Value>& args) {
269268
Environment* env = Environment::GetCurrent(args.GetIsolate());
270-
HandleScope scope(env->isolate());
271269

272270
if (!args[0]->IsObject()) {
273271
return env->ThrowTypeError("sandbox argument must be an object.");
@@ -298,7 +296,6 @@ class ContextifyContext {
298296

299297
static void IsContext(const FunctionCallbackInfo<Value>& args) {
300298
Environment* env = Environment::GetCurrent(args.GetIsolate());
301-
HandleScope scope(env->isolate());
302299

303300
if (!args[0]->IsObject()) {
304301
env->ThrowTypeError("sandbox must be an object");
@@ -473,7 +470,6 @@ class ContextifyScript : public BaseObject {
473470
// args: code, [options]
474471
static void New(const FunctionCallbackInfo<Value>& args) {
475472
Environment* env = Environment::GetCurrent(args.GetIsolate());
476-
HandleScope scope(env->isolate());
477473

478474
if (!args.IsConstructCall()) {
479475
return env->ThrowError("Must call vm.Script as a constructor.");
@@ -516,7 +512,6 @@ class ContextifyScript : public BaseObject {
516512
// args: [options]
517513
static void RunInThisContext(const FunctionCallbackInfo<Value>& args) {
518514
Isolate* isolate = args.GetIsolate();
519-
HandleScope handle_scope(isolate);
520515

521516
// Assemble arguments
522517
TryCatch try_catch;
@@ -535,7 +530,6 @@ class ContextifyScript : public BaseObject {
535530
// args: sandbox, [options]
536531
static void RunInContext(const FunctionCallbackInfo<Value>& args) {
537532
Environment* env = Environment::GetCurrent(args.GetIsolate());
538-
HandleScope scope(env->isolate());
539533

540534
int64_t timeout;
541535
bool display_errors;

0 commit comments

Comments
 (0)