Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: pass Isolate where necessary #244

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
76 changes: 39 additions & 37 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ Local<Value> ErrnoException(Isolate* isolate,
e = Exception::Error(cons2);
}

Local<Object> obj = e->ToObject();
Local<Object> obj = e->ToObject(env->isolate());
obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno));
obj->Set(env->code_string(), estring);

Expand Down Expand Up @@ -819,7 +819,7 @@ Local<Value> UVException(Isolate* isolate,
e = Exception::Error(cons2);
}

Local<Object> obj = e->ToObject();
Local<Object> obj = e->ToObject(env->isolate());
// TODO(piscisaureus) errno should probably go
obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno));
obj->Set(env->code_string(), estring);
Expand Down Expand Up @@ -899,7 +899,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
e = Exception::Error(message);
}

Local<Object> obj = e->ToObject();
Local<Object> obj = e->ToObject(env->isolate());
obj->Set(env->errno_string(), Integer::New(isolate, errorno));

if (path != nullptr) {
Expand Down 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 @@ -1350,9 +1350,9 @@ void AppendExceptionLine(Environment* env,
goto print;

err_obj->Set(env->message_string(),
String::Concat(arrow_str, msg->ToString()));
String::Concat(arrow_str, msg->ToString(env->isolate())));
err_obj->Set(env->stack_string(),
String::Concat(arrow_str, stack->ToString()));
String::Concat(arrow_str, stack->ToString(env->isolate())));
return;

print:
Expand All @@ -1376,9 +1376,9 @@ static void ReportException(Environment* env,
if (er->IsUndefined() || er->IsNull())
trace_value = Undefined(env->isolate());
else
trace_value = er->ToObject()->Get(env->stack_string());
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 @@ -1988,8 +1990,8 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
return;
}

Local<Object> module = args[0]->ToObject(); // Cast
node::Utf8Value filename(args[1]); // Cast
Local<Object> module = args[0]->ToObject(env->isolate()); // 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 All @@ -2002,7 +2004,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
Local<String> errmsg = OneByteString(env->isolate(), uv_dlerror(&lib));
#ifdef _WIN32
// Windows needs to add the filename into the error message
errmsg = String::Concat(errmsg, args[1]->ToString());
errmsg = String::Concat(errmsg, args[1]->ToString(env->isolate()));
#endif // _WIN32
env->isolate()->ThrowException(Exception::Error(errmsg));
return;
Expand Down Expand Up @@ -2031,7 +2033,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
modlist_addon = mp;

Local<String> exports_string = env->exports_string();
Local<Object> exports = module->Get(exports_string)->ToObject();
Local<Object> exports = module->Get(exports_string)->ToObject(env->isolate());

if (mp->nm_context_register_func != nullptr) {
mp->nm_context_register_func(exports, module, env->context(), mp->nm_priv);
Expand Down Expand Up @@ -2123,14 +2125,14 @@ void OnMessage(Handle<Message> message, Handle<Value> error) {
static void Binding(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

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

Local<Object> cache = env->binding_cache_object();
Local<Object> exports;

if (cache->Has(module)) {
exports = cache->Get(module)->ToObject();
exports = cache->Get(module)->ToObject(env->isolate());
args.GetReturnValue().Set(exports);
return;
}
Expand Down Expand Up @@ -2176,15 +2178,15 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
static void LinkedBinding(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());

Local<String> module = args[0]->ToString();
Local<String> module = args[0]->ToString(env->isolate());

Local<Object> cache = env->binding_cache_object();
Local<Value> exports_v = cache->Get(module);

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 All @@ -2792,8 +2794,8 @@ static void RawDebug(const FunctionCallbackInfo<Value>& args) {
void LoadEnvironment(Environment* env) {
HandleScope handle_scope(env->isolate());

V8::SetFatalErrorHandler(node::OnFatalError);
V8::AddMessageListener(OnMessage);
env->isolate()->SetFatalErrorHandler(node::OnFatalError);
env->isolate()->AddMessageListener(OnMessage);

// Compile, execute the src/node.js file. (Which was included as static C
// string in node_natives.h. 'natve_node' is the string containing that
Expand Down Expand Up @@ -3485,7 +3487,7 @@ void EmitBeforeExit(Environment* env) {
Local<String> exit_code = FIXED_ONE_BYTE_STRING(env->isolate(), "exitCode");
Local<Value> args[] = {
FIXED_ONE_BYTE_STRING(env->isolate(), "beforeExit"),
process_object->Get(exit_code)->ToInteger()
process_object->Get(exit_code)->ToInteger(env->isolate())
};
MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args);
}
Expand Down
8 changes: 4 additions & 4 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void Base64Slice(const FunctionCallbackInfo<Value>& args) {
void Copy(const FunctionCallbackInfo<Value> &args) {
Environment* env = Environment::GetCurrent(args);

Local<Object> target = args[0]->ToObject();
Local<Object> target = args[0]->ToObject(env->isolate());

if (!HasInstance(target))
return env->ThrowTypeError("first arg should be a Buffer");
Expand Down 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 Expand Up @@ -421,7 +421,7 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) {
if (!args[0]->IsString())
return env->ThrowTypeError("Argument must be a string");

Local<String> str = args[0]->ToString();
Local<String> str = args[0]->ToString(env->isolate());

if (encoding == HEX && str->Length() % 2 != 0)
return env->ThrowTypeError("Invalid hex string");
Expand Down Expand Up @@ -583,7 +583,7 @@ void ByteLength(const FunctionCallbackInfo<Value> &args) {
if (!args[0]->IsString())
return env->ThrowTypeError("Argument must be a string");

Local<String> s = args[0]->ToString();
Local<String> s = args[0]->ToString(env->isolate());
enum encoding e = ParseEncoding(env->isolate(), args[1], UTF8);

uint32_t size = StringBytes::Size(env->isolate(), s, e);
Expand Down
Loading