Prevent a crash in Safari when using $A() on NodeList objects that contain text nodes. [Thomas Fuchs]
This commit is contained in:
parent
881b7dc00f
commit
a6984e692b
@ -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)
|
||||
|
15
src/array.js
15
src/array.js
@ -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)
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user