Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes 2169. #2177

Merged
merged 1 commit into from

2 participants

Olmo Maldonado Arian Stolwijk
Olmo Maldonado
Owner

As per spec, Array.filter should return the filtered items, and not
andany possible mutation that might have occurred in the callback. See
referenced issue for more information.

Added coverage for case.

PASSED: IE6-9; FF3-5, 8, 11; Chrome latest; Safari 5; Opera 11

Olmo Maldonado
Owner

Fixes #2169

Olmo Maldonado ibolmo Fixes 2169.
As per spec, `Array.filter` should return the filtered items, and not
andany possible mutation that might have occurred in the callback. See
referenced issue for more information.

Added coverage for case.

PASSED: IE6-9; FF3-5, 8, 11; Chrome latest; Safari 5; Opera 11
676f6ce
Arian Stolwijk
Owner

:+1:

Olmo Maldonado ibolmo merged commit 71cef50 into from
Olmo Maldonado
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 19, 2011
  1. Olmo Maldonado

    Fixes 2169.

    ibolmo authored
    As per spec, `Array.filter` should return the filtered items, and not
    andany possible mutation that might have occurred in the callback. See
    referenced issue for more information.
    
    Added coverage for case.
    
    PASSED: IE6-9; FF3-5, 8, 11; Chrome latest; Safari 5; Opera 11
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 2 deletions.
  1. +3 −2 Source/Types/Array.js
  2. +16 −0 Specs/1.4base/Types/Array.js
5 Source/Types/Array.js
View
@@ -26,8 +26,9 @@ Array.implement({
filter: function(fn, bind){
var results = [];
- for (var i = 0, l = this.length >>> 0; i < l; i++){
- if ((i in this) && fn.call(bind, this[i], i, this)) results.push(this[i]);
+ for (var value, i = 0, l = this.length >>> 0; i < l; i++) if (i in this){
+ value = this[i];
+ if (fn.call(bind, value, i, this)) results.push(value);
}
return results;
},
16 Specs/1.4base/Types/Array.js
View
@@ -26,4 +26,20 @@ describe('Array', function(){
expect([].some.call(object, fn)).toBe(false);
});
+ describe('Array.filter', function(){
+
+ it('should return the original item, and not any mutations.', function(){
+
+ var result = [0, 1, 2].filter(function(num, i, array){
+ if (num == 1){
+ array[i] = 'mutation';
+ return true;
+ }
+ });
+
+ expect(result[0]).toEqual(1);
+ });
+
+ });
+
});
Something went wrong with that request. Please try again.