File tree Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -720,22 +720,11 @@ Array.from = $A;
720
720
var every = wrapNative ( Array . prototype . every ) ;
721
721
}
722
722
723
- // Prototype's `Array#inject` behaves similarly to ES5's `Array#reduce`.
724
- var _reduce = arrayProto . reduce ;
725
- function inject ( memo , iterator ) {
726
- iterator = iterator || Prototype . K ;
727
- var context = arguments [ 2 ] ;
728
- // The iterator must be bound, as `Array#reduce` always binds to
729
- // `undefined`.
730
- return _reduce . call ( this , iterator . bind ( context ) , memo ) ;
731
- }
723
+ // We used to define an `inject` method here that relied on ES5's
724
+ // `Array#reduce` (if present), but using `reduce` prevents us from
725
+ // catching a thrown `$break`. So arrays now use the standard
726
+ // `Enumerable.inject` like they did previously.
732
727
733
- // Piggyback on `Array#reduce` if it exists; otherwise fall back to the
734
- // standard `Enumerable.inject`.
735
- if ( ! arrayProto . reduce ) {
736
- var inject = Enumerable . inject ;
737
- }
738
-
739
728
Object . extend ( arrayProto , Enumerable ) ;
740
729
741
730
if ( ! arrayProto . _reverse )
@@ -753,7 +742,6 @@ Array.from = $A;
753
742
any : some ,
754
743
every : every ,
755
744
all : every ,
756
- inject : inject ,
757
745
758
746
clear : clear ,
759
747
first : first ,
Original file line number Diff line number Diff line change @@ -271,6 +271,13 @@ new Test.Unit.Runner({
271
271
Fixtures . Primes . inject ( 0 , function ( sum , value ) {
272
272
return sum + value ;
273
273
} ) ) ;
274
+
275
+ var sum = Fixtures . Primes . inject ( 0 , function ( sum , value ) {
276
+ if ( value === 5 ) throw $break ;
277
+ return sum + value ;
278
+ } ) ;
279
+
280
+ this . assertEqual ( 6 , sum , 'inject should catch a thrown $break' ) ;
274
281
} ,
275
282
276
283
"test #inject passes memo, value, index and collection to the iterator" : function ( ) {
You can’t perform that action at this time.
0 commit comments