◐ Shell
clean mode source ↗

perf_hooks: do not expose SafeMap via Histogram wrapper · nodejs/node@f67b686

Original file line numberDiff line numberDiff line change

@@ -1,12 +1,13 @@

11

'use strict';

22
33

const {

4+

Map,

5+

MapPrototypeClear,

46

MapPrototypeEntries,

57

NumberIsNaN,

68

NumberMAX_SAFE_INTEGER,

79

ObjectFromEntries,

810

ReflectConstruct,

9-

SafeMap,

1011

Symbol,

1112

} = primordials;

1213

@@ -216,7 +217,7 @@ class Histogram {

216217

get percentiles() {

217218

if (!isHistogram(this))

218219

throw new ERR_INVALID_THIS('Histogram');

219-

this[kMap].clear();

220+

MapPrototypeClear(this[kMap]);

220221

this[kHandle]?.percentiles(this[kMap]);

221222

return this[kMap];

222223

}

@@ -228,7 +229,7 @@ class Histogram {

228229

get percentilesBigInt() {

229230

if (!isHistogram(this))

230231

throw new ERR_INVALID_THIS('Histogram');

231-

this[kMap].clear();

232+

MapPrototypeClear(this[kMap]);

232233

this[kHandle]?.percentilesBigInt(this[kMap]);

233234

return this[kMap];

234235

}

@@ -331,7 +332,7 @@ function ClonedHistogram(handle) {

331332

function() {

332333

markTransferMode(this, true, false);

333334

this[kHandle] = handle;

334-

this[kMap] = new SafeMap();

335+

this[kMap] = new Map();

335336

}, [], Histogram);

336337

}

337338

@@ -342,7 +343,7 @@ function ClonedRecordableHistogram(handle) {

342343
343344

markTransferMode(histogram, true, false);

344345

histogram[kRecordable] = true;

345-

histogram[kMap] = new SafeMap();

346+

histogram[kMap] = new Map();

346347

histogram[kHandle] = handle;

347348

histogram.constructor = RecordableHistogram;

348349
Original file line numberDiff line numberDiff line change

@@ -3,6 +3,7 @@

33

const common = require('../common');

44
55

const {

6+

deepStrictEqual,

67

ok,

78

strictEqual,

89

throws,

@@ -58,6 +59,10 @@ const { inspect } = require('util');

5859

strictEqual(h.percentileBigInt(1), 1n);

5960

strictEqual(h.percentileBigInt(100), 1n);

6061
62+

deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]]));

63+
64+

deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]]));

65+
6166

const mc = new MessageChannel();

6267

mc.port1.onmessage = common.mustCall(({ data }) => {

6368

strictEqual(h.min, 1);