Skip to content

Commit 8aed9d6

Browse files
vkurchatkintrevnorris
authored andcommitted
src: cleanup Isolate::GetCurrent()
PR-URL: nodejs#807 Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Trevor Norris <trev.norris@gmail.com>
1 parent c3c2fbd commit 8aed9d6

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

src/node.cc

+8-10
Original file line numberDiff line numberDiff line change
@@ -1687,23 +1687,21 @@ static const char* name_by_gid(gid_t gid) {
16871687
#endif
16881688

16891689

1690-
static uid_t uid_by_name(Handle<Value> value) {
1690+
static uid_t uid_by_name(Isolate* isolate, Handle<Value> value) {
16911691
if (value->IsUint32()) {
16921692
return static_cast<uid_t>(value->Uint32Value());
16931693
} else {
1694-
// TODO(trevnorris): Fix to not use GetCurrent().
1695-
node::Utf8Value name(Isolate::GetCurrent(), value);
1694+
node::Utf8Value name(isolate, value);
16961695
return uid_by_name(*name);
16971696
}
16981697
}
16991698

17001699

1701-
static gid_t gid_by_name(Handle<Value> value) {
1700+
static gid_t gid_by_name(Isolate* isolate, Handle<Value> value) {
17021701
if (value->IsUint32()) {
17031702
return static_cast<gid_t>(value->Uint32Value());
17041703
} else {
1705-
// TODO(trevnorris): Fix to not use GetCurrent().
1706-
node::Utf8Value name(Isolate::GetCurrent(), value);
1704+
node::Utf8Value name(isolate, value);
17071705
return gid_by_name(*name);
17081706
}
17091707
}
@@ -1728,7 +1726,7 @@ static void SetGid(const FunctionCallbackInfo<Value>& args) {
17281726
return env->ThrowTypeError("setgid argument must be a number or a string");
17291727
}
17301728

1731-
gid_t gid = gid_by_name(args[0]);
1729+
gid_t gid = gid_by_name(env->isolate(), args[0]);
17321730

17331731
if (gid == gid_not_found) {
17341732
return env->ThrowError("setgid group id does not exist");
@@ -1747,7 +1745,7 @@ static void SetUid(const FunctionCallbackInfo<Value>& args) {
17471745
return env->ThrowTypeError("setuid argument must be a number or a string");
17481746
}
17491747

1750-
uid_t uid = uid_by_name(args[0]);
1748+
uid_t uid = uid_by_name(env->isolate(), args[0]);
17511749

17521750
if (uid == uid_not_found) {
17531751
return env->ThrowError("setuid user id does not exist");
@@ -1809,7 +1807,7 @@ static void SetGroups(const FunctionCallbackInfo<Value>& args) {
18091807
gid_t* groups = new gid_t[size];
18101808

18111809
for (size_t i = 0; i < size; i++) {
1812-
gid_t gid = gid_by_name(groups_list->Get(i));
1810+
gid_t gid = gid_by_name(env->isolate(), groups_list->Get(i));
18131811

18141812
if (gid == gid_not_found) {
18151813
delete[] groups;
@@ -1856,7 +1854,7 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {
18561854
return env->ThrowError("initgroups user not found");
18571855
}
18581856

1859-
extra_group = gid_by_name(args[1]);
1857+
extra_group = gid_by_name(env->isolate(), args[1]);
18601858

18611859
if (extra_group == gid_not_found) {
18621860
if (must_free)

src/node.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ NODE_EXTERN void RunAtExit(Environment* env);
190190
// Used to be a macro, hence the uppercase name.
191191
#define NODE_DEFINE_CONSTANT(target, constant) \
192192
do { \
193-
v8::Isolate* isolate = v8::Isolate::GetCurrent(); \
193+
v8::Isolate* isolate = target->GetIsolate(); \
194194
v8::Local<v8::String> constant_name = \
195195
v8::String::NewFromUtf8(isolate, #constant); \
196196
v8::Local<v8::Number> constant_value = \

src/node_object_wrap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ObjectWrap {
3636

3737

3838
inline v8::Local<v8::Object> handle() {
39-
return handle(v8::Isolate::GetCurrent());
39+
return v8::Local<v8::Object>::New(handle_->GetIsolate(), persistent());
4040
}
4141

4242

src/smalloc.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,7 @@ const char RetainedAllocInfo::label_[] = "smalloc";
472472

473473

474474
RetainedAllocInfo::RetainedAllocInfo(Handle<Value> wrapper) {
475-
// TODO(trevnorris): Fix to properly acquire the Isolate.
476-
Local<Object> obj = wrapper->ToObject(Isolate::GetCurrent());
475+
Local<Object> obj = wrapper.As<Object>();
477476
length_ = obj->GetIndexedPropertiesExternalArrayDataLength();
478477
data_ = static_cast<char*>(obj->GetIndexedPropertiesExternalArrayData());
479478
}

0 commit comments

Comments
 (0)