From 68551d22d2e8fcee1dc3e67ff5e80bb0ff9d543f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 7 May 2020 20:23:56 +0200 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Chengzhong Wu Reviewed-By: Luigi Pinca --- lib/perf_hooks.js | 11 ++++++----- test/parallel/test-performanceobserver.js | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index efc92ca8c4aee4..2ce0d29464a9bd 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -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 }; diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js index c68de859b6b654..3b2f94411f3df3 100644 --- a/test/parallel/test-performanceobserver.js +++ b/test/parallel/test-performanceobserver.js @@ -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"' }); });