Skip to content

Commit 01448b4

Browse files
committed
Add handle scopes
1 parent 5fcdc26 commit 01448b4

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

nan.h

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -805,24 +805,25 @@ class TryCatch {
805805
, v8::Local<v8::Function> func
806806
, int argc
807807
, v8::Local<v8::Value>* argv) {
808-
#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
808+
v8::Isolate *isolate = v8::Isolate::GetCurrent();
809+
v8::EscapableHandleScope scope(isolate);
809810
v8::Local<v8::Object> target_obj;
811+
#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
810812
if (target->IsUndefined() || target->IsNull()) {
811-
target_obj = v8::Isolate::GetCurrent()->GetCurrentContext()->Global();
813+
target_obj = isolate->GetCurrentContext()->Global();
812814
} else {
813815
target_obj = target->ToObject();
814816
}
815-
return New(node::MakeCallback(
816-
v8::Isolate::GetCurrent(), target_obj, func, argc, argv));
817+
return scope.Escape(
818+
New(node::MakeCallback(isolate, target_obj, func, argc, argv)));
817819
#else
818-
v8::Local<v8::Object> target_obj;
819820
if (target->IsUndefined() || target->IsNull()) {
820-
target_obj = v8::Isolate::GetCurrent()->GetCurrentContext()->Global();
821+
target_obj = isolate->GetCurrentContext()->Global();
821822
} else {
822823
target_obj = Nan::To<v8::Object>(target).ToLocalChecked();
823824
}
824-
return node::MakeCallback(
825-
v8::Isolate::GetCurrent(), target_obj, func, argc, argv);
825+
return scope.Escape(
826+
node::MakeCallback(isolate, target_obj, func, argc, argv));
826827
#endif
827828
}
828829

@@ -831,24 +832,25 @@ class TryCatch {
831832
, v8::Local<v8::String> symbol
832833
, int argc
833834
, v8::Local<v8::Value>* argv) {
834-
#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
835+
v8::Isolate *isolate = v8::Isolate::GetCurrent();
836+
v8::EscapableHandleScope scope(isolate);
835837
v8::Local<v8::Object> target_obj;
838+
#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
836839
if (target->IsUndefined() || target->IsNull()) {
837-
target_obj = v8::Isolate::GetCurrent()->GetCurrentContext()->Global();
840+
target_obj = isolate->GetCurrentContext()->Global();
838841
} else {
839842
target_obj = target->ToObject();
840843
}
841-
return New(node::MakeCallback(
842-
v8::Isolate::GetCurrent(), target_obj, symbol, argc, argv));
844+
return scope.Escape(
845+
New(node::MakeCallback(isolate, target_obj, symbol, argc, argv)));
843846
#else
844-
v8::Local<v8::Object> target_obj;
845847
if (target->IsUndefined() || target->IsNull()) {
846-
target_obj = v8::Isolate::GetCurrent()->GetCurrentContext()->Global();
848+
target_obj = isolate->GetCurrentContext()->Global();
847849
} else {
848850
target_obj = Nan::To<v8::Object>(target).ToLocalChecked();
849851
}
850-
return node::MakeCallback(
851-
v8::Isolate::GetCurrent(), target_obj, symbol, argc, argv);
852+
return scope.Escape(
853+
node::MakeCallback(isolate, target_obj, symbol, argc, argv));
852854
#endif
853855
}
854856

@@ -857,24 +859,25 @@ class TryCatch {
857859
, const char* method
858860
, int argc
859861
, v8::Local<v8::Value>* argv) {
860-
#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
862+
v8::Isolate *isolate = v8::Isolate::GetCurrent();
863+
v8::EscapableHandleScope scope(isolate);
861864
v8::Local<v8::Object> target_obj;
865+
#if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
862866
if (target->IsUndefined() || target->IsNull()) {
863-
target_obj = v8::Isolate::GetCurrent()->GetCurrentContext()->Global();
867+
target_obj = isolate->GetCurrentContext()->Global();
864868
} else {
865869
target_obj = target->ToObject();
866870
}
867-
return New(node::MakeCallback(
868-
v8::Isolate::GetCurrent(), target_obj, method, argc, argv));
871+
return scope.Escape(
872+
New(node::MakeCallback(isolate, target_obj, method, argc, argv)));
869873
#else
870-
v8::Local<v8::Object> target_obj;
871874
if (target->IsUndefined() || target->IsNull()) {
872-
target_obj = v8::Isolate::GetCurrent()->GetCurrentContext()->Global();
875+
target_obj = isolate->GetCurrentContext()->Global();
873876
} else {
874877
target_obj = Nan::To<v8::Object>(target).ToLocalChecked();
875878
}
876-
return node::MakeCallback(
877-
v8::Isolate::GetCurrent(), target_obj, method, argc, argv);
879+
return scope.Escape(
880+
node::MakeCallback(isolate, target_obj, method, argc, argv));
878881
#endif
879882
}
880883

@@ -1178,41 +1181,44 @@ widenString(std::vector<uint16_t> *ws, const uint8_t *s, int l) {
11781181
, v8::Local<v8::Function> func
11791182
, int argc
11801183
, v8::Local<v8::Value>* argv) {
1184+
v8::HandleScope scope;
11811185
v8::Local<v8::Object> target_obj;
11821186
if (target->IsUndefined() || target->IsNull()) {
11831187
target_obj = v8::Context::GetCurrent()->Global();
11841188
} else {
11851189
target_obj = target->ToObject();
11861190
}
1187-
return New(node::MakeCallback(target_obj, func, argc, argv));
1191+
return scope.Close(New(node::MakeCallback(target_obj, func, argc, argv)));
11881192
}
11891193

11901194
NAN_INLINE v8::Local<v8::Value> MakeCallback(
11911195
v8::Local<v8::Value> target
11921196
, v8::Local<v8::String> symbol
11931197
, int argc
11941198
, v8::Local<v8::Value>* argv) {
1199+
v8::HandleScope scope;
11951200
v8::Local<v8::Object> target_obj;
11961201
if (target->IsUndefined() || target->IsNull()) {
11971202
target_obj = v8::Context::GetCurrent()->Global();
11981203
} else {
11991204
target_obj = target->ToObject();
12001205
}
1201-
return New(node::MakeCallback(target_obj, symbol, argc, argv));
1206+
return scope.Close(New(node::MakeCallback(target_obj, symbol, argc, argv)));
12021207
}
12031208

12041209
NAN_INLINE v8::Local<v8::Value> MakeCallback(
12051210
v8::Local<v8::Value> target
12061211
, const char* method
12071212
, int argc
12081213
, v8::Local<v8::Value>* argv) {
1214+
v8::HandleScope scope;
12091215
v8::Local<v8::Object> target_obj;
12101216
if (target->IsUndefined() || target->IsNull()) {
12111217
target_obj = v8::Context::GetCurrent()->Global();
12121218
} else {
12131219
target_obj = target->ToObject();
12141220
}
1215-
return New(node::MakeCallback(target_obj, method, argc, argv));
1221+
return scope.Close(New(node::MakeCallback(target_obj, method, argc, argv)));
12161222
}
12171223

12181224
NAN_INLINE void FatalException(const TryCatch& try_catch) {

nan_maybe_pre_43_inl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,15 @@ NAN_INLINE MaybeLocal<v8::Value> CallAsFunction(
262262
#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION
263263
return MaybeLocal<v8::Value>(obj->CallAsFunction(recv, argc, argv));
264264
#else
265+
v8::HandleScope scope;
265266
v8::Local<v8::Object> recv_obj;
266267
if (recv->IsUndefined() || recv->IsNull()) {
267268
recv_obj = v8::Context::GetCurrent()->Global();
268269
} else {
269270
recv_obj = recv->ToObject();
270271
}
271-
return MaybeLocal<v8::Value>(obj->CallAsFunction(recv_obj, argc, argv));
272+
return MaybeLocal<v8::Value>(
273+
scope.Close(obj->CallAsFunction(recv_obj, argc, argv)));
272274
#endif
273275
}
274276

0 commit comments

Comments
 (0)