Skip to content

Conversation

@weillercarvalho
Copy link

@weillercarvalho weillercarvalho commented Nov 16, 2025

Summary

  • Fixes EmberArray.prototype.reduce so it behaves like native Array.prototype.reduce when initialValue is omitted.
  • Adds regression coverage for both the implicit‐initial scenario and the empty-array TypeError.

Customer Impact / Use Case

Apps relying on EmberArray.reduce without an explicit initialValue currently get undefined as the first accumulator and never see
the expected TypeError on empty collections, yielding incorrect results and masking bugs.

Implementation Details

  • Detect whether initialValue was provided (arguments.length > 1), seed the accumulator accordingly, and reuse objectAt to keep proxy support intact.
  • Throw TypeError('Reduce of empty array with no initial value') when the array is empty and no seed is passed.
  • Extend packages/@ember/-internals/runtime/tests/array/reduce-test.js with two new tests covering these code paths across every helper used in runArrayTests.

Tests

All unit tests passed after modification.
Captura de tela 2025-11-16 073436

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.

1 participant