@@ -87,6 +87,16 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
87
87
}
88
88
}
89
89
90
+ inline Local<ArrayBuffer> get_fields_array_buffer (
91
+ const FunctionCallbackInfo<Value>& args,
92
+ size_t index,
93
+ size_t array_length) {
94
+ CHECK (args[index ]->IsFloat64Array ());
95
+ Local<Float64Array> arr = args[index ].As <Float64Array>();
96
+ CHECK_EQ (arr->Length (), array_length);
97
+ return arr->Buffer ();
98
+ }
99
+
90
100
// CPUUsage use libuv's uv_getrusage() this-process resource usage accessor,
91
101
// to access ru_utime (user CPU time used) and ru_stime (system CPU time used),
92
102
// which are uv_timeval_t structs (long tv_sec, long tv_usec).
@@ -104,10 +114,7 @@ static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
104
114
}
105
115
106
116
// Get the double array pointer from the Float64Array argument.
107
- CHECK (args[0 ]->IsFloat64Array ());
108
- Local<Float64Array> array = args[0 ].As <Float64Array>();
109
- CHECK_EQ (array->Length (), 2 );
110
- Local<ArrayBuffer> ab = array->Buffer ();
117
+ Local<ArrayBuffer> ab = get_fields_array_buffer (args, 0 , 2 );
111
118
double * fields = static_cast <double *>(ab->GetBackingStore ()->Data ());
112
119
113
120
// Set the Float64Array elements to be user / system values in microseconds.
@@ -203,10 +210,7 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
203
210
env->isolate_data ()->node_allocator ();
204
211
205
212
// Get the double array pointer from the Float64Array argument.
206
- CHECK (args[0 ]->IsFloat64Array ());
207
- Local<Float64Array> array = args[0 ].As <Float64Array>();
208
- CHECK_EQ (array->Length (), 5 );
209
- Local<ArrayBuffer> ab = array->Buffer ();
213
+ Local<ArrayBuffer> ab = get_fields_array_buffer (args, 0 , 5 );
210
214
double * fields = static_cast <double *>(ab->GetBackingStore ()->Data ());
211
215
212
216
fields[0 ] = rss;
@@ -292,10 +296,7 @@ static void ResourceUsage(const FunctionCallbackInfo<Value>& args) {
292
296
if (err)
293
297
return env->ThrowUVException (err, " uv_getrusage" );
294
298
295
- CHECK (args[0 ]->IsFloat64Array ());
296
- Local<Float64Array> array = args[0 ].As <Float64Array>();
297
- CHECK_EQ (array->Length (), 16 );
298
- Local<ArrayBuffer> ab = array->Buffer ();
299
+ Local<ArrayBuffer> ab = get_fields_array_buffer (args, 0 , 16 );
299
300
double * fields = static_cast <double *>(ab->GetBackingStore ()->Data ());
300
301
301
302
fields[0 ] = MICROS_PER_SEC * rusage .ru_utime .tv_sec + rusage .ru_utime .tv_usec ;
0 commit comments