summaryrefslogtreecommitdiff
path: root/src/process_wrap.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/process_wrap.cc')
-rw-r--r--src/process_wrap.cc69
1 files changed, 30 insertions, 39 deletions
diff --git a/src/process_wrap.cc b/src/process_wrap.cc
index f21fef9b8e..31d0432e41 100644
--- a/src/process_wrap.cc
+++ b/src/process_wrap.cc
@@ -50,9 +50,10 @@ class ProcessWrap : public HandleWrap {
static void Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
+ Environment* env = Environment::GetCurrent(context);
Local<FunctionTemplate> constructor = FunctionTemplate::New(New);
constructor->InstanceTemplate()->SetInternalFieldCount(1);
- constructor->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Process"));
+ constructor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"));
NODE_SET_PROTOTYPE_METHOD(constructor, "close", HandleWrap::Close);
@@ -62,7 +63,7 @@ class ProcessWrap : public HandleWrap {
NODE_SET_PROTOTYPE_METHOD(constructor, "ref", HandleWrap::Ref);
NODE_SET_PROTOTYPE_METHOD(constructor, "unref", HandleWrap::Unref);
- target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Process"),
+ target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"),
constructor->GetFunction());
}
@@ -90,8 +91,7 @@ class ProcessWrap : public HandleWrap {
static void ParseStdioOptions(Environment* env,
Local<Object> js_options,
uv_process_options_t* options) {
- Local<String> stdio_key =
- FIXED_ONE_BYTE_STRING(node_isolate, "stdio");
+ Local<String> stdio_key = env->stdio_string();
Local<Array> stdios = js_options->Get(stdio_key).As<Array>();
uint32_t len = stdios->Length();
@@ -100,23 +100,20 @@ class ProcessWrap : public HandleWrap {
for (uint32_t i = 0; i < len; i++) {
Local<Object> stdio = stdios->Get(i).As<Object>();
- Local<Value> type =
- stdio->Get(FIXED_ONE_BYTE_STRING(node_isolate, "type"));
+ Local<Value> type = stdio->Get(env->type_string());
- if (type->Equals(FIXED_ONE_BYTE_STRING(node_isolate, "ignore"))) {
+ if (type->Equals(env->ignore_string())) {
options->stdio[i].flags = UV_IGNORE;
- } else if (type->Equals(FIXED_ONE_BYTE_STRING(node_isolate, "pipe"))) {
+ } else if (type->Equals(env->pipe_string())) {
options->stdio[i].flags = static_cast<uv_stdio_flags>(
UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE);
- Local<String> handle_key =
- FIXED_ONE_BYTE_STRING(node_isolate, "handle");
+ Local<String> handle_key = env->handle_string();
Local<Object> handle = stdio->Get(handle_key).As<Object>();
options->stdio[i].data.stream =
reinterpret_cast<uv_stream_t*>(
Unwrap<PipeWrap>(handle)->UVHandle());
- } else if (type->Equals(FIXED_ONE_BYTE_STRING(node_isolate, "wrap"))) {
- Local<String> handle_key =
- FIXED_ONE_BYTE_STRING(node_isolate, "handle");
+ } else if (type->Equals(env->wrap_string())) {
+ Local<String> handle_key = env->handle_string();
Local<Object> handle = stdio->Get(handle_key).As<Object>();
uv_stream_t* stream = HandleToStream(env, handle);
assert(stream != NULL);
@@ -124,7 +121,7 @@ class ProcessWrap : public HandleWrap {
options->stdio[i].flags = UV_INHERIT_STREAM;
options->stdio[i].data.stream = stream;
} else {
- Local<String> fd_key = FIXED_ONE_BYTE_STRING(node_isolate, "fd");
+ Local<String> fd_key = env->fd_string();
int fd = static_cast<int>(stdio->Get(fd_key)->IntegerValue());
options->stdio[i].flags = UV_INHERIT_FD;
options->stdio[i].data.fd = fd;
@@ -146,48 +143,44 @@ class ProcessWrap : public HandleWrap {
options.exit_cb = OnExit;
// options.uid
- Local<Value> uid_v =
- js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "uid"));
+ Local<Value> uid_v = js_options->Get(env->uid_string());
if (uid_v->IsInt32()) {
int32_t uid = uid_v->Int32Value();
if (uid & ~((uv_uid_t) ~0)) {
- return ThrowRangeError("options.uid is out of range");
+ return env->ThrowRangeError("options.uid is out of range");
}
options.flags |= UV_PROCESS_SETUID;
options.uid = (uv_uid_t) uid;
} else if (!uid_v->IsUndefined() && !uid_v->IsNull()) {
- return ThrowTypeError("options.uid should be a number");
+ return env->ThrowTypeError("options.uid should be a number");
}
// options.gid
- Local<Value> gid_v =
- js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "gid"));
+ Local<Value> gid_v = js_options->Get(env->gid_string());
if (gid_v->IsInt32()) {
int32_t gid = gid_v->Int32Value();
if (gid & ~((uv_gid_t) ~0)) {
- return ThrowRangeError("options.gid is out of range");
+ return env->ThrowRangeError("options.gid is out of range");
}
options.flags |= UV_PROCESS_SETGID;
options.gid = (uv_gid_t) gid;
} else if (!gid_v->IsUndefined() && !gid_v->IsNull()) {
- return ThrowTypeError("options.gid should be a number");
+ return env->ThrowTypeError("options.gid should be a number");
}
// TODO(bnoordhuis) is this possible to do without mallocing ?
// options.file
- Local<Value> file_v =
- js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "file"));
+ Local<Value> file_v = js_options->Get(env->file_string());
String::Utf8Value file(file_v->IsString() ? file_v : Local<Value>());
if (file.length() > 0) {
options.file = *file;
} else {
- return ThrowTypeError("Bad argument");
+ return env->ThrowTypeError("Bad argument");
}
// options.args
- Local<Value> argv_v =
- js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "args"));
+ Local<Value> argv_v = js_options->Get(env->args_string());
if (!argv_v.IsEmpty() && argv_v->IsArray()) {
Local<Array> js_argv = Local<Array>::Cast(argv_v);
int argc = js_argv->Length();
@@ -201,16 +194,14 @@ class ProcessWrap : public HandleWrap {
}
// options.cwd
- Local<Value> cwd_v =
- js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "cwd"));
+ Local<Value> cwd_v = js_options->Get(env->cwd_string());
String::Utf8Value cwd(cwd_v->IsString() ? cwd_v : Local<Value>());
if (cwd.length() > 0) {
options.cwd = *cwd;
}
// options.env
- Local<Value> env_v =
- js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "envPairs"));
+ Local<Value> env_v = js_options->Get(env->env_pairs_string());
if (!env_v.IsEmpty() && env_v->IsArray()) {
Local<Array> env = Local<Array>::Cast(env_v);
int envc = env->Length();
@@ -227,14 +218,13 @@ class ProcessWrap : public HandleWrap {
// options.windows_verbatim_arguments
Local<String> windows_verbatim_arguments_key =
- FIXED_ONE_BYTE_STRING(node_isolate, "windowsVerbatimArguments");
+ env->windows_verbatim_arguments_string();
if (js_options->Get(windows_verbatim_arguments_key)->IsTrue()) {
options.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
}
// options.detached
- Local<String> detached_key =
- FIXED_ONE_BYTE_STRING(node_isolate, "detached");
+ Local<String> detached_key = env->detached_string();
if (js_options->Get(detached_key)->IsTrue()) {
options.flags |= UV_PROCESS_DETACHED;
}
@@ -243,8 +233,8 @@ class ProcessWrap : public HandleWrap {
if (err == 0) {
assert(wrap->process_.data == wrap);
- wrap->object()->Set(FIXED_ONE_BYTE_STRING(node_isolate, "pid"),
- Integer::New(wrap->process_.pid, node_isolate));
+ wrap->object()->Set(env->pid_string(),
+ Integer::New(wrap->process_.pid, env->isolate()));
}
if (options.args) {
@@ -263,7 +253,8 @@ class ProcessWrap : public HandleWrap {
}
static void Kill(const FunctionCallbackInfo<Value>& args) {
- HandleScope scope(node_isolate);
+ Environment* env = Environment::GetCurrent(args.GetIsolate());
+ HandleScope scope(env->isolate());
ProcessWrap* wrap = Unwrap<ProcessWrap>(args.This());
int signal = args[0]->Int32Value();
@@ -283,8 +274,8 @@ class ProcessWrap : public HandleWrap {
Context::Scope context_scope(env->context());
Local<Value> argv[] = {
- Number::New(node_isolate, static_cast<double>(exit_status)),
- OneByteString(node_isolate, signo_string(term_signal))
+ Number::New(env->isolate(), static_cast<double>(exit_status)),
+ OneByteString(env->isolate(), signo_string(term_signal))
};
wrap->MakeCallback(env->onexit_string(), ARRAY_SIZE(argv), argv);