Skip to content

Commit 0540308

Browse files
theanarkhaduh95
authored andcommitted
lib: add toJSON to PerformanceMeasure
PR-URL: #53603 Refs: #53570 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 3cc01aa commit 0540308

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/internal/perf/usertiming.js

+10
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ class PerformanceMeasure extends PerformanceEntry {
136136
validateInternalField(this, kDetail, 'PerformanceMeasure');
137137
return this[kDetail];
138138
}
139+
140+
toJSON() {
141+
return {
142+
name: this.name,
143+
entryType: this.entryType,
144+
startTime: this.startTime,
145+
duration: this.duration,
146+
detail: this[kDetail],
147+
};
148+
}
139149
}
140150
ObjectDefineProperties(PerformanceMeasure.prototype, {
141151
detail: kEnumerableProperty,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const util = require('util');
6+
const { performance, PerformanceObserver } = require('perf_hooks');
7+
8+
const perfObserver = new PerformanceObserver(common.mustCall((items) => {
9+
const entries = items.getEntries();
10+
assert.ok(entries.length === 1);
11+
for (const entry of entries) {
12+
assert.ok(util.inspect(entry).includes('this is detail'));
13+
}
14+
}));
15+
16+
perfObserver.observe({ entryTypes: ['measure'] });
17+
18+
performance.measure('sample', {
19+
detail: 'this is detail',
20+
});

0 commit comments

Comments
 (0)