Permalink
Browse files

Merge branch 'master' of yuisource.corp.yahoo.com:yui3

  • Loading branch information...
ericf committed Apr 24, 2012
2 parents 6d88468 + 9d555b0 commit cf20337b7119b5c19e3fafa5764682dba60943bd
@@ -120,7 +120,7 @@ containing the items for which the supplied function returned a truthy value.
*/
A.filter = L._isNative(ArrayProto.filter) ?
function(a, f, o) {
- return a.filter(f, o);
+ return ArrayProto.filter.call(a, f, o);
} :
function(a, f, o) {
var i = 0,
@@ -173,7 +173,7 @@ supplied function does not return a truthy value.
*/
A.every = L._isNative(ArrayProto.every) ?
function(a, f, o) {
- return a.every(f, o);
+ return ArrayProto.every.call(a, f, o);
} :
function(a, f, o) {
for (var i = 0, l = a.length; i < l; ++i) {
@@ -207,12 +207,12 @@ containing all the values returned by the supplied function.
*/
A.map = L._isNative(ArrayProto.map) ?
function(a, f, o) {
- return a.map(f, o);
+ return ArrayProto.map.call(a, f, o);
} :
function(a, f, o) {
var i = 0,
len = a.length,
- results = a.concat();
+ results = ArrayProto.concat.call(a);
for (; i < len; ++i) {
if (i in a) {
@@ -248,7 +248,7 @@ A.reduce = L._isNative(ArrayProto.reduce) ?
function(a, init, f, o) {
// ES5 Array.reduce doesn't support a thisObject, so we need to
// implement it manually.
- return a.reduce(function(init, item, i, a) {
+ return ArrayProto.reduce.call(a, function(init, item, i, a) {
return f.call(o, init, item, i, a);
}, init);
} :

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -119,7 +119,7 @@ containing the items for which the supplied function returned a truthy value.
*/
A.filter = L._isNative(ArrayProto.filter) ?
function(a, f, o) {
- return a.filter(f, o);
+ return ArrayProto.filter.call(a, f, o);
} :
function(a, f, o) {
var i = 0,
@@ -172,7 +172,7 @@ supplied function does not return a truthy value.
*/
A.every = L._isNative(ArrayProto.every) ?
function(a, f, o) {
- return a.every(f, o);
+ return ArrayProto.every.call(a, f, o);
} :
function(a, f, o) {
for (var i = 0, l = a.length; i < l; ++i) {
@@ -206,12 +206,12 @@ containing all the values returned by the supplied function.
*/
A.map = L._isNative(ArrayProto.map) ?
function(a, f, o) {
- return a.map(f, o);
+ return ArrayProto.map.call(a, f, o);
} :
function(a, f, o) {
var i = 0,
len = a.length,
- results = a.concat();
+ results = ArrayProto.concat.call(a);
for (; i < len; ++i) {
if (i in a) {
@@ -247,7 +247,7 @@ A.reduce = L._isNative(ArrayProto.reduce) ?
function(a, init, f, o) {
// ES5 Array.reduce doesn't support a thisObject, so we need to
// implement it manually.
- return a.reduce(function(init, item, i, a) {
+ return ArrayProto.reduce.call(a, function(init, item, i, a) {
return f.call(o, init, item, i, a);
}, init);
} :
View
@@ -1,12 +1,26 @@
Collection Change History
=========================
+3.6.0
+-----
+
+* The `every()`, `filter()`, `map()`, and `reduce()` functions now work
+ correctly on array-like objects in ES5 browsers. [Ticket #2531652]
+
+
+3.5.1
+-----
+
+* No changes.
+
+
3.5.0
-----
* YUI now detects non-native ES5 shims added to native objects by other
libraries and falls back to its own internal shims rather than relying on the
potentially broken code from the other library.
+
* Deprecated arraylist-add and arraylist-filter in favor of individual
subclass implementations or ModelList.
@@ -32,8 +46,10 @@ Collection Change History
* [!] The `sort` parameter of `Array.unique` has been deprecated. It still
works, but you're encouraged not to use it as it will be removed from a
future version of YUI.
+
* `Array.lastIndexOf` now supports the `fromIndex` parameter as specified in
ES5.
+
* Improved the performance of `Array.filter`, `Array.map`, `Array.reduce`, and
`Array.unique`, especially in browsers without native ES5 array extras.
@@ -54,8 +70,11 @@ Collection Change History
------
* `array-extras` is the base submodule for the package.
+
* Added `ArrayList` for generic iterable objects.
+
* `Array.forEach` is an alias for `Array.each`.
+
* Added `Array.invoke` to execute a named method on an array of objects.
@@ -118,7 +118,7 @@ containing the items for which the supplied function returned a truthy value.
*/
A.filter = L._isNative(ArrayProto.filter) ?
function(a, f, o) {
- return a.filter(f, o);
+ return ArrayProto.filter.call(a, f, o);
} :
function(a, f, o) {
var i = 0,
@@ -171,7 +171,7 @@ supplied function does not return a truthy value.
*/
A.every = L._isNative(ArrayProto.every) ?
function(a, f, o) {
- return a.every(f, o);
+ return ArrayProto.every.call(a, f, o);
} :
function(a, f, o) {
for (var i = 0, l = a.length; i < l; ++i) {
@@ -205,12 +205,12 @@ containing all the values returned by the supplied function.
*/
A.map = L._isNative(ArrayProto.map) ?
function(a, f, o) {
- return a.map(f, o);
+ return ArrayProto.map.call(a, f, o);
} :
function(a, f, o) {
var i = 0,
len = a.length,
- results = a.concat();
+ results = ArrayProto.concat.call(a);
for (; i < len; ++i) {
if (i in a) {
@@ -246,7 +246,7 @@ A.reduce = L._isNative(ArrayProto.reduce) ?
function(a, init, f, o) {
// ES5 Array.reduce doesn't support a thisObject, so we need to
// implement it manually.
- return a.reduce(function(init, item, i, a) {
+ return ArrayProto.reduce.call(a, function(init, item, i, a) {
return f.call(o, init, item, i, a);
}, init);
} :
@@ -84,6 +84,21 @@ suite.add(new Y.Test.Case({
Assert.areSame(1, calls);
},
+ 'map() should work on array-like objects': function () {
+ var calls = 0;
+
+ (function () {
+ var results = Y.Array.map(arguments, function () {
+ calls += 1;
+ return 'z';
+ });
+
+ Y.ArrayAssert.itemsAreSame(['z', 'z', 'z'], results);
+ }('a', 'b', 'c'));
+
+ Assert.areSame(3, calls);
+ },
+
testReduce: function () {
var obj = {};
@@ -121,6 +136,19 @@ suite.add(new Y.Test.Case({
Assert.areSame(1, calls);
},
+ 'reduce() should work on array-like objects': function () {
+ var calls = 0;
+
+ (function () {
+ Y.Array.reduce(arguments, true, function () {
+ calls += 1;
+ return true;
+ });
+ }('a', 'b', 'c'));
+
+ Assert.areSame(3, calls);
+ },
+
testFind: function () {
var data = this.data;
var result = A.find(data, function (item) {
@@ -208,6 +236,21 @@ suite.add(new Y.Test.Case({
Assert.areSame(1, calls);
},
+ 'filter() should work on array-like objects': function () {
+ var calls = 0;
+
+ (function () {
+ var results = Y.Array.filter(arguments, function (value) {
+ calls += 1;
+ return value === 'a';
+ });
+
+ Y.ArrayAssert.itemsAreSame(['a'], results);
+ }('a', 'b', 'c'));
+
+ Assert.areSame(3, calls);
+ },
+
testReject: function () {
var data = this.data;
var result = A.reject(data, function (item) {
@@ -293,6 +336,21 @@ suite.add(new Y.Test.Case({
Assert.areSame(1, calls);
},
+ 'every() should work on array-like objects': function () {
+ var calls = 0;
+
+ (function () {
+ var result = Y.Array.every(arguments, function (value) {
+ calls += 1;
+ return value === 'a';
+ });
+
+ Assert.isFalse(result);
+ }('a', 'b', 'c'));
+
+ Assert.areSame(2, calls);
+ },
+
testUnique: function() {
var obj = {};
@@ -52,6 +52,12 @@ suite.add(new Y.Test.Case({
Y.ArrayAssert.itemsAreSame(['foo', 'bar', 'baz'], Y.Array.dedupe(array));
},
+ 'dedupe() should work on array-like objects': function () {
+ (function () {
+ Y.ArrayAssert.itemsAreSame(['a', 'b', 'c'], Y.Array.dedupe(arguments));
+ }('a', 'a', 'b', 'c'));
+ },
+
testEach: function () {
var calls = 0,
data = ['a', 'b', 'c', 'd'],
@@ -87,6 +93,18 @@ suite.add(new Y.Test.Case({
Assert.areSame(1, calls);
},
+ 'each() should work on array-like objects': function () {
+ var calls = 0;
+
+ (function () {
+ Y.Array.each(arguments, function () {
+ calls += 1;
+ });
+ }('a', 'b', 'c'));
+
+ Assert.areSame(3, calls);
+ },
+
testHash: function () {
Assert.isObject(Y.Array.hash(['a', 'b', 'c'], ['foo', 'bar']));
@@ -118,6 +136,12 @@ suite.add(new Y.Test.Case({
Y.Assert.isTrue(hash.bar);
},
+ 'hash() should work on array-like objects': function () {
+ (function () {
+ Y.ObjectAssert.areEqual({a: true, b: true, c: true}, Y.Array.hash(arguments));
+ }('a', 'b', 'c'));
+ },
+
testIndexOf: function () {
var data = ['a', 'b', 1, 0, false, null, 'a'];
@@ -151,7 +175,16 @@ suite.add(new Y.Test.Case({
var array = ['a', 'b'];
array[3] = undefined;
- Y.Assert.areSame(3, Y.Array.indexOf(array, undefined));
+ Assert.areSame(3, Y.Array.indexOf(array, undefined));
+ },
+
+ 'indexOf() should work on array-like objects': function () {
+ (function () {
+ Assert.areSame(0, Y.Array.indexOf(arguments, 'a'));
+ Assert.areSame(1, Y.Array.indexOf(arguments, 'b'));
+ Assert.areSame(2, Y.Array.indexOf(arguments, 'c'));
+ Assert.areSame(-1, Y.Array.indexOf(arguments, 'd'));
+ }('a', 'b', 'c'));
},
testNumericSort: function () {
@@ -199,6 +232,22 @@ suite.add(new Y.Test.Case({
Assert.areSame(1, calls);
},
+ 'some() should work on array-like objects': function () {
+ var calls = 0;
+
+ (function () {
+ Y.Array.some(arguments, function (value) {
+ calls += 1;
+
+ if (value === 'b') {
+ return true;
+ }
+ });
+ }('a', 'b', 'c'));
+
+ Assert.areSame(2, calls);
+ },
+
testTest: function () {
Y.Assert.areEqual(0, Y.Array.test(function(){})); // functions should fail
Y.Assert.areEqual(0, Y.Array.test('string'));

0 comments on commit cf20337

Please sign in to comment.