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

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎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
returnthis[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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
constutil=require('util');
6+
const{ performance, PerformanceObserver }=require('perf_hooks');
7+
8+
constperfObserver=newPerformanceObserver(common.mustCall((items)=>{
9+
constentries=items.getEntries();
10+
assert.ok(entries.length===1);
11+
for(constentryofentries){
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)