Skip to content

Commit

Permalink
perf_hooks: add missing type argument to getEntriesByName
Browse files Browse the repository at this point in the history
Fixes: #54766
PR-URL: #54767
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
luketaher authored and targos committed Oct 4, 2024
1 parent bebc95e commit cbfc980
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/internal/perf/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-performance-timeline.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cbfc980

Please sign in to comment.