perf_hooks: do not expose SafeMap via Histogram wrapper

PR-URL: https://github.com/nodejs/node/pull/59094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
René 2025-07-22 17:28:02 +01:00 committed by GitHub
parent 97dbb79c8b
commit fb6d6aa3bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -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;

View File

@ -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);