Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Commit 8efc0f9

Browse files
cjihrigaddaleax
authored andcommitted
src: increase usage of context in process_wrap.cc
Refs: nodejs/node#15380 PR-URL: nodejs/node#16247 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d3cb315 commit 8efc0f9

File tree

1 file changed

+49
-27
lines changed

1 file changed

+49
-27
lines changed

src/process_wrap.cc

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,46 @@ class ProcessWrap : public HandleWrap {
9494
static void ParseStdioOptions(Environment* env,
9595
Local<Object> js_options,
9696
uv_process_options_t* options) {
97+
Local<Context> context = env->context();
9798
Local<String> stdio_key = env->stdio_string();
98-
Local<Array> stdios = js_options->Get(stdio_key).As<Array>();
99+
Local<Array> stdios =
100+
js_options->Get(context, stdio_key).ToLocalChecked().As<Array>();
99101

100102
uint32_t len = stdios->Length();
101103
options->stdio = new uv_stdio_container_t[len];
102104
options->stdio_count = len;
103105

104106
for (uint32_t i = 0; i < len; i++) {
105-
Local<Object> stdio = stdios->Get(i).As<Object>();
106-
Local<Value> type = stdio->Get(env->type_string());
107+
Local<Object> stdio =
108+
stdios->Get(context, i).ToLocalChecked().As<Object>();
109+
Local<Value> type =
110+
stdio->Get(context, env->type_string()).ToLocalChecked();
107111

108112
if (type->Equals(env->ignore_string())) {
109113
options->stdio[i].flags = UV_IGNORE;
110114
} else if (type->Equals(env->pipe_string())) {
111115
options->stdio[i].flags = static_cast<uv_stdio_flags>(
112116
UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE);
113117
Local<String> handle_key = env->handle_string();
114-
Local<Object> handle = stdio->Get(handle_key).As<Object>();
118+
Local<Object> handle =
119+
stdio->Get(context, handle_key).ToLocalChecked().As<Object>();
115120
CHECK(!handle.IsEmpty());
116121
options->stdio[i].data.stream =
117122
reinterpret_cast<uv_stream_t*>(
118123
Unwrap<PipeWrap>(handle)->UVHandle());
119124
} else if (type->Equals(env->wrap_string())) {
120125
Local<String> handle_key = env->handle_string();
121-
Local<Object> handle = stdio->Get(handle_key).As<Object>();
126+
Local<Object> handle =
127+
stdio->Get(context, handle_key).ToLocalChecked().As<Object>();
122128
uv_stream_t* stream = HandleToStream(env, handle);
123129
CHECK_NE(stream, nullptr);
124130

125131
options->stdio[i].flags = UV_INHERIT_STREAM;
126132
options->stdio[i].data.stream = stream;
127133
} else {
128134
Local<String> fd_key = env->fd_string();
129-
int fd = static_cast<int>(stdio->Get(fd_key)->IntegerValue());
135+
int fd = static_cast<int>(
136+
stdio->Get(context, fd_key).ToLocalChecked()->IntegerValue());
130137
options->stdio[i].flags = UV_INHERIT_FD;
131138
options->stdio[i].data.fd = fd;
132139
}
@@ -135,7 +142,7 @@ class ProcessWrap : public HandleWrap {
135142

136143
static void Spawn(const FunctionCallbackInfo<Value>& args) {
137144
Environment* env = Environment::GetCurrent(args);
138-
145+
Local<Context> context = env->context();
139146
ProcessWrap* wrap;
140147
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
141148

@@ -147,62 +154,70 @@ class ProcessWrap : public HandleWrap {
147154
options.exit_cb = OnExit;
148155

149156
// options.uid
150-
Local<Value> uid_v = js_options->Get(env->uid_string());
157+
Local<Value> uid_v =
158+
js_options->Get(context, env->uid_string()).ToLocalChecked();
151159
if (!uid_v->IsUndefined() && !uid_v->IsNull()) {
152160
CHECK(uid_v->IsInt32());
153-
const int32_t uid = uid_v->Int32Value(env->context()).FromJust();
161+
const int32_t uid = uid_v->Int32Value(context).FromJust();
154162
options.flags |= UV_PROCESS_SETUID;
155163
options.uid = static_cast<uv_uid_t>(uid);
156164
}
157165

158166
// options.gid
159-
Local<Value> gid_v = js_options->Get(env->gid_string());
167+
Local<Value> gid_v =
168+
js_options->Get(context, env->gid_string()).ToLocalChecked();
160169
if (!gid_v->IsUndefined() && !gid_v->IsNull()) {
161170
CHECK(gid_v->IsInt32());
162-
const int32_t gid = gid_v->Int32Value(env->context()).FromJust();
171+
const int32_t gid = gid_v->Int32Value(context).FromJust();
163172
options.flags |= UV_PROCESS_SETGID;
164173
options.gid = static_cast<uv_gid_t>(gid);
165174
}
166175

167176
// TODO(bnoordhuis) is this possible to do without mallocing ?
168177

169178
// options.file
170-
Local<Value> file_v = js_options->Get(env->file_string());
179+
Local<Value> file_v =
180+
js_options->Get(context, env->file_string()).ToLocalChecked();
171181
CHECK(file_v->IsString());
172182
node::Utf8Value file(env->isolate(), file_v);
173183
options.file = *file;
174184

175185
// options.args
176-
Local<Value> argv_v = js_options->Get(env->args_string());
186+
Local<Value> argv_v =
187+
js_options->Get(context, env->args_string()).ToLocalChecked();
177188
if (!argv_v.IsEmpty() && argv_v->IsArray()) {
178189
Local<Array> js_argv = Local<Array>::Cast(argv_v);
179190
int argc = js_argv->Length();
180191
// Heap allocate to detect errors. +1 is for nullptr.
181192
options.args = new char*[argc + 1];
182193
for (int i = 0; i < argc; i++) {
183-
node::Utf8Value arg(env->isolate(), js_argv->Get(i));
194+
node::Utf8Value arg(env->isolate(),
195+
js_argv->Get(context, i).ToLocalChecked());
184196
options.args[i] = strdup(*arg);
185197
CHECK_NE(options.args[i], nullptr);
186198
}
187199
options.args[argc] = nullptr;
188200
}
189201

190202
// options.cwd
191-
Local<Value> cwd_v = js_options->Get(env->cwd_string());
203+
Local<Value> cwd_v =
204+
js_options->Get(context, env->cwd_string()).ToLocalChecked();
192205
node::Utf8Value cwd(env->isolate(),
193206
cwd_v->IsString() ? cwd_v : Local<Value>());
194207
if (cwd.length() > 0) {
195208
options.cwd = *cwd;
196209
}
197210

198211
// options.env
199-
Local<Value> env_v = js_options->Get(env->env_pairs_string());
212+
Local<Value> env_v =
213+
js_options->Get(context, env->env_pairs_string()).ToLocalChecked();
200214
if (!env_v.IsEmpty() && env_v->IsArray()) {
201215
Local<Array> env_opt = Local<Array>::Cast(env_v);
202216
int envc = env_opt->Length();
203217
options.env = new char*[envc + 1]; // Heap allocated to detect errors.
204218
for (int i = 0; i < envc; i++) {
205-
node::Utf8Value pair(env->isolate(), env_opt->Get(i));
219+
node::Utf8Value pair(env->isolate(),
220+
env_opt->Get(context, i).ToLocalChecked());
206221
options.env[i] = strdup(*pair);
207222
CHECK_NE(options.env[i], nullptr);
208223
}
@@ -213,22 +228,27 @@ class ProcessWrap : public HandleWrap {
213228
ParseStdioOptions(env, js_options, &options);
214229

215230
// options.windowsHide
216-
Local<String> windows_hide_key = env->windows_hide_string();
231+
Local<Value> hide_v =
232+
js_options->Get(context, env->windows_hide_string()).ToLocalChecked();
217233

218-
if (js_options->Get(windows_hide_key)->IsTrue()) {
234+
if (hide_v->IsTrue()) {
219235
options.flags |= UV_PROCESS_WINDOWS_HIDE;
220236
}
221237

222238
// options.windows_verbatim_arguments
223-
Local<String> windows_verbatim_arguments_key =
224-
env->windows_verbatim_arguments_string();
225-
if (js_options->Get(windows_verbatim_arguments_key)->IsTrue()) {
239+
Local<Value> wva_v =
240+
js_options->Get(context, env->windows_verbatim_arguments_string())
241+
.ToLocalChecked();
242+
243+
if (wva_v->IsTrue()) {
226244
options.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
227245
}
228246

229247
// options.detached
230-
Local<String> detached_key = env->detached_string();
231-
if (js_options->Get(detached_key)->IsTrue()) {
248+
Local<Value> detached_v =
249+
js_options->Get(context, env->detached_string()).ToLocalChecked();
250+
251+
if (detached_v->IsTrue()) {
232252
options.flags |= UV_PROCESS_DETACHED;
233253
}
234254

@@ -237,8 +257,9 @@ class ProcessWrap : public HandleWrap {
237257

238258
if (err == 0) {
239259
CHECK_EQ(wrap->process_.data, wrap);
240-
wrap->object()->Set(env->pid_string(),
241-
Integer::New(env->isolate(), wrap->process_.pid));
260+
wrap->object()->Set(context, env->pid_string(),
261+
Integer::New(env->isolate(),
262+
wrap->process_.pid)).FromJust();
242263
}
243264

244265
if (options.args) {
@@ -257,9 +278,10 @@ class ProcessWrap : public HandleWrap {
257278
}
258279

259280
static void Kill(const FunctionCallbackInfo<Value>& args) {
281+
Environment* env = Environment::GetCurrent(args);
260282
ProcessWrap* wrap;
261283
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
262-
int signal = args[0]->Int32Value();
284+
int signal = args[0]->Int32Value(env->context()).FromJust();
263285
int err = uv_process_kill(&wrap->process_, signal);
264286
args.GetReturnValue().Set(err);
265287
}

0 commit comments

Comments
 (0)