Skip to content

Fix thisArg binding in polyArrFindIndex / polyArrFindLastIndex polyfills#562

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-bitwise-or-in-polyfills
Open

Fix thisArg binding in polyArrFindIndex / polyArrFindLastIndex polyfills#562
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-bitwise-or-in-polyfills

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

polyArrFindIndex and polyArrFindLastIndex were using bitwise OR (|) when resolving callback context, which coerced object thisArg values and broke callback this binding. This updates both polyfills to use logical fallback semantics as intended.

  • Polyfill callback context fix

    • Replaced thisArg | theArray with thisArg || theArray in:
      • lib/src/polyfills/array.ts (polyArrFindIndex)
      • lib/src/polyfills/array.ts (polyArrFindLastIndex)
    • Effect: callback this now correctly uses the provided thisArg, and falls back to theArray only when thisArg is not provided/falsy.
  • Regression coverage

    • Added focused tests in lib/test/src/common/polyfills/array.test.ts for both functions to verify:
      • explicit thisArg is preserved as callback this
      • default fallback binds callback this to the source array
// before (buggy)
callbackFn[CALL](thisArg | theArray as any, value, index, theArray);

// after
callbackFn[CALL](thisArg || theArray as any, value, index, theArray);

Warning

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
    • Triggering command: /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)
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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:

Copilot AI changed the title [WIP] Fix bug: Use logical OR in polyArrFindIndex and polyArrFindLastIndex Fix thisArg binding in polyArrFindIndex / polyArrFindLastIndex polyfills May 15, 2026
Copilot finished work on behalf of MSNev May 15, 2026 20:43
Copilot AI requested a review from MSNev May 15, 2026 20:43
@MSNev MSNev marked this pull request as ready for review May 15, 2026 23:48
@MSNev MSNev requested a review from a team as a code owner May 15, 2026 23:48
Copilot AI review requested due to automatic review settings May 15, 2026 23:48
@MSNev MSNev requested a review from a team as a code owner May 15, 2026 23:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes callback this binding in array find-index polyfills and adds regression coverage for the corrected behavior.

Changes:

  • Updates polyArrFindIndex and polyArrFindLastIndex callback invocation context handling.
  • Adds tests verifying object thisArg binding 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 falsy thisArg values such as 0, 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 falsy thisArg values.
        if (idx in theArray && callbackFn[CALL](thisArg || theArray as any, theArray[idx], idx, theArray)) {

Comment thread lib/src/polyfills/array.ts Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.46%. Comparing base (4d28559) to head (4cfd860).

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           
Files with missing lines Coverage Δ
lib/src/polyfills/array.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

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)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Bitwise OR (|) instead of logical OR (||) in polyArrFindIndex/polyArrFindLastIndex

3 participants