Fix thisArg binding in polyArrFindIndex / polyArrFindLastIndex polyfills#562
Open
Copilot wants to merge 3 commits into
Open
Fix thisArg binding in polyArrFindIndex / polyArrFindLastIndex polyfills#562Copilot wants to merge 3 commits into
thisArg binding in polyArrFindIndex / polyArrFindLastIndex polyfills#562Copilot wants to merge 3 commits into
Conversation
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>
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.46% 99.46%
=======================================
Files 145 145
Lines 4271 4271
Branches 938 918 -20
=======================================
Hits 4248 4248
Misses 23 23
🚀 New features to boost your workflow:
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| let len = theArray[LENGTH] >>> 0; | ||
| for (let idx = len - 1; idx >= 0; idx--) { | ||
| if (idx in theArray && callbackFn[CALL](thisArg | theArray as any, theArray[idx], idx, theArray)) { | ||
| if (idx in theArray && callbackFn[CALL](thisArg || theArray as any, theArray[idx], idx, theArray)) { |
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: