Skip to content

Commit 45c9ca7

Browse files
committed
src: remove redundant spawn/spawnSync type checks
This commit removes C++ checks from spawn() and spawnSync() that are duplicates of the JavaScript type checking. Fixes: #8096 Fixes: #8539 Refs: #9722 PR-URL: #8312 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent fc7b0dd commit 45c9ca7

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

src/process_wrap.cc

+7-13
Original file line numberDiff line numberDiff line change
@@ -121,35 +121,29 @@ class ProcessWrap : public HandleWrap {
121121

122122
// options.uid
123123
Local<Value> uid_v = js_options->Get(env->uid_string());
124-
if (uid_v->IsInt32()) {
124+
if (!uid_v->IsUndefined() && !uid_v->IsNull()) {
125+
CHECK(uid_v->IsInt32());
125126
const int32_t uid = uid_v->Int32Value(env->context()).FromJust();
126127
options.flags |= UV_PROCESS_SETUID;
127128
options.uid = static_cast<uv_uid_t>(uid);
128-
} else if (!uid_v->IsUndefined() && !uid_v->IsNull()) {
129-
return env->ThrowTypeError("options.uid should be a number");
130129
}
131130

132131
// options.gid
133132
Local<Value> gid_v = js_options->Get(env->gid_string());
134-
if (gid_v->IsInt32()) {
133+
if (!gid_v->IsUndefined() && !gid_v->IsNull()) {
134+
CHECK(gid_v->IsInt32());
135135
const int32_t gid = gid_v->Int32Value(env->context()).FromJust();
136136
options.flags |= UV_PROCESS_SETGID;
137137
options.gid = static_cast<uv_gid_t>(gid);
138-
} else if (!gid_v->IsUndefined() && !gid_v->IsNull()) {
139-
return env->ThrowTypeError("options.gid should be a number");
140138
}
141139

142140
// TODO(bnoordhuis) is this possible to do without mallocing ?
143141

144142
// options.file
145143
Local<Value> file_v = js_options->Get(env->file_string());
146-
node::Utf8Value file(env->isolate(),
147-
file_v->IsString() ? file_v : Local<Value>());
148-
if (file.length() > 0) {
149-
options.file = *file;
150-
} else {
151-
return env->ThrowTypeError("Bad argument");
152-
}
144+
CHECK(file_v->IsString());
145+
node::Utf8Value file(env->isolate(), file_v);
146+
options.file = *file;
153147

154148
// options.args
155149
Local<Value> argv_v = js_options->Get(env->args_string());

src/spawn_sync.cc

+5-14
Original file line numberDiff line numberDiff line change
@@ -734,17 +734,15 @@ int SyncProcessRunner::ParseOptions(Local<Value> js_value) {
734734
}
735735
Local<Value> js_uid = js_options->Get(env()->uid_string());
736736
if (IsSet(js_uid)) {
737-
if (!js_uid->IsInt32())
738-
return UV_EINVAL;
737+
CHECK(js_uid->IsInt32());
739738
const int32_t uid = js_uid->Int32Value(env()->context()).FromJust();
740739
uv_process_options_.uid = static_cast<uv_uid_t>(uid);
741740
uv_process_options_.flags |= UV_PROCESS_SETUID;
742741
}
743742

744743
Local<Value> js_gid = js_options->Get(env()->gid_string());
745744
if (IsSet(js_gid)) {
746-
if (!js_gid->IsInt32())
747-
return UV_EINVAL;
745+
CHECK(js_gid->IsInt32());
748746
const int32_t gid = js_gid->Int32Value(env()->context()).FromJust();
749747
uv_process_options_.gid = static_cast<uv_gid_t>(gid);
750748
uv_process_options_.flags |= UV_PROCESS_SETGID;
@@ -760,28 +758,21 @@ int SyncProcessRunner::ParseOptions(Local<Value> js_value) {
760758

761759
Local<Value> js_timeout = js_options->Get(env()->timeout_string());
762760
if (IsSet(js_timeout)) {
763-
if (!js_timeout->IsNumber())
764-
return UV_EINVAL;
761+
CHECK(js_timeout->IsNumber());
765762
int64_t timeout = js_timeout->IntegerValue();
766-
if (timeout < 0)
767-
return UV_EINVAL;
768763
timeout_ = static_cast<uint64_t>(timeout);
769764
}
770765

771766
Local<Value> js_max_buffer = js_options->Get(env()->max_buffer_string());
772767
if (IsSet(js_max_buffer)) {
773-
if (!js_max_buffer->IsUint32())
774-
return UV_EINVAL;
768+
CHECK(js_max_buffer->IsUint32());
775769
max_buffer_ = js_max_buffer->Uint32Value();
776770
}
777771

778772
Local<Value> js_kill_signal = js_options->Get(env()->kill_signal_string());
779773
if (IsSet(js_kill_signal)) {
780-
if (!js_kill_signal->IsInt32())
781-
return UV_EINVAL;
774+
CHECK(js_kill_signal->IsInt32());
782775
kill_signal_ = js_kill_signal->Int32Value();
783-
if (kill_signal_ == 0)
784-
return UV_EINVAL;
785776
}
786777

787778
Local<Value> js_stdio = js_options->Get(env()->stdio_string());

0 commit comments

Comments
 (0)