From 1a375daea249ee6a42a1ddbb288baded8953c74f Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Thu, 19 Mar 2009 16:22:37 -0400 Subject: [PATCH 1/2] Remove sniffing from `$A` by using `in` operator when accessing property of a nodelist. --- CHANGELOG | 2 ++ src/lang/array.js | 19 +++---------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 479781c..57cb79c 100644 --- a/CHANGELOG +++ b/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) diff --git a/src/lang/array.js b/src/lang/array.js index 7855ad6..62f5f4d 100644 --- a/src/lang/array.js +++ b/src/lang/array.js @@ -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. From c7a5d3480ede6cd8af98b9439cd2034ecd386df3 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Thu, 19 Mar 2009 16:47:07 -0400 Subject: [PATCH 2/2] Make sure try/catch/finally is used instead of try/finally [#421 state:resolved] --- CHANGELOG | 4 +++- src/lang/periodical_executer.js | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 57cb79c..dfe1afe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ -* . Use `in` operator when accessing property of a nodelist to prevent Safari <=2.0.4 from crashing (kangax) +* Make sure try/catch/finally is used instead of try/finally for clients without support for the latter one (e.g. Blackberry, IE) (Ville Koskinen, kangax) + +* 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) diff --git a/src/lang/periodical_executer.js b/src/lang/periodical_executer.js index 266f324..c0584fb 100644 --- a/src/lang/periodical_executer.js +++ b/src/lang/periodical_executer.js @@ -52,9 +52,12 @@ var PeriodicalExecuter = Class.create({ try { this.currentlyExecuting = true; this.execute(); - } finally { + } catch(e) { + /* empty catch for clients that don't support try/finally */ + } + finally { this.currentlyExecuting = false; } } } -}); +}); \ No newline at end of file