Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks: getEntriesBy[Name|Type](undefined) should not return all the entries #42104

Merged
merged 1 commit into from Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/internal/perf/performance.js
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
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'
});