Skip to content

Commit

Permalink
lib: add toJSON to PerformanceMeasure
Browse files Browse the repository at this point in the history
  • Loading branch information
theanarkh committed Jun 27, 2024
1 parent ce531af commit 7bd3cae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/internal/perf/usertiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ class PerformanceMeasure extends PerformanceEntry {
validateInternalField(this, kDetail, 'PerformanceMeasure');
return this[kDetail];
}

toJSON() {
return {
name: this.name,
entryType: this.entryType,
startTime: this.startTime,
duration: this.duration,
detail: this[kDetail],
};
}
}
ObjectDefineProperties(PerformanceMeasure.prototype, {
detail: kEnumerableProperty,
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-performance-measure-detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

require('../common');
const assert = require('assert');
const util = require('util');
const { performance, PerformanceObserver } = require('perf_hooks');

const perfObserver = new PerformanceObserver((items) => {
items.getEntries().forEach((entry) => {
assert.ok(util.inspect(entry).includes('this is detail'));
});
});

perfObserver.observe({ entryTypes: ['measure'] });

performance.measure('sample', {
detail: 'this is detail',
});

0 comments on commit 7bd3cae

Please sign in to comment.