diff --git a/lib/internal/histogram.js b/lib/internal/histogram.js index fe0fab0ea5d2f7..f2cf3835b9a62a 100644 --- a/lib/internal/histogram.js +++ b/lib/internal/histogram.js @@ -1,12 +1,13 @@ 'use strict'; const { + Map, + MapPrototypeClear, MapPrototypeEntries, NumberIsNaN, NumberMAX_SAFE_INTEGER, ObjectFromEntries, ReflectConstruct, - SafeMap, Symbol, } = primordials; @@ -216,7 +217,7 @@ class Histogram { get percentiles() { if (!isHistogram(this)) throw new ERR_INVALID_THIS('Histogram'); - this[kMap].clear(); + MapPrototypeClear(this[kMap]); this[kHandle]?.percentiles(this[kMap]); return this[kMap]; } @@ -228,7 +229,7 @@ class Histogram { get percentilesBigInt() { if (!isHistogram(this)) throw new ERR_INVALID_THIS('Histogram'); - this[kMap].clear(); + MapPrototypeClear(this[kMap]); this[kHandle]?.percentilesBigInt(this[kMap]); return this[kMap]; } @@ -331,7 +332,7 @@ function ClonedHistogram(handle) { function() { markTransferMode(this, true, false); this[kHandle] = handle; - this[kMap] = new SafeMap(); + this[kMap] = new Map(); }, [], Histogram); } @@ -342,7 +343,7 @@ function ClonedRecordableHistogram(handle) { markTransferMode(histogram, true, false); histogram[kRecordable] = true; - histogram[kMap] = new SafeMap(); + histogram[kMap] = new Map(); histogram[kHandle] = handle; histogram.constructor = RecordableHistogram; diff --git a/test/parallel/test-perf-hooks-histogram.js b/test/parallel/test-perf-hooks-histogram.js index 9e76cca2f4f479..a93ae17e9f23d8 100644 --- a/test/parallel/test-perf-hooks-histogram.js +++ b/test/parallel/test-perf-hooks-histogram.js @@ -3,6 +3,7 @@ const common = require('../common'); const { + deepStrictEqual, ok, strictEqual, throws, @@ -58,6 +59,10 @@ const { inspect } = require('util'); strictEqual(h.percentileBigInt(1), 1n); strictEqual(h.percentileBigInt(100), 1n); + deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]])); + + deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]])); + const mc = new MessageChannel(); mc.port1.onmessage = common.mustCall(({ data }) => { strictEqual(h.min, 1);