From c146fff307423a5fa4368268e15188fbf58dc69e Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Wed, 4 Sep 2019 23:01:07 +0300 Subject: [PATCH] perf_hooks: ignore duplicated entries in observer PerformanceObserver should add to observing only unique entry types. PR-URL: https://github.com/nodejs/node/pull/29442 Reviewed-By: David Carlier Reviewed-By: Minwoo Jung --- lib/perf_hooks.js | 1 + test/parallel/test-performanceobserver.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index 1bf635790e1332..12909b047ce20b 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -354,6 +354,7 @@ class PerformanceObserver extends AsyncResource { for (var n = 0; n < entryTypes.length; n++) { const entryType = entryTypes[n]; const list = getObserversList(entryType); + if (this[kTypes][entryType]) continue; const item = { obs: this }; this[kTypes][entryType] = item; L.append(list, item); diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js index 513d7db220c0d1..75097cb8c77141 100644 --- a/test/parallel/test-performanceobserver.js +++ b/test/parallel/test-performanceobserver.js @@ -62,6 +62,12 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0); 'for option "entryTypes"' }); }); + + const obs = new PerformanceObserver(common.mustNotCall()); + obs.observe({ entryTypes: ['mark', 'mark'] }); + obs.disconnect(); + performance.mark('42'); + assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_MARK], 0); } // Test Non-Buffered