@@ -93,39 +93,46 @@ class ProcessWrap : public HandleWrap {
93
93
static void ParseStdioOptions (Environment* env,
94
94
Local<Object> js_options,
95
95
uv_process_options_t * options) {
96
+ Local<Context> context = env->context ();
96
97
Local<String> stdio_key = env->stdio_string ();
97
- Local<Array> stdios = js_options->Get (stdio_key).As <Array>();
98
+ Local<Array> stdios =
99
+ js_options->Get (context, stdio_key).ToLocalChecked ().As <Array>();
98
100
99
101
uint32_t len = stdios->Length ();
100
102
options->stdio = new uv_stdio_container_t [len];
101
103
options->stdio_count = len;
102
104
103
105
for (uint32_t i = 0 ; i < len; i++) {
104
- Local<Object> stdio = stdios->Get (i).As <Object>();
105
- Local<Value> type = stdio->Get (env->type_string ());
106
+ Local<Object> stdio =
107
+ stdios->Get (context, i).ToLocalChecked ().As <Object>();
108
+ Local<Value> type =
109
+ stdio->Get (context, env->type_string ()).ToLocalChecked ();
106
110
107
111
if (type->Equals (env->ignore_string ())) {
108
112
options->stdio [i].flags = UV_IGNORE;
109
113
} else if (type->Equals (env->pipe_string ())) {
110
114
options->stdio [i].flags = static_cast <uv_stdio_flags>(
111
115
UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE);
112
116
Local<String> handle_key = env->handle_string ();
113
- Local<Object> handle = stdio->Get (handle_key).As <Object>();
117
+ Local<Object> handle =
118
+ stdio->Get (context, handle_key).ToLocalChecked ().As <Object>();
114
119
CHECK (!handle.IsEmpty ());
115
120
options->stdio [i].data .stream =
116
121
reinterpret_cast <uv_stream_t *>(
117
122
Unwrap<PipeWrap>(handle)->UVHandle ());
118
123
} else if (type->Equals (env->wrap_string ())) {
119
124
Local<String> handle_key = env->handle_string ();
120
- Local<Object> handle = stdio->Get (handle_key).As <Object>();
125
+ Local<Object> handle =
126
+ stdio->Get (context, handle_key).ToLocalChecked ().As <Object>();
121
127
uv_stream_t * stream = HandleToStream (env, handle);
122
128
CHECK_NE (stream, nullptr );
123
129
124
130
options->stdio [i].flags = UV_INHERIT_STREAM;
125
131
options->stdio [i].data .stream = stream;
126
132
} else {
127
133
Local<String> fd_key = env->fd_string ();
128
- int fd = static_cast <int >(stdio->Get (fd_key)->IntegerValue ());
134
+ int fd = static_cast <int >(
135
+ stdio->Get (context, fd_key).ToLocalChecked ()->IntegerValue ());
129
136
options->stdio [i].flags = UV_INHERIT_FD;
130
137
options->stdio [i].data .fd = fd;
131
138
}
@@ -134,7 +141,7 @@ class ProcessWrap : public HandleWrap {
134
141
135
142
static void Spawn (const FunctionCallbackInfo<Value>& args) {
136
143
Environment* env = Environment::GetCurrent (args);
137
-
144
+ Local<Context> context = env-> context ();
138
145
ProcessWrap* wrap;
139
146
ASSIGN_OR_RETURN_UNWRAP (&wrap, args.Holder ());
140
147
@@ -146,62 +153,70 @@ class ProcessWrap : public HandleWrap {
146
153
options.exit_cb = OnExit;
147
154
148
155
// options.uid
149
- Local<Value> uid_v = js_options->Get (env->uid_string ());
156
+ Local<Value> uid_v =
157
+ js_options->Get (context, env->uid_string ()).ToLocalChecked ();
150
158
if (!uid_v->IsUndefined () && !uid_v->IsNull ()) {
151
159
CHECK (uid_v->IsInt32 ());
152
- const int32_t uid = uid_v->Int32Value (env-> context () ).FromJust ();
160
+ const int32_t uid = uid_v->Int32Value (context).FromJust ();
153
161
options.flags |= UV_PROCESS_SETUID;
154
162
options.uid = static_cast <uv_uid_t >(uid);
155
163
}
156
164
157
165
// options.gid
158
- Local<Value> gid_v = js_options->Get (env->gid_string ());
166
+ Local<Value> gid_v =
167
+ js_options->Get (context, env->gid_string ()).ToLocalChecked ();
159
168
if (!gid_v->IsUndefined () && !gid_v->IsNull ()) {
160
169
CHECK (gid_v->IsInt32 ());
161
- const int32_t gid = gid_v->Int32Value (env-> context () ).FromJust ();
170
+ const int32_t gid = gid_v->Int32Value (context).FromJust ();
162
171
options.flags |= UV_PROCESS_SETGID;
163
172
options.gid = static_cast <uv_gid_t >(gid);
164
173
}
165
174
166
175
// TODO(bnoordhuis) is this possible to do without mallocing ?
167
176
168
177
// options.file
169
- Local<Value> file_v = js_options->Get (env->file_string ());
178
+ Local<Value> file_v =
179
+ js_options->Get (context, env->file_string ()).ToLocalChecked ();
170
180
CHECK (file_v->IsString ());
171
181
node::Utf8Value file (env->isolate (), file_v);
172
182
options.file = *file;
173
183
174
184
// options.args
175
- Local<Value> argv_v = js_options->Get (env->args_string ());
185
+ Local<Value> argv_v =
186
+ js_options->Get (context, env->args_string ()).ToLocalChecked ();
176
187
if (!argv_v.IsEmpty () && argv_v->IsArray ()) {
177
188
Local<Array> js_argv = Local<Array>::Cast (argv_v);
178
189
int argc = js_argv->Length ();
179
190
// Heap allocate to detect errors. +1 is for nullptr.
180
191
options.args = new char *[argc + 1 ];
181
192
for (int i = 0 ; i < argc; i++) {
182
- node::Utf8Value arg (env->isolate (), js_argv->Get (i));
193
+ node::Utf8Value arg (env->isolate (),
194
+ js_argv->Get (context, i).ToLocalChecked ());
183
195
options.args [i] = strdup (*arg);
184
196
CHECK_NE (options.args [i], nullptr );
185
197
}
186
198
options.args [argc] = nullptr ;
187
199
}
188
200
189
201
// options.cwd
190
- Local<Value> cwd_v = js_options->Get (env->cwd_string ());
202
+ Local<Value> cwd_v =
203
+ js_options->Get (context, env->cwd_string ()).ToLocalChecked ();
191
204
node::Utf8Value cwd (env->isolate (),
192
205
cwd_v->IsString () ? cwd_v : Local<Value>());
193
206
if (cwd.length () > 0 ) {
194
207
options.cwd = *cwd;
195
208
}
196
209
197
210
// options.env
198
- Local<Value> env_v = js_options->Get (env->env_pairs_string ());
211
+ Local<Value> env_v =
212
+ js_options->Get (context, env->env_pairs_string ()).ToLocalChecked ();
199
213
if (!env_v.IsEmpty () && env_v->IsArray ()) {
200
214
Local<Array> env_opt = Local<Array>::Cast (env_v);
201
215
int envc = env_opt->Length ();
202
216
options.env = new char *[envc + 1 ]; // Heap allocated to detect errors.
203
217
for (int i = 0 ; i < envc; i++) {
204
- node::Utf8Value pair (env->isolate (), env_opt->Get (i));
218
+ node::Utf8Value pair (env->isolate (),
219
+ env_opt->Get (context, i).ToLocalChecked ());
205
220
options.env [i] = strdup (*pair);
206
221
CHECK_NE (options.env [i], nullptr );
207
222
}
@@ -212,31 +227,37 @@ class ProcessWrap : public HandleWrap {
212
227
ParseStdioOptions (env, js_options, &options);
213
228
214
229
// options.windowsHide
215
- Local<String> windows_hide_key = env->windows_hide_string ();
230
+ Local<Value> hide_v =
231
+ js_options->Get (context, env->windows_hide_string ()).ToLocalChecked ();
216
232
217
- if (js_options-> Get (windows_hide_key) ->IsTrue ()) {
233
+ if (hide_v ->IsTrue ()) {
218
234
options.flags |= UV_PROCESS_WINDOWS_HIDE;
219
235
}
220
236
221
237
// options.windows_verbatim_arguments
222
- Local<String> windows_verbatim_arguments_key =
223
- env->windows_verbatim_arguments_string ();
224
- if (js_options->Get (windows_verbatim_arguments_key)->IsTrue ()) {
238
+ Local<Value> wva_v =
239
+ js_options->Get (context, env->windows_verbatim_arguments_string ())
240
+ .ToLocalChecked ();
241
+
242
+ if (wva_v->IsTrue ()) {
225
243
options.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
226
244
}
227
245
228
246
// options.detached
229
- Local<String> detached_key = env->detached_string ();
230
- if (js_options->Get (detached_key)->IsTrue ()) {
247
+ Local<Value> detached_v =
248
+ js_options->Get (context, env->detached_string ()).ToLocalChecked ();
249
+
250
+ if (detached_v->IsTrue ()) {
231
251
options.flags |= UV_PROCESS_DETACHED;
232
252
}
233
253
234
254
int err = uv_spawn (env->event_loop (), &wrap->process_ , &options);
235
255
236
256
if (err == 0 ) {
237
257
CHECK_EQ (wrap->process_ .data , wrap);
238
- wrap->object ()->Set (env->pid_string (),
239
- Integer::New (env->isolate (), wrap->process_ .pid ));
258
+ wrap->object ()->Set (context, env->pid_string (),
259
+ Integer::New (env->isolate (),
260
+ wrap->process_ .pid )).FromJust ();
240
261
}
241
262
242
263
if (options.args ) {
@@ -255,9 +276,10 @@ class ProcessWrap : public HandleWrap {
255
276
}
256
277
257
278
static void Kill (const FunctionCallbackInfo<Value>& args) {
279
+ Environment* env = Environment::GetCurrent (args);
258
280
ProcessWrap* wrap;
259
281
ASSIGN_OR_RETURN_UNWRAP (&wrap, args.Holder ());
260
- int signal = args[0 ]->Int32Value ();
282
+ int signal = args[0 ]->Int32Value (env-> context ()). FromJust ( );
261
283
int err = uv_process_kill (&wrap->process_ , signal );
262
284
args.GetReturnValue ().Set (err);
263
285
}
0 commit comments