Skip to content

Commit c146fff

Browse files
fanatidtargos
authored andcommitted
perf_hooks: ignore duplicated entries in observer
PerformanceObserver should add to observing only unique entry types. PR-URL: #29442 Reviewed-By: David Carlier <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 9b4a49c commit c146fff

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/perf_hooks.js

+1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ class PerformanceObserver extends AsyncResource {
354354
for (var n = 0; n < entryTypes.length; n++) {
355355
const entryType = entryTypes[n];
356356
const list = getObserversList(entryType);
357+
if (this[kTypes][entryType]) continue;
357358
const item = { obs: this };
358359
this[kTypes][entryType] = item;
359360
L.append(list, item);

test/parallel/test-performanceobserver.js

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
6262
'for option "entryTypes"'
6363
});
6464
});
65+
66+
const obs = new PerformanceObserver(common.mustNotCall());
67+
obs.observe({ entryTypes: ['mark', 'mark'] });
68+
obs.disconnect();
69+
performance.mark('42');
70+
assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_MARK], 0);
6571
}
6672

6773
// Test Non-Buffered

0 commit comments

Comments
 (0)