Skip to content

Commit

Permalink
perf_hooks: fix error message for invalid entryTypes
Browse files Browse the repository at this point in the history
Will now print a more meaningful value instead of always [object Object]

PR-URL: #33285
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
targos authored and codebytere committed May 11, 2020
1 parent ba66b21 commit 398bdf4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
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;
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
Original file line number Diff line number Diff line change
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

0 comments on commit 398bdf4

Please sign in to comment.