Fix thisArg binding in polyArrFindIndex / polyArrFindLastIndex polyfills#562
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix bug: Use logical OR in polyArrFindIndex and polyArrFindLastIndex
Fix May 15, 2026
thisArg binding in polyArrFindIndex / polyArrFindLastIndex polyfills
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes callback this binding in array find-index polyfills and adds regression coverage for the corrected behavior.
Changes:
- Updates
polyArrFindIndexandpolyArrFindLastIndexcallback invocation context handling. - Adds tests verifying object
thisArgbinding and default array binding.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/src/polyfills/array.ts |
Adjusts callback thisArg fallback logic for find-index polyfills. |
lib/test/src/common/polyfills/array.test.ts |
Adds regression tests for callback context binding. |
Comments suppressed due to low confidence (1)
lib/src/polyfills/array.ts:275
- Using
||still replaces explicitly supplied falsythisArgvalues such as0,false, or""with the source array, so callbacks cannot observe those valid bindings. Use a check that only falls back when no usable default was intended (for example omitted/nullish, per the API docs) and add a regression case for falsythisArgvalues.
if (idx in theArray && callbackFn[CALL](thisArg || theArray as any, theArray[idx], idx, theArray)) {
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #562 +/- ##
=======================================
Coverage 99.43% 99.43%
=======================================
Files 150 150
Lines 4452 4452
Branches 956 955 -1
=======================================
Hits 4427 4427
Misses 25 25
🚀 New features to boost your workflow:
|
Agent-Logs-Url: https://github.com/nevware21/ts-utils/sessions/5e6a31e7-083e-47d8-973e-0f74f23dc2b0 Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/nevware21/ts-utils/sessions/5e6a31e7-083e-47d8-973e-0f74f23dc2b0 Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
3879d25 to
745458e
Compare
nev21
approved these changes
May 17, 2026
nev21
added a commit
that referenced
this pull request
May 19, 2026
## Release v0.14.0 This PR increases the version to `0.14.0` and updates the changelog with all significant changes since v0.13.0. ### Summary of Changes #### Features - New array helpers and array-like detection (#525) - `strReplace` and `strReplaceAll` string helpers (#527) - `strCapitalizeWords` helper (#528) - `strTruncate`, `strCount`, `strAt`, `strMatchAll` helpers (#529, #530) - `arrFlatMap` with ES5 polyfill (#533) - Typing utilities and expanded TSDoc examples (#535) - `isAsyncIterable` and `isIntegerInRange` helpers (#536) - `strStartsWithAny`, `strEndsWithAny`, `strWrap`, `strUnwrap`, `strNormalizeNewlines` (#543) - New object utility helpers and prototype pollution hardening (#564, #565) #### Bug Fixes - Fix ES2015 built-in type errors in consumers by adding lib reference directive to published declarations (#558) - Fix `thisArg` binding in `polyArrFindIndex` / `polyArrFindLastIndex` polyfills (#562) - Fix falsy `thisArg` (0, `''`, `false`) being overridden in `arrForEach`, `iterForOf`, `objForEachKey` (#566) #### Repository Improvements - Drop Node.js 16 from CI matrix and add Node.js 24 (#549) - Upgrade Grunt devDependency to v1.6.2 (#552) - Add funding metadata to published package manifests (#554) ### Files Updated - `CHANGELOG.md` — Added v0.14.0 entry - `package.json` — Version bumped to 0.14.0 - `lib/package.json` — Version bumped to 0.14.0 - `README.md` — Updated recommended version specification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
polyArrFindIndexandpolyArrFindLastIndexwere using bitwise OR (|) when resolving callback context, which coerced objectthisArgvalues and broke callbackthisbinding. This updates both polyfills to use logical fallback semantics as intended.Polyfill callback context fix
thisArg | theArraywiththisArg || theArrayin:lib/src/polyfills/array.ts(polyArrFindIndex)lib/src/polyfills/array.ts(polyArrFindLastIndex)thisnow correctly uses the providedthisArg, and falls back totheArrayonly whenthisArgis not provided/falsy.Regression coverage
lib/test/src/common/polyfills/array.test.tsfor both functions to verify:thisArgis preserved as callbackthisthisto the source arrayWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
accounts.google.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=4244 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-7608247 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,17861204591039112903,10939758914733537520,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,16105935546789010716,16606217994416365594,4 --trace-process-track-uuid=3190708989122997041(dns block)/home/REDACTED/.cache/puppeteer/chrome/linux-148.0.7778.97/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-148.0.7778.97/chrome-linux64/chrome --user-data-dir=/tmp/karma-7608247 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu --disable-web-security --disable-dev-shm-usage http://localhost:9876/?id=7608247 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222(dns block)/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=4481 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-68332849 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,7502828240700176064,4166064653183156238,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,16762107709327361543,16977408465753334385,4 --trace-process-track-uuid=3190708989122997041(dns block)clients2.google.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=4244 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-7608247 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,17861204591039112903,10939758914733537520,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,16105935546789010716,16606217994416365594,4 --trace-process-track-uuid=3190708989122997041(dns block)/home/REDACTED/.cache/puppeteer/chrome/linux-148.0.7778.97/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-148.0.7778.97/chrome-linux64/chrome --user-data-dir=/tmp/karma-7608247 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu --disable-web-security --disable-dev-shm-usage http://localhost:9876/?id=7608247 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222(dns block)/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=4481 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-68332849 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,7502828240700176064,4166064653183156238,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,16762107709327361543,16977408465753334385,4 --trace-process-track-uuid=3190708989122997041(dns block)redirector.gvt1.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=4244 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-7608247 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,17861204591039112903,10939758914733537520,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,16105935546789010716,16606217994416365594,4 --trace-process-track-uuid=3190708989122997041(dns block)/home/REDACTED/.cache/puppeteer/chrome/linux-148.0.7778.97/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-148.0.7778.97/chrome-linux64/chrome --user-data-dir=/tmp/karma-7608247 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu --disable-web-security --disable-dev-shm-usage http://localhost:9876/?id=7608247 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222(dns block)/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=4481 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-68332849 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,7502828240700176064,4166064653183156238,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,16762107709327361543,16977408465753334385,4 --trace-process-track-uuid=3190708989122997041(dns block)www.google.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=4244 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-7608247 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,17861204591039112903,10939758914733537520,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,16105935546789010716,16606217994416365594,4 --trace-process-track-uuid=3190708989122997041(dns block)/home/REDACTED/.cache/puppeteer/chrome/linux-148.0.7778.97/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-148.0.7778.97/chrome-linux64/chrome --user-data-dir=/tmp/karma-7608247 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu --disable-web-security --disable-dev-shm-usage http://localhost:9876/?id=7608247 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222(dns block)/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=4481 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-68332849 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,7502828240700176064,4166064653183156238,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,16762107709327361543,16977408465753334385,4 --trace-process-track-uuid=3190708989122997041(dns block)www.googleapis.com/usr/local/bin/node node install.js(dns block)If you need me to access, download, or install something from one of these locations, you can either: