ember.js
ember.js copied to clipboard
[BUGFIX beta] Align EmberArray.reduce with native semantics, related with issue #21005.
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.