Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a258bc9

Browse filesBrowse files
aduh95danielleadams
authored andcommitted
perf_hooks: refactor to avoid unsafe array iteration
PR-URL: #36723 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 5bc130b commit a258bc9
Copy full SHA for a258bc9

File tree

Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed
Open diff view settings
Collapse file

‎lib/perf_hooks.js‎

Copy file name to clipboardExpand all lines: lib/perf_hooks.js
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const {
44
ArrayIsArray,
55
ArrayPrototypeFilter,
6+
ArrayPrototypeForEach,
67
ArrayPrototypeIncludes,
78
ArrayPrototypeMap,
89
ArrayPrototypePush,
@@ -375,13 +376,13 @@ class PerformanceObserver {
375376
disconnect() {
376377
const observerCountsGC = observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC];
377378
const types = this[kTypes];
378-
for (const key of ObjectKeys(types)) {
379+
ArrayPrototypeForEach(ObjectKeys(types), (key) => {
379380
const item = types[key];
380381
if (item) {
381382
L.remove(item);
382383
observerCounts[key]--;
383384
}
384-
}
385+
});
385386
this[kTypes] = {};
386387
if (observerCountsGC === 1 &&
387388
observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC] === 0) {
@@ -408,14 +409,14 @@ class PerformanceObserver {
408409
this[kBuffer][kEntries] = [];
409410
L.init(this[kBuffer][kEntries]);
410411
this[kBuffering] = Boolean(options.buffered);
411-
for (const entryType of filteredEntryTypes) {
412+
ArrayPrototypeForEach(filteredEntryTypes, (entryType) => {
412413
const list = getObserversList(entryType);
413-
if (this[kTypes][entryType]) continue;
414+
if (this[kTypes][entryType]) return;
414415
const item = { obs: this };
415416
this[kTypes][entryType] = item;
416417
L.append(list, item);
417418
observerCounts[entryType]++;
418-
}
419+
});
419420
if (observerCountsGC === 0 &&
420421
observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC] === 1) {
421422
installGarbageCollectionTracking();
@@ -640,6 +641,7 @@ function sortedInsert(list, entry) {
640641
}
641642

642643
class ELDHistogram extends Histogram {
644+
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
643645
enable() { return this[kHandle].enable(); }
644646
disable() { return this[kHandle].disable(); }
645647
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.