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 <devnexen@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
This commit is contained in:
Kirill Fomichev 2019-09-04 23:01:07 +03:00 committed by Rich Trott
parent 6d01f1fa41
commit ef9ecfbcfe
2 changed files with 7 additions and 0 deletions

View File

@ -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);

View File

@ -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