Browse Source

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: https://github.com/nodejs/node/issues/8096
Fixes: https://github.com/nodejs/node/issues/8539
Refs: https://github.com/nodejs/node/issues/9722
PR-URL: https://github.com/nodejs/node/pull/8312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
v6
cjihrig 8 years ago
parent
commit
45c9ca7fd4
  1. 20
      src/process_wrap.cc
  2. 19
      src/spawn_sync.cc

20
src/process_wrap.cc

@ -121,35 +121,29 @@ class ProcessWrap : public HandleWrap {
// options.uid // options.uid
Local<Value> uid_v = js_options->Get(env->uid_string()); Local<Value> uid_v = js_options->Get(env->uid_string());
if (uid_v->IsInt32()) { if (!uid_v->IsUndefined() && !uid_v->IsNull()) {
CHECK(uid_v->IsInt32());
const int32_t uid = uid_v->Int32Value(env->context()).FromJust(); const int32_t uid = uid_v->Int32Value(env->context()).FromJust();
options.flags |= UV_PROCESS_SETUID; options.flags |= UV_PROCESS_SETUID;
options.uid = static_cast<uv_uid_t>(uid); options.uid = static_cast<uv_uid_t>(uid);
} else if (!uid_v->IsUndefined() && !uid_v->IsNull()) {
return env->ThrowTypeError("options.uid should be a number");
} }
// options.gid // options.gid
Local<Value> gid_v = js_options->Get(env->gid_string()); Local<Value> gid_v = js_options->Get(env->gid_string());
if (gid_v->IsInt32()) { if (!gid_v->IsUndefined() && !gid_v->IsNull()) {
CHECK(gid_v->IsInt32());
const int32_t gid = gid_v->Int32Value(env->context()).FromJust(); const int32_t gid = gid_v->Int32Value(env->context()).FromJust();
options.flags |= UV_PROCESS_SETGID; options.flags |= UV_PROCESS_SETGID;
options.gid = static_cast<uv_gid_t>(gid); options.gid = static_cast<uv_gid_t>(gid);
} else if (!gid_v->IsUndefined() && !gid_v->IsNull()) {
return env->ThrowTypeError("options.gid should be a number");
} }
// TODO(bnoordhuis) is this possible to do without mallocing ? // TODO(bnoordhuis) is this possible to do without mallocing ?
// options.file // options.file
Local<Value> file_v = js_options->Get(env->file_string()); Local<Value> file_v = js_options->Get(env->file_string());
node::Utf8Value file(env->isolate(), CHECK(file_v->IsString());
file_v->IsString() ? file_v : Local<Value>()); node::Utf8Value file(env->isolate(), file_v);
if (file.length() > 0) { options.file = *file;
options.file = *file;
} else {
return env->ThrowTypeError("Bad argument");
}
// options.args // options.args
Local<Value> argv_v = js_options->Get(env->args_string()); Local<Value> argv_v = js_options->Get(env->args_string());

19
src/spawn_sync.cc

@ -734,8 +734,7 @@ int SyncProcessRunner::ParseOptions(Local<Value> js_value) {
} }
Local<Value> js_uid = js_options->Get(env()->uid_string()); Local<Value> js_uid = js_options->Get(env()->uid_string());
if (IsSet(js_uid)) { if (IsSet(js_uid)) {
if (!js_uid->IsInt32()) CHECK(js_uid->IsInt32());
return UV_EINVAL;
const int32_t uid = js_uid->Int32Value(env()->context()).FromJust(); const int32_t uid = js_uid->Int32Value(env()->context()).FromJust();
uv_process_options_.uid = static_cast<uv_uid_t>(uid); uv_process_options_.uid = static_cast<uv_uid_t>(uid);
uv_process_options_.flags |= UV_PROCESS_SETUID; uv_process_options_.flags |= UV_PROCESS_SETUID;
@ -743,8 +742,7 @@ int SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Local<Value> js_gid = js_options->Get(env()->gid_string()); Local<Value> js_gid = js_options->Get(env()->gid_string());
if (IsSet(js_gid)) { if (IsSet(js_gid)) {
if (!js_gid->IsInt32()) CHECK(js_gid->IsInt32());
return UV_EINVAL;
const int32_t gid = js_gid->Int32Value(env()->context()).FromJust(); const int32_t gid = js_gid->Int32Value(env()->context()).FromJust();
uv_process_options_.gid = static_cast<uv_gid_t>(gid); uv_process_options_.gid = static_cast<uv_gid_t>(gid);
uv_process_options_.flags |= UV_PROCESS_SETGID; uv_process_options_.flags |= UV_PROCESS_SETGID;
@ -760,28 +758,21 @@ int SyncProcessRunner::ParseOptions(Local<Value> js_value) {
Local<Value> js_timeout = js_options->Get(env()->timeout_string()); Local<Value> js_timeout = js_options->Get(env()->timeout_string());
if (IsSet(js_timeout)) { if (IsSet(js_timeout)) {
if (!js_timeout->IsNumber()) CHECK(js_timeout->IsNumber());
return UV_EINVAL;
int64_t timeout = js_timeout->IntegerValue(); int64_t timeout = js_timeout->IntegerValue();
if (timeout < 0)
return UV_EINVAL;
timeout_ = static_cast<uint64_t>(timeout); timeout_ = static_cast<uint64_t>(timeout);
} }
Local<Value> js_max_buffer = js_options->Get(env()->max_buffer_string()); Local<Value> js_max_buffer = js_options->Get(env()->max_buffer_string());
if (IsSet(js_max_buffer)) { if (IsSet(js_max_buffer)) {
if (!js_max_buffer->IsUint32()) CHECK(js_max_buffer->IsUint32());
return UV_EINVAL;
max_buffer_ = js_max_buffer->Uint32Value(); max_buffer_ = js_max_buffer->Uint32Value();
} }
Local<Value> js_kill_signal = js_options->Get(env()->kill_signal_string()); Local<Value> js_kill_signal = js_options->Get(env()->kill_signal_string());
if (IsSet(js_kill_signal)) { if (IsSet(js_kill_signal)) {
if (!js_kill_signal->IsInt32()) CHECK(js_kill_signal->IsInt32());
return UV_EINVAL;
kill_signal_ = js_kill_signal->Int32Value(); kill_signal_ = js_kill_signal->Int32Value();
if (kill_signal_ == 0)
return UV_EINVAL;
} }
Local<Value> js_stdio = js_options->Get(env()->stdio_string()); Local<Value> js_stdio = js_options->Get(env()->stdio_string());

Loading…
Cancel
Save