perf_hooks: fix error message for invalid entryTypes

Will now print a more meaningful value instead of always [object Object]

PR-URL: https://github.com/nodejs/node/pull/33285
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Michaël Zasso committed 2020-05-10 13:53:15 +02:00
1 parent 94e5b5c77d
commit 1182539307
2 files changed
+7 -6

No files matched your search

+6 -5
View File
@@ -341,11 +341,12 @@ 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();
@@ -353,7 +354,7 @@ class PerformanceObserver extends AsyncResource {
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 };
+1 -1
View File
@@ -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"'
});
});