From a3310d13bf37a2d3af08353bec3bbd07595ee55a Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 21 May 2022 17:53:52 +0800 Subject: [PATCH] perf_hooks: use `kEmptyObject` PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel --- lib/internal/perf/event_loop_delay.js | 6 +++++- lib/internal/perf/observe.js | 3 ++- lib/internal/perf/timerify.js | 6 +++++- lib/internal/perf/usertiming.js | 9 ++++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/internal/perf/event_loop_delay.js b/lib/internal/perf/event_loop_delay.js index efd45f4ed77..18d7967477e 100644 --- a/lib/internal/perf/event_loop_delay.js +++ b/lib/internal/perf/event_loop_delay.js @@ -27,6 +27,10 @@ const { kMap, } = require('internal/histogram'); +const { + kEmptyObject, +} = require('internal/util'); + const { makeTransferable, } = require('internal/worker/js_transferable'); @@ -69,7 +73,7 @@ class ELDHistogram extends Histogram { * }} [options] * @returns {ELDHistogram} */ -function monitorEventLoopDelay(options = {}) { +function monitorEventLoopDelay(options = kEmptyObject) { validateObject(options, 'options'); const { resolution = 10 } = options; diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js index c58aec7040f..656015f8410 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -55,6 +55,7 @@ const { customInspectSymbol: kInspect, deprecate, lazyDOMException, + kEmptyObject, } = require('internal/util'); const { @@ -212,7 +213,7 @@ class PerformanceObserver { this.#callback = callback; } - observe(options = {}) { + observe(options = kEmptyObject) { validateObject(options, 'options'); const { entryTypes, diff --git a/lib/internal/perf/timerify.js b/lib/internal/perf/timerify.js index 38f6b3d37ac..926b6537ade 100644 --- a/lib/internal/perf/timerify.js +++ b/lib/internal/perf/timerify.js @@ -34,6 +34,10 @@ const { enqueue, } = require('internal/perf/observe'); +const { + kEmptyObject, +} = require('internal/util'); + function processComplete(name, start, args, histogram) { const duration = now() - start; if (histogram !== undefined) @@ -52,7 +56,7 @@ function processComplete(name, start, args, histogram) { enqueue(entry); } -function timerify(fn, options = {}) { +function timerify(fn, options = kEmptyObject) { validateFunction(fn, 'fn'); validateObject(options, 'options'); diff --git a/lib/internal/perf/usertiming.js b/lib/internal/perf/usertiming.js index 7266b14ef40..51625ee08d5 100644 --- a/lib/internal/perf/usertiming.js +++ b/lib/internal/perf/usertiming.js @@ -27,7 +27,10 @@ const { } = require('internal/errors'); const { structuredClone } = require('internal/structured_clone'); -const { lazyDOMException } = require('internal/util'); +const { + kEmptyObject, + lazyDOMException, +} = require('internal/util'); const markTimings = new SafeMap(); @@ -61,7 +64,7 @@ class PerformanceMark extends InternalPerformanceEntry { name = `${name}`; if (nodeTimingReadOnlyAttributes.has(name)) throw new ERR_INVALID_ARG_VALUE('name', name); - options ??= {}; + options ??= kEmptyObject; validateObject(options, 'options'); const startTime = options.startTime ?? now(); validateNumber(startTime, 'startTime'); @@ -91,7 +94,7 @@ class PerformanceMeasure extends InternalPerformanceEntry { } } -function mark(name, options = {}) { +function mark(name, options = kEmptyObject) { const mark = new PerformanceMark(name, options); enqueue(mark); return mark;