Skip to content

Commit 822cfc4

Browse files
OskarEichlermeta-codesync[bot]
authored andcommitted
Preserve null NodeList forEach context (#58243)
Summary: `NodeList.forEach` currently treats both null and undefined as the omitted-context fast path, so a strict callback receives undefined when the caller explicitly supplied null. Use the fast path only for undefined and cover the standards-compatible null receiver. Fixes #58242. ## Changelog: [GENERAL] [FIXED] - Preserve an explicit null `thisArg` in NodeList.forEach callbacks. Pull Request resolved: #58243 Test Plan: - Exact upstream focused suite: 12 existing tests passed and the new null-context regression failed. - Fixed focused Fantom suite: 13/13 passed. - Fresh Flow check: 0 errors. - Targeted no-ignore ESLint, Prettier, and `git diff --check` passed. Only the observably incorrect explicit-null context changes; omitted and undefined contexts are unchanged. Reviewed By: christophpurrer Differential Revision: D123889530 Pulled By: rubennorte fbshipit-source-id: ddca4cd7d2e62c8dcf40cc7b583fa15d74127afa
1 parent ff78e95 commit 822cfc4

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎packages/react-native/src/private/webapis/dom/oldstylecollections/NodeList.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default class NodeList<T> implements Iterable<T>, ArrayLike<T> {
7575
const arrayLike: ArrayLike<T> = this;
7676

7777
for (let index = 0; index < this._length; index++) {
78-
if (thisArg == null) {
78+
if (thisArg === undefined) {
7979
callbackFn(arrayLike[index], index, this);
8080
} else {
8181
callbackFn.call(thisArg, arrayLike[index], index, this);

‎packages/react-native/src/private/webapis/dom/oldstylecollections/__tests__/NodeList-itest.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ describe('NodeList', () => {
166166
i++;
167167
}, explicitThis);
168168
});
169+
170+
it('preserves an explicit null `this` argument', () => {
171+
const collection = createNodeList(['a']);
172+
let that;
173+
174+
collection.forEach(function (this: unknown) {
175+
'use strict';
176+
that = this;
177+
}, null);
178+
179+
expect(that).toBe(null);
180+
});
169181
});
170182

171183
describe('global constructor', () => {

0 commit comments

Comments
 (0)