Skip to content

Commit

Permalink
src: cleanup Isolate::GetCurrent()
Browse files Browse the repository at this point in the history
PR-URL: #807
Reviewed-by: Ben Noordhuis <[email protected]>
Reviewed-by: Trevor Norris <[email protected]>
  • Loading branch information
vkurchatkin authored and trevnorris committed Feb 11, 2015
1 parent c3c2fbd commit 8aed9d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
18 changes: 8 additions & 10 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1687,23 +1687,21 @@ static const char* name_by_gid(gid_t gid) {
#endif


static uid_t uid_by_name(Handle<Value> value) {
static uid_t uid_by_name(Isolate* isolate, Handle<Value> value) {
if (value->IsUint32()) {
return static_cast<uid_t>(value->Uint32Value());
} else {
// TODO(trevnorris): Fix to not use GetCurrent().
node::Utf8Value name(Isolate::GetCurrent(), value);
node::Utf8Value name(isolate, value);
return uid_by_name(*name);
}
}


static gid_t gid_by_name(Handle<Value> value) {
static gid_t gid_by_name(Isolate* isolate, Handle<Value> value) {
if (value->IsUint32()) {
return static_cast<gid_t>(value->Uint32Value());
} else {
// TODO(trevnorris): Fix to not use GetCurrent().
node::Utf8Value name(Isolate::GetCurrent(), value);
node::Utf8Value name(isolate, value);
return gid_by_name(*name);
}
}
Expand All @@ -1728,7 +1726,7 @@ static void SetGid(const FunctionCallbackInfo<Value>& args) {
return env->ThrowTypeError("setgid argument must be a number or a string");
}

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

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

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

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

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

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

extra_group = gid_by_name(args[1]);
extra_group = gid_by_name(env->isolate(), args[1]);

if (extra_group == gid_not_found) {
if (must_free)
Expand Down
2 changes: 1 addition & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ NODE_EXTERN void RunAtExit(Environment* env);
// Used to be a macro, hence the uppercase name.
#define NODE_DEFINE_CONSTANT(target, constant) \
do { \
v8::Isolate* isolate = v8::Isolate::GetCurrent(); \
v8::Isolate* isolate = target->GetIsolate(); \
v8::Local<v8::String> constant_name = \
v8::String::NewFromUtf8(isolate, #constant); \
v8::Local<v8::Number> constant_value = \
Expand Down
2 changes: 1 addition & 1 deletion src/node_object_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ObjectWrap {


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


Expand Down
3 changes: 1 addition & 2 deletions src/smalloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,7 @@ const char RetainedAllocInfo::label_[] = "smalloc";


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

0 comments on commit 8aed9d6

Please sign in to comment.