From 286bead88552b9eab1f3cd3c9142a1e7da774a4d Mon Sep 17 00:00:00 2001 From: Luke Taher Date: Tue, 24 Sep 2024 20:39:51 +0100 Subject: [PATCH] perf_hooks: add missing type argument to getEntriesByName Fixes: https://github.com/nodejs/node/issues/54766 PR-URL: https://github.com/nodejs/node/pull/54767 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- lib/internal/perf/performance.js | 7 +++++-- test/parallel/test-performance-timeline.mjs | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/internal/perf/performance.js b/lib/internal/perf/performance.js index 836dcaa87d8b31..9e08bc5db7ea49 100644 --- a/lib/internal/perf/performance.js +++ b/lib/internal/perf/performance.js @@ -97,13 +97,16 @@ class Performance extends EventTarget { return filterBufferMapByNameAndType(); } - getEntriesByName(name) { + getEntriesByName(name, type = undefined) { validateInternalField(this, kPerformanceBrand, 'Performance'); if (arguments.length === 0) { throw new ERR_MISSING_ARGS('name'); } name = `${name}`; - return filterBufferMapByNameAndType(name, undefined); + if (type !== undefined) { + type = `${type}`; + } + return filterBufferMapByNameAndType(name, type); } getEntriesByType(type) { diff --git a/test/parallel/test-performance-timeline.mjs b/test/parallel/test-performance-timeline.mjs index 57e0f6f0b7b6da..e3af49447c8604 100644 --- a/test/parallel/test-performance-timeline.mjs +++ b/test/parallel/test-performance-timeline.mjs @@ -33,6 +33,12 @@ await setTimeout(50); performance.measure('a', 'one'); const entriesByName = performance.getEntriesByName('a'); assert.deepStrictEqual(entriesByName.map((x) => x.entryType), ['measure', 'mark', 'measure', 'mark']); +const marksByName = performance.getEntriesByName('a', 'mark'); +assert.deepStrictEqual(marksByName.map((x) => x.entryType), ['mark', 'mark']); +const measuresByName = performance.getEntriesByName('a', 'measure'); +assert.deepStrictEqual(measuresByName.map((x) => x.entryType), ['measure', 'measure']); +const invalidTypeEntriesByName = performance.getEntriesByName('a', null); +assert.strictEqual(invalidTypeEntriesByName.length, 0); // getEntriesBy[Name|Type](undefined) performance.mark(undefined);