Skip to content

Commit

Permalink
perf_hooks: do not return all entries with getEntriesBy[Name|Type]
Browse files Browse the repository at this point in the history
Fix: #42028

PR-URL: #42104
Fixes: #42028
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
meixg authored and danielleadams committed Apr 24, 2022
1 parent a44bfdf commit 9a526fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/internal/perf/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_MISSING_ARGS
}
} = require('internal/errors');

Expand Down Expand Up @@ -86,16 +87,18 @@ function getEntries() {
}

function getEntriesByName(name) {
if (name !== undefined) {
name = `${name}`;
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('name');
}
name = `${name}`;
return filterBufferMapByNameAndType(name, undefined);
}

function getEntriesByType(type) {
if (type !== undefined) {
type = `${type}`;
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('type');
}
type = `${type}`;
return filterBufferMapByNameAndType(undefined, type);
}

Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-performance-timeline.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ await setTimeout(50);
performance.measure('a', 'one');
const entriesByName = performance.getEntriesByName('a');
assert.deepStrictEqual(entriesByName.map((x) => x.entryType), ['measure', 'mark', 'measure', 'mark']);

// getEntriesBy[Name|Type](undefined)
performance.mark(undefined);
assert.strictEqual(performance.getEntriesByName(undefined).length, 1);
assert.strictEqual(performance.getEntriesByType(undefined).length, 0);
assert.throws(() => performance.getEntriesByName(), {
name: 'TypeError',
message: 'The "name" argument must be specified',
code: 'ERR_MISSING_ARGS'
});
assert.throws(() => performance.getEntriesByType(), {
name: 'TypeError',
message: 'The "type" argument must be specified',
code: 'ERR_MISSING_ARGS'
});

0 comments on commit 9a526fb

Please sign in to comment.