5
5
} = require ( 'internal/util' ) ;
6
6
7
7
const { format } = require ( 'util' ) ;
8
- const { Map , Symbol } = primordials ;
8
+ const { SafeMap , Symbol } = primordials ;
9
9
10
10
const {
11
11
ERR_INVALID_ARG_TYPE ,
@@ -19,11 +19,10 @@ const kHandle = Symbol('kHandle');
19
19
// record various metrics. This Histogram class provides a
20
20
// generally read-only view of the internal histogram.
21
21
class Histogram {
22
- #handle = undefined ;
23
- #map = new Map ( ) ;
22
+ #map = new SafeMap ( ) ;
24
23
25
24
constructor ( internal ) {
26
- this . #handle = internal ;
25
+ this [ kHandle ] = internal ;
27
26
}
28
27
29
28
[ kInspect ] ( ) {
@@ -39,23 +38,23 @@ class Histogram {
39
38
}
40
39
41
40
get min ( ) {
42
- return this . #handle ? this . #handle . min ( ) : undefined ;
41
+ return this [ kHandle ] ?. min ( ) ;
43
42
}
44
43
45
44
get max ( ) {
46
- return this . #handle ? this . #handle . max ( ) : undefined ;
45
+ return this [ kHandle ] ?. max ( ) ;
47
46
}
48
47
49
48
get mean ( ) {
50
- return this . #handle ? this . #handle . mean ( ) : undefined ;
49
+ return this [ kHandle ] ?. mean ( ) ;
51
50
}
52
51
53
52
get exceeds ( ) {
54
- return this . #handle ? this . #handle . exceeds ( ) : undefined ;
53
+ return this [ kHandle ] ?. exceeds ( ) ;
55
54
}
56
55
57
56
get stddev ( ) {
58
- return this . #handle ? this . #handle . stddev ( ) : undefined ;
57
+ return this [ kHandle ] ?. stddev ( ) ;
59
58
}
60
59
61
60
percentile ( percentile ) {
@@ -65,26 +64,22 @@ class Histogram {
65
64
if ( percentile <= 0 || percentile > 100 )
66
65
throw new ERR_INVALID_ARG_VALUE . RangeError ( 'percentile' , percentile ) ;
67
66
68
- return this . #handle ? this . #handle . percentile ( percentile ) : undefined ;
67
+ return this [ kHandle ] ?. percentile ( percentile ) ;
69
68
}
70
69
71
70
get percentiles ( ) {
72
71
this . #map. clear ( ) ;
73
- if ( this . #handle)
74
- this . #handle. percentiles ( this . #map) ;
72
+ this [ kHandle ] ?. percentiles ( this . #map) ;
75
73
return this . #map;
76
74
}
77
75
78
76
reset ( ) {
79
- if ( this . #handle)
80
- this . #handle. reset ( ) ;
77
+ this [ kHandle ] ?. reset ( ) ;
81
78
}
82
79
83
80
[ kDestroy ] ( ) {
84
- this . #handle = undefined ;
81
+ this [ kHandle ] = undefined ;
85
82
}
86
-
87
- get [ kHandle ] ( ) { return this . #handle; }
88
83
}
89
84
90
85
module . exports = {
0 commit comments