@@ -89,6 +89,16 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
89
89
}
90
90
}
91
91
92
+ inline Local<ArrayBuffer> get_fields_array_buffer (
93
+ const FunctionCallbackInfo<Value>& args,
94
+ size_t index,
95
+ size_t array_length) {
96
+ CHECK (args[index ]->IsFloat64Array ());
97
+ Local<Float64Array> arr = args[index ].As <Float64Array>();
98
+ CHECK_EQ (arr->Length (), array_length);
99
+ return arr->Buffer ();
100
+ }
101
+
92
102
// CPUUsage use libuv's uv_getrusage() this-process resource usage accessor,
93
103
// to access ru_utime (user CPU time used) and ru_stime (system CPU time used),
94
104
// which are uv_timeval_t structs (long tv_sec, long tv_usec).
@@ -106,10 +116,7 @@ static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
106
116
}
107
117
108
118
// Get the double array pointer from the Float64Array argument.
109
- CHECK (args[0 ]->IsFloat64Array ());
110
- Local<Float64Array> array = args[0 ].As <Float64Array>();
111
- CHECK_EQ (array->Length (), 2 );
112
- Local<ArrayBuffer> ab = array->Buffer ();
119
+ Local<ArrayBuffer> ab = get_fields_array_buffer (args, 0 , 2 );
113
120
double * fields = static_cast <double *>(ab->GetBackingStore ()->Data ());
114
121
115
122
// Set the Float64Array elements to be user / system values in microseconds.
@@ -175,10 +182,7 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
175
182
env->isolate_data ()->node_allocator ();
176
183
177
184
// Get the double array pointer from the Float64Array argument.
178
- CHECK (args[0 ]->IsFloat64Array ());
179
- Local<Float64Array> array = args[0 ].As <Float64Array>();
180
- CHECK_EQ (array->Length (), 5 );
181
- Local<ArrayBuffer> ab = array->Buffer ();
185
+ Local<ArrayBuffer> ab = get_fields_array_buffer (args, 0 , 5 );
182
186
double * fields = static_cast <double *>(ab->GetBackingStore ()->Data ());
183
187
184
188
fields[0 ] = rss;
@@ -275,10 +279,7 @@ static void ResourceUsage(const FunctionCallbackInfo<Value>& args) {
275
279
if (err)
276
280
return env->ThrowUVException (err, " uv_getrusage" );
277
281
278
- CHECK (args[0 ]->IsFloat64Array ());
279
- Local<Float64Array> array = args[0 ].As <Float64Array>();
280
- CHECK_EQ (array->Length (), 16 );
281
- Local<ArrayBuffer> ab = array->Buffer ();
282
+ Local<ArrayBuffer> ab = get_fields_array_buffer (args, 0 , 16 );
282
283
double * fields = static_cast <double *>(ab->GetBackingStore ()->Data ());
283
284
284
285
fields[0 ] = MICROS_PER_SEC * rusage .ru_utime .tv_sec + rusage .ru_utime .tv_usec ;
0 commit comments