@@ -52,9 +52,13 @@ function isHistogram(object) {
52
52
return object ?. [ kHandle ] !== undefined ;
53
53
}
54
54
55
+ const kSkipThrow = Symbol ( 'kSkipThrow' ) ;
56
+
55
57
class Histogram {
56
- constructor ( ) {
57
- throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
58
+ constructor ( skipThrowSymbol = undefined ) {
59
+ if ( skipThrowSymbol !== kSkipThrow ) {
60
+ throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
61
+ }
58
62
}
59
63
60
64
[ kInspect ] ( depth , options ) {
@@ -242,7 +246,7 @@ class Histogram {
242
246
const handle = this [ kHandle ] ;
243
247
return {
244
248
data : { handle } ,
245
- deserializeInfo : 'internal/histogram:internalHistogram ' ,
249
+ deserializeInfo : 'internal/histogram:ClonedHistogram ' ,
246
250
} ;
247
251
}
248
252
@@ -264,8 +268,12 @@ class Histogram {
264
268
}
265
269
266
270
class 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 ) ;
269
277
}
270
278
271
279
/**
@@ -309,7 +317,7 @@ class RecordableHistogram extends Histogram {
309
317
const handle = this [ kHandle ] ;
310
318
return {
311
319
data : { handle } ,
312
- deserializeInfo : 'internal/histogram:internalRecordableHistogram ' ,
320
+ deserializeInfo : 'internal/histogram:ClonedRecordableHistogram ' ,
313
321
} ;
314
322
}
315
323
@@ -318,24 +326,32 @@ class RecordableHistogram extends Histogram {
318
326
}
319
327
}
320
328
321
- function internalHistogram ( handle ) {
329
+ function ClonedHistogram ( handle ) {
322
330
return makeTransferable ( ReflectConstruct (
323
331
function ( ) {
324
332
this [ kHandle ] = handle ;
325
333
this [ kMap ] = new SafeMap ( ) ;
326
334
} , [ ] , Histogram ) ) ;
327
335
}
328
- internalHistogram . prototype [ kDeserialize ] = ( ) => { } ;
329
336
330
- function internalRecordableHistogram ( handle ) {
331
- return makeTransferable ( ReflectConstruct (
332
- function ( ) {
333
- this [ kHandle ] = handle ;
334
- this [ kMap ] = new SafeMap ( ) ;
335
- this [ kRecordable ] = true ;
336
- } , [ ] , RecordableHistogram ) ) ;
337
+ ClonedHistogram . prototype [ kDeserialize ] = ( ) => { } ;
338
+
339
+ function ClonedRecordableHistogram ( handle ) {
340
+ const histogram = new RecordableHistogram ( kSkipThrow ) ;
341
+
342
+ histogram [ kRecordable ] = true ;
343
+ histogram [ kMap ] = new SafeMap ( ) ;
344
+ histogram [ kHandle ] = handle ;
345
+ histogram . constructor = RecordableHistogram ;
346
+
347
+ return makeTransferable ( histogram ) ;
348
+ }
349
+
350
+ ClonedRecordableHistogram . prototype [ kDeserialize ] = ( ) => { } ;
351
+
352
+ function createRecordableHistogram ( handle ) {
353
+ return new ClonedRecordableHistogram ( handle ) ;
337
354
}
338
- internalRecordableHistogram . prototype [ kDeserialize ] = ( ) => { } ;
339
355
340
356
/**
341
357
* @param {{
@@ -361,14 +377,14 @@ function createHistogram(options = kEmptyObject) {
361
377
throw new ERR_INVALID_ARG_VALUE . RangeError ( 'options.highest' , highest ) ;
362
378
}
363
379
validateInteger ( figures , 'options.figures' , 1 , 5 ) ;
364
- return internalRecordableHistogram ( new _Histogram ( lowest , highest , figures ) ) ;
380
+ return createRecordableHistogram ( new _Histogram ( lowest , highest , figures ) ) ;
365
381
}
366
382
367
383
module . exports = {
368
384
Histogram,
369
385
RecordableHistogram,
370
- internalHistogram ,
371
- internalRecordableHistogram ,
386
+ ClonedHistogram ,
387
+ ClonedRecordableHistogram ,
372
388
isHistogram,
373
389
kDestroy,
374
390
kHandle,
0 commit comments