55} = require ( 'internal/util' ) ;
66
77const { format } = require ( 'util' ) ;
8- const { Map , Symbol } = primordials ;
8+ const { SafeMap , Symbol } = primordials ;
99
1010const {
1111 ERR_INVALID_ARG_TYPE ,
@@ -19,11 +19,10 @@ const kHandle = Symbol('kHandle');
1919// record various metrics. This Histogram class provides a
2020// generally read-only view of the internal histogram.
2121class Histogram {
22- #handle = undefined ;
23- #map = new Map ( ) ;
22+ #map = new SafeMap ( ) ;
2423
2524 constructor ( internal ) {
26- this . #handle = internal ;
25+ this [ kHandle ] = internal ;
2726 }
2827
2928 [ kInspect ] ( ) {
@@ -39,23 +38,23 @@ class Histogram {
3938 }
4039
4140 get min ( ) {
42- return this . #handle ? this . #handle . min ( ) : undefined ;
41+ return this [ kHandle ] ?. min ( ) ;
4342 }
4443
4544 get max ( ) {
46- return this . #handle ? this . #handle . max ( ) : undefined ;
45+ return this [ kHandle ] ?. max ( ) ;
4746 }
4847
4948 get mean ( ) {
50- return this . #handle ? this . #handle . mean ( ) : undefined ;
49+ return this [ kHandle ] ?. mean ( ) ;
5150 }
5251
5352 get exceeds ( ) {
54- return this . #handle ? this . #handle . exceeds ( ) : undefined ;
53+ return this [ kHandle ] ?. exceeds ( ) ;
5554 }
5655
5756 get stddev ( ) {
58- return this . #handle ? this . #handle . stddev ( ) : undefined ;
57+ return this [ kHandle ] ?. stddev ( ) ;
5958 }
6059
6160 percentile ( percentile ) {
@@ -65,26 +64,22 @@ class Histogram {
6564 if ( percentile <= 0 || percentile > 100 )
6665 throw new ERR_INVALID_ARG_VALUE . RangeError ( 'percentile' , percentile ) ;
6766
68- return this . #handle ? this . #handle . percentile ( percentile ) : undefined ;
67+ return this [ kHandle ] ?. percentile ( percentile ) ;
6968 }
7069
7170 get percentiles ( ) {
7271 this . #map. clear ( ) ;
73- if ( this . #handle)
74- this . #handle. percentiles ( this . #map) ;
72+ this [ kHandle ] ?. percentiles ( this . #map) ;
7573 return this . #map;
7674 }
7775
7876 reset ( ) {
79- if ( this . #handle)
80- this . #handle. reset ( ) ;
77+ this [ kHandle ] ?. reset ( ) ;
8178 }
8279
8380 [ kDestroy ] ( ) {
84- this . #handle = undefined ;
81+ this [ kHandle ] = undefined ;
8582 }
86-
87- get [ kHandle ] ( ) { return this . #handle; }
8883}
8984
9085module . exports = {
0 commit comments