@@ -52,9 +52,13 @@ function isHistogram(object) {
5252 return object ?. [ kHandle ] !== undefined ;
5353}
5454
55+ const kSkipThrow = Symbol ( 'kSkipThrow' ) ;
56+
5557class Histogram {
56- constructor ( ) {
57- throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
58+ constructor ( skipThrowSymbol = undefined ) {
59+ if ( skipThrowSymbol !== kSkipThrow ) {
60+ throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
61+ }
5862 }
5963
6064 [ kInspect ] ( depth , options ) {
@@ -242,7 +246,7 @@ class Histogram {
242246 const handle = this [ kHandle ] ;
243247 return {
244248 data : { handle } ,
245- deserializeInfo : 'internal/histogram:internalHistogram ' ,
249+ deserializeInfo : 'internal/histogram:ClonedHistogram ' ,
246250 } ;
247251 }
248252
@@ -264,8 +268,12 @@ class Histogram {
264268}
265269
266270class RecordableHistogram extends Histogram {
267- constructor ( ) {
268- throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
271+ constructor ( skipThrowSymbol = undefined ) {
272+ if ( skipThrowSymbol !== kSkipThrow ) {
273+ throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
274+ }
275+
276+ super ( skipThrowSymbol ) ;
269277 }
270278
271279 /**
@@ -309,7 +317,7 @@ class RecordableHistogram extends Histogram {
309317 const handle = this [ kHandle ] ;
310318 return {
311319 data : { handle } ,
312- deserializeInfo : 'internal/histogram:internalRecordableHistogram ' ,
320+ deserializeInfo : 'internal/histogram:ClonedRecordableHistogram ' ,
313321 } ;
314322 }
315323
@@ -318,26 +326,34 @@ class RecordableHistogram extends Histogram {
318326 }
319327}
320328
321- function internalHistogram ( handle ) {
329+ function ClonedHistogram ( handle ) {
322330 return ReflectConstruct (
323331 function ( ) {
324332 markTransferMode ( this , true , false ) ;
325333 this [ kHandle ] = handle ;
326334 this [ kMap ] = new SafeMap ( ) ;
327335 } , [ ] , Histogram ) ;
328336}
329- internalHistogram . prototype [ kDeserialize ] = ( ) => { } ;
330337
331- function internalRecordableHistogram ( handle ) {
332- return ReflectConstruct (
333- function ( ) {
334- markTransferMode ( this , true , false ) ;
335- this [ kHandle ] = handle ;
336- this [ kMap ] = new SafeMap ( ) ;
337- this [ kRecordable ] = true ;
338- } , [ ] , RecordableHistogram ) ;
338+ ClonedHistogram . prototype [ kDeserialize ] = ( ) => { } ;
339+
340+ function ClonedRecordableHistogram ( handle ) {
341+ const histogram = new RecordableHistogram ( kSkipThrow ) ;
342+
343+ markTransferMode ( histogram , true , false ) ;
344+ histogram [ kRecordable ] = true ;
345+ histogram [ kMap ] = new SafeMap ( ) ;
346+ histogram [ kHandle ] = handle ;
347+ histogram . constructor = RecordableHistogram ;
348+
349+ return histogram ;
350+ }
351+
352+ ClonedRecordableHistogram . prototype [ kDeserialize ] = ( ) => { } ;
353+
354+ function createRecordableHistogram ( handle ) {
355+ return new ClonedRecordableHistogram ( handle ) ;
339356}
340- internalRecordableHistogram . prototype [ kDeserialize ] = ( ) => { } ;
341357
342358/**
343359 * @param {{
@@ -363,14 +379,14 @@ function createHistogram(options = kEmptyObject) {
363379 throw new ERR_INVALID_ARG_VALUE . RangeError ( 'options.highest' , highest ) ;
364380 }
365381 validateInteger ( figures , 'options.figures' , 1 , 5 ) ;
366- return internalRecordableHistogram ( new _Histogram ( lowest , highest , figures ) ) ;
382+ return createRecordableHistogram ( new _Histogram ( lowest , highest , figures ) ) ;
367383}
368384
369385module . exports = {
370386 Histogram,
371387 RecordableHistogram,
372- internalHistogram ,
373- internalRecordableHistogram ,
388+ ClonedHistogram ,
389+ ClonedRecordableHistogram ,
374390 isHistogram,
375391 kDestroy,
376392 kHandle,
0 commit comments