Skip to content

Commit

Permalink
src: pass Isolate to node::Utf8Value constructor
Browse files Browse the repository at this point in the history
Initial attempt to remove all uses of Isolate::GetCurrent(). Still
exists a few locations, but this works out a heavy usage.

PR-URL: nodejs#244
Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
trevnorris committed Jan 7, 2015
1 parent d553386 commit cbf76c1
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 90 deletions.
10 changes: 5 additions & 5 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ static void Query(const FunctionCallbackInfo<Value>& args) {
Local<String> string = args[1].As<String>();
Wrap* wrap = new Wrap(env, req_wrap_obj);

node::Utf8Value name(string);
node::Utf8Value name(env->isolate(), string);
int err = wrap->Send(*name);
if (err)
delete wrap;
Expand Down Expand Up @@ -1023,7 +1023,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,


static void IsIP(const FunctionCallbackInfo<Value>& args) {
node::Utf8Value ip(args[0]);
node::Utf8Value ip(args.GetIsolate(), args[0]);
char address_buffer[sizeof(struct in6_addr)];

int rc = 0;
Expand All @@ -1043,7 +1043,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
CHECK(args[1]->IsString());
CHECK(args[2]->IsInt32());
Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value hostname(args[1]);
node::Utf8Value hostname(env->isolate(), args[1]);

int32_t flags = (args[3]->IsInt32()) ? args[3]->Int32Value() : 0;
int family;
Expand Down Expand Up @@ -1092,7 +1092,7 @@ static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
CHECK(args[1]->IsString());
CHECK(args[2]->IsUint32());
Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value ip(args[1]);
node::Utf8Value ip(env->isolate(), args[1]);
const unsigned port = args[2]->Uint32Value();
struct sockaddr_storage addr;

Expand Down Expand Up @@ -1171,7 +1171,7 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
CHECK(elm->Get(1)->IsString());

int fam = elm->Get(0)->Int32Value();
node::Utf8Value ip(elm->Get(1));
node::Utf8Value ip(env->isolate(), elm->Get(1));

ares_addr_node* cur = &servers[i];

Expand Down
2 changes: 1 addition & 1 deletion src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
return env->ThrowTypeError("Bad arguments");
}

node::Utf8Value path(args[0]);
node::Utf8Value path(env->isolate(), args[0]);

unsigned int flags = 0;
if (args[2]->IsTrue())
Expand Down
46 changes: 24 additions & 22 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ enum encoding ParseEncoding(Isolate* isolate,
if (!encoding_v->IsString())
return _default;

node::Utf8Value encoding(encoding_v);
node::Utf8Value encoding(isolate, encoding_v);

if (strcasecmp(*encoding, "utf8") == 0) {
return UTF8;
Expand Down Expand Up @@ -1275,11 +1275,11 @@ void AppendExceptionLine(Environment* env,
char arrow[1024];

// Print (filename):(line number): (message).
node::Utf8Value filename(message->GetScriptResourceName());
node::Utf8Value filename(env->isolate(), message->GetScriptResourceName());
const char* filename_string = *filename;
int linenum = message->GetLineNumber();
// Print line of source code.
node::Utf8Value sourceline(message->GetSourceLine());
node::Utf8Value sourceline(env->isolate(), message->GetSourceLine());
const char* sourceline_string = *sourceline;

// Because of how node modules work, all scripts are wrapped with a
Expand Down Expand Up @@ -1378,7 +1378,7 @@ static void ReportException(Environment* env,
else
trace_value = er->ToObject(env->isolate())->Get(env->stack_string());

node::Utf8Value trace(trace_value);
node::Utf8Value trace(env->isolate(), trace_value);

// range errors have a trace member set to undefined
if (trace.length() > 0 && !trace_value->IsUndefined()) {
Expand All @@ -1401,11 +1401,11 @@ static void ReportException(Environment* env,
name.IsEmpty() ||
name->IsUndefined()) {
// Not an error object. Just print as-is.
node::Utf8Value message(er);
node::Utf8Value message(env->isolate(), er);
fprintf(stderr, "%s\n", *message);
} else {
node::Utf8Value name_string(name);
node::Utf8Value message_string(message);
node::Utf8Value name_string(env->isolate(), name);
node::Utf8Value message_string(env->isolate(), message);
fprintf(stderr, "%s: %s\n", *name_string, *message_string);
}
}
Expand Down Expand Up @@ -1503,7 +1503,7 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
return env->ThrowError("Bad argument.");
}

node::Utf8Value path(args[0]);
node::Utf8Value path(args.GetIsolate(), args[0]);
int err = uv_chdir(*path);
if (err) {
return env->ThrowUVException(err, "uv_chdir");
Expand Down Expand Up @@ -1549,7 +1549,7 @@ static void Umask(const FunctionCallbackInfo<Value>& args) {
oct = args[0]->Uint32Value();
} else {
oct = 0;
node::Utf8Value str(args[0]);
node::Utf8Value str(env->isolate(), args[0]);

// Parse the octal string.
for (size_t i = 0; i < str.length(); i++) {
Expand Down Expand Up @@ -1656,7 +1656,8 @@ static uid_t uid_by_name(Handle<Value> value) {
if (value->IsUint32()) {
return static_cast<uid_t>(value->Uint32Value());
} else {
node::Utf8Value name(value);
// TODO(trevnorris): Fix to not use GetCurrent().
node::Utf8Value name(Isolate::GetCurrent(), value);
return uid_by_name(*name);
}
}
Expand All @@ -1666,7 +1667,8 @@ static gid_t gid_by_name(Handle<Value> value) {
if (value->IsUint32()) {
return static_cast<gid_t>(value->Uint32Value());
} else {
node::Utf8Value name(value);
// TODO(trevnorris): Fix to not use GetCurrent().
node::Utf8Value name(Isolate::GetCurrent(), value);
return gid_by_name(*name);
}
}
Expand Down Expand Up @@ -1802,7 +1804,7 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {
return env->ThrowTypeError("argument 2 must be a number or a string");
}

node::Utf8Value arg0(args[0]);
node::Utf8Value arg0(env->isolate(), args[0]);
gid_t extra_group;
bool must_free;
char* user;
Expand Down Expand Up @@ -1989,7 +1991,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
}

Local<Object> module = args[0]->ToObject(env->isolate()); // Cast
node::Utf8Value filename(args[1]); // Cast
node::Utf8Value filename(env->isolate(), args[1]); // Cast
const bool is_dlopen_error = uv_dlopen(*filename, &lib);

// Objects containing v14 or later modules will have registered themselves
Expand Down Expand Up @@ -2124,7 +2126,7 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Local<String> module = args[0]->ToString(env->isolate());
node::Utf8Value module_v(module);
node::Utf8Value module_v(env->isolate(), module);

Local<Object> cache = env->binding_cache_object();
Local<Object> exports;
Expand Down Expand Up @@ -2184,7 +2186,7 @@ static void LinkedBinding(const FunctionCallbackInfo<Value>& args) {
if (exports_v->IsObject())
return args.GetReturnValue().Set(exports_v.As<Object>());

node::Utf8Value module_v(module);
node::Utf8Value module_v(env->isolate(), module);
node_module* mod = get_linked_module(*module_v);

if (mod == nullptr) {
Expand Down Expand Up @@ -2229,7 +2231,7 @@ static void ProcessTitleSetter(Local<String> property,
const PropertyCallbackInfo<void>& info) {
Environment* env = Environment::GetCurrent(info.GetIsolate());
HandleScope scope(env->isolate());
node::Utf8Value title(value);
node::Utf8Value title(env->isolate(), value);
// TODO(piscisaureus): protect with a lock
uv_set_process_title(*title);
}
Expand All @@ -2240,7 +2242,7 @@ static void EnvGetter(Local<String> property,
Environment* env = Environment::GetCurrent(info.GetIsolate());
HandleScope scope(env->isolate());
#ifdef __POSIX__
node::Utf8Value key(property);
node::Utf8Value key(env->isolate(), property);
const char* val = getenv(*key);
if (val) {
return info.GetReturnValue().Set(String::NewFromUtf8(env->isolate(), val));
Expand Down Expand Up @@ -2273,8 +2275,8 @@ static void EnvSetter(Local<String> property,
Environment* env = Environment::GetCurrent(info.GetIsolate());
HandleScope scope(env->isolate());
#ifdef __POSIX__
node::Utf8Value key(property);
node::Utf8Value val(value);
node::Utf8Value key(env->isolate(), property);
node::Utf8Value val(env->isolate(), value);
setenv(*key, *val, 1);
#else // _WIN32
String::Value key(property);
Expand All @@ -2296,7 +2298,7 @@ static void EnvQuery(Local<String> property,
HandleScope scope(env->isolate());
int32_t rc = -1; // Not found unless proven otherwise.
#ifdef __POSIX__
node::Utf8Value key(property);
node::Utf8Value key(env->isolate(), property);
if (getenv(*key))
rc = 0;
#else // _WIN32
Expand Down Expand Up @@ -2324,7 +2326,7 @@ static void EnvDeleter(Local<String> property,
HandleScope scope(env->isolate());
bool rc = true;
#ifdef __POSIX__
node::Utf8Value key(property);
node::Utf8Value key(env->isolate(), property);
rc = getenv(*key) != nullptr;
if (rc)
unsetenv(*key);
Expand Down Expand Up @@ -2783,7 +2785,7 @@ static void SignalExit(int signo) {
static void RawDebug(const FunctionCallbackInfo<Value>& args) {
CHECK(args.Length() == 1 && args[0]->IsString() &&
"must be called with a single string");
node::Utf8Value message(args[0]);
node::Utf8Value message(args.GetIsolate(), args[0]);
fprintf(stderr, "%s\n", *message);
fflush(stderr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
return;
}

node::Utf8Value str(args[1]);
node::Utf8Value str(args.GetIsolate(), args[1]);
size_t str_length = str.length();
size_t in_there = str_length;
char* ptr = obj_data + start + str_length;
Expand Down
Loading

0 comments on commit cbf76c1

Please sign in to comment.