From 93f0b4d35bf72a1119b8a5bfea932b85faa1a4a6 Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Tue, 16 Mar 2021 22:15:02 +0530 Subject: [PATCH] perf_hooks: add toJSON to performance class 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: https://github.com/nodejs/node/issues/37623 PR-URL: https://github.com/nodejs/node/pull/37771 Fixes: https://github.com/nodejs/node/issues/37623 Reviewed-By: James M Snell --- doc/api/perf_hooks.md | 9 +++++++++ lib/perf_hooks.js | 14 ++++++++++++++ test/parallel/test-tojson-perf_hooks.js | 14 ++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 test/parallel/test-tojson-perf_hooks.js diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 11795b98dc71fa..3609ddfc042bf0 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -261,6 +261,14 @@ If the wrapped function returns a promise, a finally handler will be attached to the promise and the duration will be reported once the finally handler is invoked. +### `performance.toJSON()` + + +An object which is JSON representation of the `performance` object. It +is similar to [`window.performance.toJSON`][] in browsers. + ## Class: `PerformanceEntry`