Skip to content

Commit 09724b3

Browse files
committed
src: fix Environment::GetCurrent() usage
Create a HandleScope before calling the Environment::GetCurrent() that takes a v8::Isolate* as an argument because it creates a handle with the call to v8::Isolate::CurrentContext().
1 parent 7f09a13 commit 09724b3

21 files changed

Lines changed: 76 additions & 59 deletions

src/async-wrap-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
191191
template <typename TYPE>
192192
inline void AsyncWrap::AddAsyncListener(
193193
const v8::FunctionCallbackInfo<v8::Value>& args) {
194-
Environment* env = Environment::GetCurrent(args.GetIsolate());
195194
v8::HandleScope handle_scope(args.GetIsolate());
195+
Environment* env = Environment::GetCurrent(args.GetIsolate());
196196

197197
v8::Local<v8::Object> handle = args.This();
198198
v8::Local<v8::Value> listener = args[0];
@@ -211,8 +211,8 @@ inline void AsyncWrap::AddAsyncListener(
211211
template <typename TYPE>
212212
inline void AsyncWrap::RemoveAsyncListener(
213213
const v8::FunctionCallbackInfo<v8::Value>& args) {
214-
Environment* env = Environment::GetCurrent(args.GetIsolate());
215214
v8::HandleScope handle_scope(args.GetIsolate());
215+
Environment* env = Environment::GetCurrent(args.GetIsolate());
216216

217217
v8::Local<v8::Object> handle = args.This();
218218
v8::Local<v8::Value> listener = args[0];

src/cares_wrap.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,8 @@ class GetHostByNameWrap: public QueryWrap {
776776

777777
template <class Wrap>
778778
static void Query(const FunctionCallbackInfo<Value>& args) {
779-
Environment* env = Environment::GetCurrent(args.GetIsolate());
780779
HandleScope handle_scope(args.GetIsolate());
780+
Environment* env = Environment::GetCurrent(args.GetIsolate());
781781

782782
assert(!args.IsConstructCall());
783783
assert(args[0]->IsObject());
@@ -911,8 +911,8 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) {
911911

912912

913913
static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
914-
Environment* env = Environment::GetCurrent(args.GetIsolate());
915914
HandleScope handle_scope(args.GetIsolate());
915+
Environment* env = Environment::GetCurrent(args.GetIsolate());
916916

917917
assert(args[0]->IsObject());
918918
assert(args[1]->IsString());
@@ -958,8 +958,8 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
958958

959959

960960
static void GetServers(const FunctionCallbackInfo<Value>& args) {
961-
Environment* env = Environment::GetCurrent(args.GetIsolate());
962961
HandleScope handle_scope(args.GetIsolate());
962+
Environment* env = Environment::GetCurrent(args.GetIsolate());
963963

964964
Local<Array> server_array = Array::New();
965965

@@ -988,8 +988,8 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
988988

989989

990990
static void SetServers(const FunctionCallbackInfo<Value>& args) {
991-
Environment* env = Environment::GetCurrent(args.GetIsolate());
992991
HandleScope handle_scope(args.GetIsolate());
992+
Environment* env = Environment::GetCurrent(args.GetIsolate());
993993

994994
assert(args[0]->IsArray());
995995

src/fs_event_wrap.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ FSEventWrap::~FSEventWrap() {
7878
void FSEventWrap::Initialize(Handle<Object> target,
7979
Handle<Value> unused,
8080
Handle<Context> context) {
81-
Environment* env = Environment::GetCurrent(context);
82-
HandleScope handle_scope(env->isolate());
83-
8481
Local<FunctionTemplate> t = FunctionTemplate::New(New);
8582
t->InstanceTemplate()->SetInternalFieldCount(1);
8683
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "FSEvent"));
@@ -94,6 +91,7 @@ void FSEventWrap::Initialize(Handle<Object> target,
9491

9592
void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) {
9693
assert(args.IsConstructCall());
94+
HandleScope handle_scope(args.GetIsolate());
9795
Environment* env = Environment::GetCurrent(args.GetIsolate());
9896
new FSEventWrap(env, args.This());
9997
}

src/node.cc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ Local<Value> WinapiErrnoException(int errorno,
845845

846846

847847
void SetupAsyncListener(const FunctionCallbackInfo<Value>& args) {
848-
Environment* env = Environment::GetCurrent(args.GetIsolate());
849848
HandleScope handle_scope(args.GetIsolate());
849+
Environment* env = Environment::GetCurrent(args.GetIsolate());
850850

851851
assert(args[0]->IsObject());
852852
assert(args[1]->IsFunction());
@@ -875,8 +875,8 @@ void SetupAsyncListener(const FunctionCallbackInfo<Value>& args) {
875875

876876

877877
void SetupNextTick(const FunctionCallbackInfo<Value>& args) {
878-
Environment* env = Environment::GetCurrent(args.GetIsolate());
879878
HandleScope handle_scope(args.GetIsolate());
879+
Environment* env = Environment::GetCurrent(args.GetIsolate());
880880

881881
assert(args[0]->IsObject() && args[1]->IsFunction());
882882

@@ -1648,8 +1648,8 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {
16481648

16491649

16501650
void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
1651-
Environment* env = Environment::GetCurrent(args.GetIsolate());
16521651
HandleScope handle_scope(args.GetIsolate());
1652+
Environment* env = Environment::GetCurrent(args.GetIsolate());
16531653

16541654
size_t rss;
16551655
int err = uv_resident_set_memory(&rss);
@@ -1728,8 +1728,8 @@ typedef void (UV_DYNAMIC* extInit)(Handle<Object> exports);
17281728
// when two contexts try to load the same shared object. Maybe have a shadow
17291729
// cache that's a plain C list or hash table that's shared across contexts?
17301730
void DLOpen(const FunctionCallbackInfo<Value>& args) {
1731-
Environment* env = Environment::GetCurrent(args.GetIsolate());
17321731
HandleScope handle_scope(args.GetIsolate());
1732+
Environment* env = Environment::GetCurrent(args.GetIsolate());
17331733
char symbol[1024], *base, *pos;
17341734
uv_lib_t lib;
17351735
int r;
@@ -1898,8 +1898,8 @@ void OnMessage(Handle<Message> message, Handle<Value> error) {
18981898

18991899

19001900
static void Binding(const FunctionCallbackInfo<Value>& args) {
1901-
Environment* env = Environment::GetCurrent(args.GetIsolate());
19021901
HandleScope handle_scope(args.GetIsolate());
1902+
Environment* env = Environment::GetCurrent(args.GetIsolate());
19031903

19041904
Local<String> module = args[0]->ToString();
19051905
String::Utf8Value module_v(module);
@@ -2181,6 +2181,7 @@ static void DebugEnd(const FunctionCallbackInfo<Value>& args);
21812181

21822182
void NeedImmediateCallbackGetter(Local<String> property,
21832183
const PropertyCallbackInfo<Value>& info) {
2184+
HandleScope handle_scope(info.GetIsolate());
21842185
Environment* env = Environment::GetCurrent(info.GetIsolate());
21852186
const uv_check_t* immediate_check_handle = env->immediate_check_handle();
21862187
bool active = uv_is_active(
@@ -2193,8 +2194,8 @@ static void NeedImmediateCallbackSetter(
21932194
Local<String> property,
21942195
Local<Value> value,
21952196
const PropertyCallbackInfo<void>& info) {
2196-
Environment* env = Environment::GetCurrent(info.GetIsolate());
21972197
HandleScope handle_scope(info.GetIsolate());
2198+
Environment* env = Environment::GetCurrent(info.GetIsolate());
21982199

21992200
uv_check_t* immediate_check_handle = env->immediate_check_handle();
22002201
bool active = uv_is_active(
@@ -2241,12 +2242,16 @@ void StopProfilerIdleNotifier(Environment* env) {
22412242

22422243

22432244
void StartProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
2244-
StartProfilerIdleNotifier(Environment::GetCurrent(args.GetIsolate()));
2245+
HandleScope handle_scope(args.GetIsolate());
2246+
Environment* env = Environment::GetCurrent(args.GetIsolate());
2247+
StartProfilerIdleNotifier(env);
22452248
}
22462249

22472250

22482251
void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
2249-
StopProfilerIdleNotifier(Environment::GetCurrent(args.GetIsolate()));
2252+
HandleScope handle_scope(args.GetIsolate());
2253+
Environment* env = Environment::GetCurrent(args.GetIsolate());
2254+
StopProfilerIdleNotifier(env);
22502255
}
22512256

22522257

@@ -2761,6 +2766,7 @@ static void EnableDebug(bool wait_connect) {
27612766
assert(debugger_running == false);
27622767
Isolate* isolate = node_isolate; // TODO(bnoordhuis) Multi-isolate support.
27632768
Isolate::Scope isolate_scope(isolate);
2769+
HandleScope handle_scope(isolate);
27642770
v8::Debug::SetDebugMessageDispatchHandler(DispatchMessagesDebugAgentCallback,
27652771
false);
27662772
debugger_running = v8::Debug::EnableAgent("node " NODE_VERSION,
@@ -2779,7 +2785,6 @@ static void EnableDebug(bool wait_connect) {
27792785
return; // Still starting up.
27802786

27812787
Context::Scope context_scope(env->context());
2782-
HandleScope handle_scope(env->isolate());
27832788
Local<Object> message = Object::New();
27842789
message->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "cmd"),
27852790
FIXED_ONE_BYTE_STRING(env->isolate(), "NODE_DEBUG_ENABLED"));

src/node_buffer.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ Local<Object> New(Handle<String> string, enum encoding enc) {
127127

128128

129129
Local<Object> New(size_t length) {
130+
HandleScope handle_scope(node_isolate);
130131
Environment* env = Environment::GetCurrent(node_isolate);
131-
return Buffer::New(env, length);
132+
Local<Object> obj = Buffer::New(env, length);
133+
return handle_scope.Close(obj);
132134
}
133135

134136

@@ -160,8 +162,10 @@ Local<Object> New(Environment* env, size_t length) {
160162

161163

162164
Local<Object> New(const char* data, size_t length) {
165+
HandleScope handle_scope(node_isolate);
163166
Environment* env = Environment::GetCurrent(node_isolate);
164-
return Buffer::New(env, data, length);
167+
Local<Object> obj = Buffer::New(env, data, length);
168+
return handle_scope.Close(obj);
165169
}
166170

167171

@@ -199,8 +203,10 @@ Local<Object> New(char* data,
199203
size_t length,
200204
smalloc::FreeCallback callback,
201205
void* hint) {
206+
HandleScope handle_scope(node_isolate);
202207
Environment* env = Environment::GetCurrent(node_isolate);
203-
return Buffer::New(env, data, length, callback, hint);
208+
Local<Object> obj = Buffer::New(env, data, length, callback, hint);
209+
return handle_scope.Close(obj);
204210
}
205211

206212

@@ -223,8 +229,10 @@ Local<Object> New(Environment* env,
223229

224230

225231
Local<Object> Use(char* data, uint32_t length) {
232+
HandleScope handle_scope(node_isolate);
226233
Environment* env = Environment::GetCurrent(node_isolate);
227-
return Buffer::Use(env, data, length);
234+
Local<Object> obj = Buffer::Use(env, data, length);
235+
return handle_scope.Close(obj);
228236
}
229237

230238

@@ -588,8 +596,8 @@ void ByteLength(const FunctionCallbackInfo<Value> &args) {
588596

589597
// pass Buffer object to load prototype methods
590598
void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
591-
Environment* env = Environment::GetCurrent(args.GetIsolate());
592599
HandleScope handle_scope(args.GetIsolate());
600+
Environment* env = Environment::GetCurrent(args.GetIsolate());
593601

594602
assert(args[0]->IsFunction());
595603

@@ -649,7 +657,6 @@ void Initialize(Handle<Object> target,
649657
Handle<Value> unused,
650658
Handle<Context> context) {
651659
Environment* env = Environment::GetCurrent(context);
652-
HandleScope handle_scope(env->isolate());
653660
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "setupBufferJS"),
654661
FunctionTemplate::New(SetupBufferJS)->GetFunction());
655662
}

src/node_contextify.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ class ContextifyContext {
218218

219219

220220
static void MakeContext(const FunctionCallbackInfo<Value>& args) {
221-
Environment* env = Environment::GetCurrent(args.GetIsolate());
222221
HandleScope handle_scope(args.GetIsolate());
222+
Environment* env = Environment::GetCurrent(args.GetIsolate());
223223

224224
if (!args[0]->IsObject()) {
225225
return ThrowTypeError("sandbox argument must be an object.");
@@ -449,8 +449,8 @@ class ContextifyScript : public WeakObject {
449449

450450
// args: [options]
451451
static void RunInThisContext(const FunctionCallbackInfo<Value>& args) {
452-
Environment* env = Environment::GetCurrent(args.GetIsolate());
453452
HandleScope handle_scope(args.GetIsolate());
453+
Environment* env = Environment::GetCurrent(args.GetIsolate());
454454

455455
// Assemble arguments
456456
TryCatch try_catch;

src/node_crypto.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ void SecureContext::Initialize(Environment* env, Handle<Object> target) {
245245

246246

247247
void SecureContext::New(const FunctionCallbackInfo<Value>& args) {
248+
HandleScope handle_scope(args.GetIsolate());
248249
Environment* env = Environment::GetCurrent(args.GetIsolate());
249250
new SecureContext(env, args.This());
250251
}
@@ -2105,6 +2106,7 @@ void CipherBase::Initialize(Environment* env, Handle<Object> target) {
21052106

21062107
void CipherBase::New(const FunctionCallbackInfo<Value>& args) {
21072108
assert(args.IsConstructCall() == true);
2109+
HandleScope handle_scope(args.GetIsolate());
21082110
CipherKind kind = args[0]->IsTrue() ? kCipher : kDecipher;
21092111
Environment* env = Environment::GetCurrent(args.GetIsolate());
21102112
new CipherBase(env, args.This(), kind);
@@ -2241,8 +2243,8 @@ bool CipherBase::Update(const char* data,
22412243

22422244

22432245
void CipherBase::Update(const FunctionCallbackInfo<Value>& args) {
2244-
Environment* env = Environment::GetCurrent(args.GetIsolate());
22452246
HandleScope handle_scope(args.GetIsolate());
2247+
Environment* env = Environment::GetCurrent(args.GetIsolate());
22462248

22472249
CipherBase* cipher = Unwrap<CipherBase>(args.This());
22482250

@@ -2310,8 +2312,8 @@ bool CipherBase::Final(unsigned char** out, int *out_len) {
23102312

23112313

23122314
void CipherBase::Final(const FunctionCallbackInfo<Value>& args) {
2313-
Environment* env = Environment::GetCurrent(args.GetIsolate());
23142315
HandleScope handle_scope(args.GetIsolate());
2316+
Environment* env = Environment::GetCurrent(args.GetIsolate());
23152317

23162318
CipherBase* cipher = Unwrap<CipherBase>(args.This());
23172319

@@ -2348,6 +2350,7 @@ void Hmac::Initialize(Environment* env, v8::Handle<v8::Object> target) {
23482350

23492351

23502352
void Hmac::New(const FunctionCallbackInfo<Value>& args) {
2353+
HandleScope handle_scope(args.GetIsolate());
23512354
Environment* env = Environment::GetCurrent(args.GetIsolate());
23522355
new Hmac(env, args.This());
23532356
}
@@ -2586,6 +2589,7 @@ void Sign::Initialize(Environment* env, v8::Handle<v8::Object> target) {
25862589

25872590

25882591
void Sign::New(const FunctionCallbackInfo<Value>& args) {
2592+
HandleScope handle_scope(args.GetIsolate());
25892593
Environment* env = Environment::GetCurrent(args.GetIsolate());
25902594
new Sign(env, args.This());
25912595
}
@@ -2768,6 +2772,7 @@ void Verify::Initialize(Environment* env, v8::Handle<v8::Object> target) {
27682772

27692773

27702774
void Verify::New(const FunctionCallbackInfo<Value>& args) {
2775+
HandleScope handle_scope(args.GetIsolate());
27712776
Environment* env = Environment::GetCurrent(args.GetIsolate());
27722777
new Verify(env, args.This());
27732778
}
@@ -3449,8 +3454,8 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
34493454

34503455

34513456
void PBKDF2(const FunctionCallbackInfo<Value>& args) {
3452-
Environment* env = Environment::GetCurrent(args.GetIsolate());
34533457
HandleScope handle_scope(args.GetIsolate());
3458+
Environment* env = Environment::GetCurrent(args.GetIsolate());
34543459

34553460
const char* type_error = NULL;
34563461
char* pass = NULL;
@@ -3655,8 +3660,8 @@ void RandomBytesAfter(uv_work_t* work_req, int status) {
36553660
RandomBytesRequest,
36563661
work_req_);
36573662
Environment* env = req->env();
3658-
Context::Scope context_scope(env->context());
36593663
HandleScope handle_scope(env->isolate());
3664+
Context::Scope context_scope(env->context());
36603665
Local<Value> argv[2];
36613666
RandomBytesCheck(req, argv);
36623667
req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
@@ -3666,8 +3671,8 @@ void RandomBytesAfter(uv_work_t* work_req, int status) {
36663671

36673672
template <bool pseudoRandom>
36683673
void RandomBytes(const FunctionCallbackInfo<Value>& args) {
3669-
Environment* env = Environment::GetCurrent(args.GetIsolate());
36703674
HandleScope handle_scope(args.GetIsolate());
3675+
Environment* env = Environment::GetCurrent(args.GetIsolate());
36713676

36723677
// maybe allow a buffer to write to? cuts down on object creation
36733678
// when generating random data in a loop
@@ -3776,6 +3781,7 @@ void Certificate::Initialize(Handle<Object> target) {
37763781

37773782

37783783
void Certificate::New(const FunctionCallbackInfo<Value>& args) {
3784+
HandleScope handle_scope(args.GetIsolate());
37793785
Environment* env = Environment::GetCurrent(args.GetIsolate());
37803786
new Certificate(env, args.This());
37813787
}

src/node_file.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
731731
// if null, write from the current position
732732
// 3 enc encoding of string
733733
static void WriteString(const FunctionCallbackInfo<Value>& args) {
734-
Environment* env = Environment::GetCurrent(args.GetIsolate());
735734
HandleScope handle_scope(args.GetIsolate());
735+
Environment* env = Environment::GetCurrent(args.GetIsolate());
736736

737737
if (!args[0]->IsInt32())
738738
return ThrowTypeError("First argument must be file descriptor");

0 commit comments

Comments
 (0)