From 5a37860ffbf97559c75694db3793de30a7370c0b Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Thu, 20 Dec 2007 15:47:32 +0000 Subject: [PATCH] prototype: Ensure creates an empty array when its argument's length is undefined. Closes #10574 --- CHANGELOG | 3 +++ src/array.js | 4 ++-- test/unit/array.html | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) 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(){