Skip to content

Commit

Permalink
Remove sniffing from $A by using in operator when accessing prope…
Browse files Browse the repository at this point in the history
…rty of a nodelist.
  • Loading branch information
Juriy Zaytsev committed Mar 19, 2009
1 parent 4fefe32 commit 1a375da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* . Use `in` operator when accessing property of a nodelist to prevent Safari <=2.0.4 from crashing (kangax)

* Add Element#clone as a safe wrapper of native `cloneNode`. (Andrew Dupont, kangax)

* Add tests to ensure IE8 properly assigns a class name in the `Element` constructor. [#529 state:resolved] (Riki Fridrich, Andrew Dupont)
Expand Down
19 changes: 3 additions & 16 deletions src/lang/array.js
Expand Up @@ -8,27 +8,14 @@
**/
function $A(iterable) {
if (!iterable) return [];
if (iterable.toArray) return iterable.toArray();
// Safari <2.0.4 crashes when accessing property of a node list with property accessor.
// It nevertheless works fine with `in` operator, which is why we use it here
if ('toArray' in iterable) return iterable.toArray();
var length = iterable.length || 0, results = new Array(length);
while (length--) results[length] = iterable[length];
return results;
}

if (Prototype.Browser.WebKit) {
$A = function(iterable) {
if (!iterable) return [];
// In Safari, only use the `toArray` method if it's not a NodeList.
// A NodeList is a function, has an function `item` property, and a numeric
// `length` property. Adapted from Google Doctype.
if (!(typeof iterable === 'function' && typeof iterable.length ===
'number' && typeof iterable.item === 'function') && iterable.toArray)
return iterable.toArray();
var length = iterable.length || 0, results = new Array(length);
while (length--) results[length] = iterable[length];
return results;
};
}

/** section: Language, related to: Array
* $w(string) -> Array
* - string (String): A string with zero or more spaces.
Expand Down

0 comments on commit 1a375da

Please sign in to comment.