prototype: Ensure creates an empty array when its argument's length is undefined. Closes #10574

This commit is contained in:
Tobie Langel 2007-12-20 15:47:32 +00:00
parent 23f7cb642c
commit 5a37860ffb
3 changed files with 8 additions and 2 deletions

View File

@ -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]

View File

@ -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;
}

View File

@ -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(){