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: fix error message for invalid entryTypes #33285

Closed
wants to merge 1 commit into from
Closed
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: 6 additions & 5 deletions lib/perf_hooks.js
Expand Up @@ -341,19 +341,20 @@ class PerformanceObserver extends AsyncResource {
if (typeof options !== 'object' || options === null) {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
if (!ArrayIsArray(options.entryTypes)) {
throw new ERR_INVALID_OPT_VALUE('entryTypes', options);
const { entryTypes } = options;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to prevent accessing the value more than once (it could be a getter that doesn't always return the same thing)

if (!ArrayIsArray(entryTypes)) {
throw new ERR_INVALID_OPT_VALUE('entryTypes', entryTypes);
}
const entryTypes = options.entryTypes.filter(filterTypes).map(mapTypes);
if (entryTypes.length === 0) {
const filteredEntryTypes = entryTypes.filter(filterTypes).map(mapTypes);
if (filteredEntryTypes.length === 0) {
throw new ERR_VALID_PERFORMANCE_ENTRY_TYPE();
}
this.disconnect();
const observerCountsGC = observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC];
this[kBuffer][kEntries] = [];
L.init(this[kBuffer][kEntries]);
this[kBuffering] = Boolean(options.buffered);
for (const entryType of entryTypes) {
for (const entryType of filteredEntryTypes) {
const list = getObserversList(entryType);
if (this[kTypes][entryType]) continue;
const item = { obs: this };
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-performanceobserver.js
Expand Up @@ -58,7 +58,7 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
{
code: 'ERR_INVALID_OPT_VALUE',
name: 'TypeError',
message: 'The value "[object Object]" is invalid ' +
message: `The value "${i}" is invalid ` +
'for option "entryTypes"'
});
});
Expand Down