Skip to content

Commit c72c3f4

Browse files
meixgsxa
authored andcommitted
perf_hooks: do not return all entries with getEntriesBy[Name|Type]
Fix: #42028 PR-URL: #42104 Fixes: #42028 Reviewed-By: Mestery <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent ccacf99 commit c72c3f4

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/internal/perf/performance.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
const {
1010
codes: {
1111
ERR_ILLEGAL_CONSTRUCTOR,
12+
ERR_MISSING_ARGS
1213
}
1314
} = require('internal/errors');
1415

@@ -86,16 +87,18 @@ function getEntries() {
8687
}
8788

8889
function getEntriesByName(name) {
89-
if (name !== undefined) {
90-
name = `${name}`;
90+
if (arguments.length === 0) {
91+
throw new ERR_MISSING_ARGS('name');
9192
}
93+
name = `${name}`;
9294
return filterBufferMapByNameAndType(name, undefined);
9395
}
9496

9597
function getEntriesByType(type) {
96-
if (type !== undefined) {
97-
type = `${type}`;
98+
if (arguments.length === 0) {
99+
throw new ERR_MISSING_ARGS('type');
98100
}
101+
type = `${type}`;
99102
return filterBufferMapByNameAndType(undefined, type);
100103
}
101104

test/parallel/test-performance-timeline.mjs

+15
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,18 @@ await setTimeout(50);
3333
performance.measure('a', 'one');
3434
const entriesByName = performance.getEntriesByName('a');
3535
assert.deepStrictEqual(entriesByName.map((x) => x.entryType), ['measure', 'mark', 'measure', 'mark']);
36+
37+
// getEntriesBy[Name|Type](undefined)
38+
performance.mark(undefined);
39+
assert.strictEqual(performance.getEntriesByName(undefined).length, 1);
40+
assert.strictEqual(performance.getEntriesByType(undefined).length, 0);
41+
assert.throws(() => performance.getEntriesByName(), {
42+
name: 'TypeError',
43+
message: 'The "name" argument must be specified',
44+
code: 'ERR_MISSING_ARGS'
45+
});
46+
assert.throws(() => performance.getEntriesByType(), {
47+
name: 'TypeError',
48+
message: 'The "type" argument must be specified',
49+
code: 'ERR_MISSING_ARGS'
50+
});

0 commit comments

Comments
 (0)