@@ -37,10 +37,56 @@ function assert(x, msg) {
37
37
if ( ! x ) throw new ERR_ASSERTION ( msg || 'assertion error' ) ;
38
38
}
39
39
40
+ function getFastAPIs ( binding ) {
41
+ const {
42
+ hrtime : _hrtime
43
+ } = binding . getFastAPIs ( ) ;
44
+
45
+ // The 3 entries filled in by the original process.hrtime contains
46
+ // the upper/lower 32 bits of the second part of the value,
47
+ // and the remaining nanoseconds of the value.
48
+ const hrValues = new Uint32Array ( _hrtime . buffer ) ;
49
+
50
+ function hrtime ( time ) {
51
+ _hrtime . hrtime ( ) ;
52
+
53
+ if ( time !== undefined ) {
54
+ if ( ! ArrayIsArray ( time ) ) {
55
+ throw new ERR_INVALID_ARG_TYPE ( 'time' , 'Array' , time ) ;
56
+ }
57
+ if ( time . length !== 2 ) {
58
+ throw new ERR_OUT_OF_RANGE ( 'time' , 2 , time . length ) ;
59
+ }
60
+
61
+ const sec = ( hrValues [ 0 ] * 0x100000000 + hrValues [ 1 ] ) - time [ 0 ] ;
62
+ const nsec = hrValues [ 2 ] - time [ 1 ] ;
63
+ const needsBorrow = nsec < 0 ;
64
+ return [ needsBorrow ? sec - 1 : sec , needsBorrow ? nsec + 1e9 : nsec ] ;
65
+ }
66
+
67
+ return [
68
+ hrValues [ 0 ] * 0x100000000 + hrValues [ 1 ] ,
69
+ hrValues [ 2 ]
70
+ ] ;
71
+ }
72
+
73
+ // Use a BigUint64Array in the closure because this is actually a bit
74
+ // faster than simply returning a BigInt from C++ in V8 7.1.
75
+ const hrBigintValues = new BigUint64Array ( _hrtime . buffer , 0 , 1 ) ;
76
+ function hrtimeBigInt ( ) {
77
+ _hrtime . hrtimeBigInt ( ) ;
78
+ return hrBigintValues [ 0 ] ;
79
+ }
80
+
81
+ return {
82
+ hrtime,
83
+ hrtimeBigInt,
84
+ } ;
85
+ }
86
+
40
87
// The execution of this function itself should not cause any side effects.
41
88
function wrapProcessMethods ( binding ) {
42
89
const {
43
- hrtime : _hrtime ,
44
90
cpuUsage : _cpuUsage ,
45
91
memoryUsage : _memoryUsage ,
46
92
resourceUsage : _resourceUsage
@@ -109,42 +155,6 @@ function wrapProcessMethods(binding) {
109
155
num >= 0 ;
110
156
}
111
157
112
- // The 3 entries filled in by the original process.hrtime contains
113
- // the upper/lower 32 bits of the second part of the value,
114
- // and the remaining nanoseconds of the value.
115
- const hrValues = new Uint32Array ( _hrtime . buffer ) ;
116
-
117
- function hrtime ( time ) {
118
- _hrtime . hrtime ( ) ;
119
-
120
- if ( time !== undefined ) {
121
- if ( ! ArrayIsArray ( time ) ) {
122
- throw new ERR_INVALID_ARG_TYPE ( 'time' , 'Array' , time ) ;
123
- }
124
- if ( time . length !== 2 ) {
125
- throw new ERR_OUT_OF_RANGE ( 'time' , 2 , time . length ) ;
126
- }
127
-
128
- const sec = ( hrValues [ 0 ] * 0x100000000 + hrValues [ 1 ] ) - time [ 0 ] ;
129
- const nsec = hrValues [ 2 ] - time [ 1 ] ;
130
- const needsBorrow = nsec < 0 ;
131
- return [ needsBorrow ? sec - 1 : sec , needsBorrow ? nsec + 1e9 : nsec ] ;
132
- }
133
-
134
- return [
135
- hrValues [ 0 ] * 0x100000000 + hrValues [ 1 ] ,
136
- hrValues [ 2 ]
137
- ] ;
138
- }
139
-
140
- // Use a BigUint64Array in the closure because this is actually a bit
141
- // faster than simply returning a BigInt from C++ in V8 7.1.
142
- const hrBigintValues = new BigUint64Array ( _hrtime . buffer , 0 , 1 ) ;
143
- function hrtimeBigInt ( ) {
144
- _hrtime . hrtimeBigInt ( ) ;
145
- return hrBigintValues [ 0 ] ;
146
- }
147
-
148
158
const memValues = new Float64Array ( 5 ) ;
149
159
function memoryUsage ( ) {
150
160
_memoryUsage ( memValues ) ;
@@ -225,8 +235,6 @@ function wrapProcessMethods(binding) {
225
235
226
236
return {
227
237
_rawDebug,
228
- hrtime,
229
- hrtimeBigInt,
230
238
cpuUsage,
231
239
resourceUsage,
232
240
memoryUsage,
@@ -356,6 +364,7 @@ function toggleTraceCategoryState(asyncHooksEnabled) {
356
364
357
365
module . exports = {
358
366
toggleTraceCategoryState,
367
+ getFastAPIs,
359
368
assert,
360
369
buildAllowedFlags,
361
370
wrapProcessMethods
0 commit comments