diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 105cbff151b151..ec6e25b49557a7 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -89,6 +89,16 @@ static void Chdir(const FunctionCallbackInfo& args) { } } +inline Local get_fields_array_buffer( + const FunctionCallbackInfo& args, + size_t index, + size_t array_length) { + CHECK(args[index]->IsFloat64Array()); + Local arr = args[index].As(); + CHECK_EQ(arr->Length(), array_length); + return arr->Buffer(); +} + // CPUUsage use libuv's uv_getrusage() this-process resource usage accessor, // to access ru_utime (user CPU time used) and ru_stime (system CPU time used), // which are uv_timeval_t structs (long tv_sec, long tv_usec). @@ -106,10 +116,7 @@ static void CPUUsage(const FunctionCallbackInfo& args) { } // Get the double array pointer from the Float64Array argument. - CHECK(args[0]->IsFloat64Array()); - Local array = args[0].As(); - CHECK_EQ(array->Length(), 2); - Local ab = array->Buffer(); + Local ab = get_fields_array_buffer(args, 0, 2); double* fields = static_cast(ab->GetBackingStore()->Data()); // Set the Float64Array elements to be user / system values in microseconds. @@ -175,10 +182,7 @@ static void MemoryUsage(const FunctionCallbackInfo& args) { env->isolate_data()->node_allocator(); // Get the double array pointer from the Float64Array argument. - CHECK(args[0]->IsFloat64Array()); - Local array = args[0].As(); - CHECK_EQ(array->Length(), 5); - Local ab = array->Buffer(); + Local ab = get_fields_array_buffer(args, 0, 5); double* fields = static_cast(ab->GetBackingStore()->Data()); fields[0] = rss; @@ -275,10 +279,7 @@ static void ResourceUsage(const FunctionCallbackInfo& args) { if (err) return env->ThrowUVException(err, "uv_getrusage"); - CHECK(args[0]->IsFloat64Array()); - Local array = args[0].As(); - CHECK_EQ(array->Length(), 16); - Local ab = array->Buffer(); + Local ab = get_fields_array_buffer(args, 0, 16); double* fields = static_cast(ab->GetBackingStore()->Data()); fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec;