Skip to content

Commit 7bd3cae

Browse files
committed
lib: add toJSON to PerformanceMeasure
1 parent ce531af commit 7bd3cae

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/internal/perf/usertiming.js

Lines changed: 10 additions & 0 deletions
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,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
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((items) => {
9+
items.getEntries().forEach((entry) => {
10+
assert.ok(util.inspect(entry).includes('this is detail'));
11+
});
12+
});
13+
14+
perfObserver.observe({ entryTypes: ['measure'] });
15+
16+
performance.measure('sample', {
17+
detail: 'this is detail',
18+
});

0 commit comments

Comments
 (0)