Skip to content

Commit

Permalink
perf: add toJSON to performance class
Browse files Browse the repository at this point in the history
Added toJSON method to the InternalPerformance class as per the
convention followed in other performance classes and per the spec:
https://www.w3.org/TR/hr-time/#tojson-method

Fixes: #37623
  • Loading branch information
yashLadha committed Mar 17, 2021
1 parent 8e8dea3 commit 551aa74
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ class Performance extends EventTarget {
timeOrigin: this.timeOrigin,
}, opts)}`;
}

toJSON() {
return {
nodeTiming: this.nodeTiming.toJSON(),
timeOrigin: this.timeOrigin,
eventLoopUtilization: this.eventLoopUtilization()
};
}
}

class InternalPerformance extends EventTarget {}
Expand Down Expand Up @@ -114,7 +122,7 @@ module.exports = {
PerformanceObserver,
monitorEventLoopDelay,
createHistogram,
performance: new InternalPerformance(),
performance: new InternalPerformance()
};

ObjectDefineProperty(module.exports, 'constants', {
Expand Down

0 comments on commit 551aa74

Please sign in to comment.