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 8381fba
Show file tree
Hide file tree
Showing 2 changed files with 30 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
20 changes: 20 additions & 0 deletions test/parallel/test-performance-measure-detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

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

const perfObserver = new PerformanceObserver(common.mustCall((items) => {
const entries = items.getEntries();
assert.ok(entries.length === 1);
for (const entry of entries) {
assert.ok(util.inspect(entry).includes('this is detail'));
}
}));

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

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

0 comments on commit 8381fba

Please sign in to comment.