From a6984e692be9a9803312965e58ee103e72e598fd Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Sun, 11 Mar 2007 13:42:40 +0000 Subject: [PATCH] Prevent a crash in Safari when using $A() on NodeList objects that contain text nodes. [Thomas Fuchs] --- CHANGELOG | 2 ++ src/array.js | 15 +++++++++++++++ test/unit/array.html | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 8453bca..ee22d37 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/src/array.js b/src/array.js index e3dd30e..feb592f 100644 --- a/src/array.js +++ b/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) diff --git a/test/unit/array.html b/test/unit/array.html index 171c9d2..56d8560 100644 --- a/test/unit/array.html +++ b/test/unit/array.html @@ -23,6 +23,8 @@
+
22
+