From b4d1dc08132651a98afef7e1321a82537f9a7391 Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Sun, 30 Aug 2026 11:36:25 +0200 Subject: [PATCH] Preserve null NodeList forEach context --- .../webapis/dom/oldstylecollections/NodeList.js | 2 +- .../oldstylecollections/__tests__/NodeList-itest.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/react-native/src/private/webapis/dom/oldstylecollections/NodeList.js b/packages/react-native/src/private/webapis/dom/oldstylecollections/NodeList.js index dc9cc466453..31eee8b52ad 100644 --- a/packages/react-native/src/private/webapis/dom/oldstylecollections/NodeList.js +++ b/packages/react-native/src/private/webapis/dom/oldstylecollections/NodeList.js @@ -75,7 +75,7 @@ export default class NodeList implements Iterable, ArrayLike { const arrayLike: ArrayLike = this; for (let index = 0; index < this._length; index++) { - if (thisArg == null) { + if (thisArg === undefined) { callbackFn(arrayLike[index], index, this); } else { callbackFn.call(thisArg, arrayLike[index], index, this); diff --git a/packages/react-native/src/private/webapis/dom/oldstylecollections/__tests__/NodeList-itest.js b/packages/react-native/src/private/webapis/dom/oldstylecollections/__tests__/NodeList-itest.js index fc7710f028a..466600d4a76 100644 --- a/packages/react-native/src/private/webapis/dom/oldstylecollections/__tests__/NodeList-itest.js +++ b/packages/react-native/src/private/webapis/dom/oldstylecollections/__tests__/NodeList-itest.js @@ -166,6 +166,18 @@ describe('NodeList', () => { i++; }, explicitThis); }); + + it('preserves an explicit null `this` argument', () => { + const collection = createNodeList(['a']); + let that; + + collection.forEach(function (this: unknown) { + 'use strict'; + that = this; + }, null); + + expect(that).toBe(null); + }); }); describe('global constructor', () => {