diff --git a/CHANGELOG b/CHANGELOG index 9c67ac8..86a1cd6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ *SVN* + +* Ensure $A creates an empty array when its argument's length is undefined. Closes #10574. [henryju, Tobie Langel] + * Fix incorrect variable declaration in Event.fire. Closes #10329. [rubley] * Fix the way Selector handles [pseudoclass + combinator] with no space in between. Closes #9696. [kangax, fearphage, Andrew Dupont] diff --git a/src/array.js b/src/array.js index 245ad13..5bdabb3 100644 --- a/src/array.js +++ b/src/array.js @@ -1,7 +1,7 @@ function $A(iterable) { if (!iterable) return []; if (iterable.toArray) return iterable.toArray(); - var length = iterable.length, results = new Array(length); + var length = iterable.length || 0, results = new Array(length); while (length--) results[length] = iterable[length]; return results; } @@ -11,7 +11,7 @@ if (Prototype.Browser.WebKit) { if (!iterable) return []; if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') && iterable.toArray) return iterable.toArray(); - var length = iterable.length, results = new Array(length); + var length = iterable.length || 0, results = new Array(length); while (length--) results[length] = iterable[length]; return results; } diff --git a/test/unit/array.html b/test/unit/array.html index 95de657..3be5cff 100644 --- a/test/unit/array.html +++ b/test/unit/array.html @@ -32,6 +32,9 @@ var globalArgsTest = 'nothing to see here'; new Test.Unit.Runner({ + test$A: function(){ with(this) { + assertEnumEqual([], $A({})); + }}, testToArrayOnArguments: function(){ with(this) { function toArrayOnArguments(){