Prevent a crash in Safari when using $A() on NodeList objects that contain text nodes. [Thomas Fuchs]

This commit is contained in:
Thomas Fuchs 2007-03-11 13:42:40 +00:00
parent 881b7dc00f
commit a6984e692b
3 changed files with 35 additions and 0 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Prevent a crash in Safari when using $A() on NodeList objects that contain text nodes. [Thomas Fuchs]
* Fix Element.Methods.descendants() to properly extend elements on IE. [Thomas Fuchs]
*1.5.1_rc1* (March 9, 2007)

View File

@ -10,6 +10,21 @@ var $A = Array.from = function(iterable) {
}
}
if (Prototype.Browser.WebKit) {
$A = Array.from = function(iterable) {
if (!iterable) return [];
if (!(typeof iterable == 'function' && iterable == '[object NodeList]') &&
iterable.toArray) {
return iterable.toArray();
} else {
var results = [];
for (var i = 0, length = iterable.length; i < length; i++)
results.push(iterable[i]);
return results;
}
}
}
Object.extend(Array.prototype, Enumerable);
if (!Array.prototype._reverse)

View File

@ -23,6 +23,8 @@
<!-- Log output -->
<div id="testlog"> </div>
<div id="test_node">22<span id="span_1"></span><span id="span_2"></span></div>
<!-- Tests follow -->
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
@ -43,6 +45,22 @@
assertEnumEqual(['foo','bar'], globalArgsTest);
}},
testToArrayOnNodeList: function(){ with(this) {
// direct HTML
assertEqual(3, $A($('test_node').childNodes).length);
// DOM
var element = document.createElement('div');
element.appendChild(document.createTextNode('22'));
(2).times(function(){ element.appendChild(document.createElement('span')) });
assertEqual(3, $A(element.childNodes).length);
// HTML String
element = document.createElement('div');
$(element).update('22<span></span><span></span');
assertEqual(3, $A(element.childNodes).length);
}},
testClear: function(){ with(this) {
assertEnumEqual([], [].clear());
assertEnumEqual([], [1].clear());