Repository: nodejs/node
File: src/node_process_methods.cc (C++)

Code before:

  // Get the double array pointer from the Float64Array argument.
  Local<ArrayBuffer> ab = get_fields_array_buffer(args, 0, 2);
  double* fields = static_cast<double*>(ab->Data());

  // Set the Float64Array elements to be user / system values in microseconds.
  fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec;
  fields[1] = MICROS_PER_SEC * rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec;
}

static void Cwd(const FunctionCallbackInfo<Value>& args) {
  Environment* env = Environment::GetCurrent(args);
  CHECK(env->has_run_bootstrapping_code());
  char buf[PATH_MAX_BYTES];
  size_t cwd_len = sizeof(buf);
  int err = uv_cwd(buf, &cwd_len);
  if (err) {
    std::string err_msg =
        std::string("process.cwd failed with error ") + uv_strerror(err);
    if (err == UV_ENOENT) {
      // If err == UV_ENOENT it is necessary to notice the user
      // that the current working dir was likely removed.
      err_msg =
          err_msg +
          std::string(", the current working directory was likely removed ") +
          std::string("without changing the working directory");
    }
    return env->ThrowUVException(err, "uv_cwd", err_msg.c_str());
  }
  Local<String> cwd;
  if (String::NewFromUtf8(env->isolate(), buf, NewStringType::kNormal, cwd_len)
          .ToLocal(&cwd)) {
    args.GetReturnValue().Set(cwd);
  }
}

static void Kill(const FunctionCallbackInfo<Value>& args) {
  Environment* env = Environment::GetCurrent(args);
  Local<Context> context = env->context();

  if (args.Length() < 2) {
    THROW_ERR_MISSING_ARGS(env, "Bad argument.");
  }

  int pid;
  if (!args[0]->Int32Value(context).To(&pid)) return;
  int sig;
  if (!args[1]->Int32Value(context).To(&sig)) return;

  uv_pid_t own_pid = uv_os_getpid();
  if (sig > 0 &&

Review comment (suggestion):
Completely optional, but this could be simplified a bit:

```suggestion
          ", the current working directory was likely removed "
          "without changing the working directory";
```

Code after:

  // Get the double array pointer from the Float64Array argument.
  Local<ArrayBuffer> ab = get_fields_array_buffer(args, 0, 2);
  double* fields = static_cast<double*>(ab->Data());

  // Set the Float64Array elements to be user / system values in microseconds.
  fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec;
  fields[1] = MICROS_PER_SEC * rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec;
}

static void Cwd(const FunctionCallbackInfo<Value>& args) {
  Environment* env = Environment::GetCurrent(args);
  CHECK(env->has_run_bootstrapping_code());
  char buf[PATH_MAX_BYTES];
  size_t cwd_len = sizeof(buf);
  int err = uv_cwd(buf, &cwd_len);
  if (err) {
    std::string err_msg =
        std::string("process.cwd failed with error ") + uv_strerror(err);
    if (err == UV_ENOENT) {
      // If err == UV_ENOENT it is necessary to notice the user
      // that the current working dir was likely removed.
      err_msg = err_msg +
                ", the current working directory was likely removed " +
                "without changing the working directory";
    }
    return env->ThrowUVException(err, "uv_cwd", err_msg.c_str());
  }
  Local<String> cwd;
  if (String::NewFromUtf8(env->isolate(), buf, NewStringType::kNormal, cwd_len)
          .ToLocal(&cwd)) {
    args.GetReturnValue().Set(cwd);
  }
}

static void Kill(const FunctionCallbackInfo<Value>& args) {
  Environment* env = Environment::GetCurrent(args);
  Local<Context> context = env->context();

  if (args.Length() < 2) {
    THROW_ERR_MISSING_ARGS(env, "Bad argument.");
  }

  int pid;
  if (!args[0]->Int32Value(context).To(&pid)) return;
  int sig;
  if (!args[1]->Int32Value(context).To(&sig)) return;

  uv_pid_t own_pid = uv_os_getpid();
  if (sig > 0 &&
      (pid == 0 || pid == -1 || pid == own_pid || pid == -own_pid) &&