From 682a55c2d3c00053c098ca3483123c44fb6eee7f Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sat, 28 Feb 2009 04:47:48 -0600 Subject: [PATCH] Make sure `_extendedByPrototype`, `_countedByPrototype`, and `prototypeUID` node expandos are accessed with `typeof` to prevent errors in some environments. [#354 state:resolved] (Hilberty, kangax, Andrew Dupont) --- CHANGELOG | 2 ++ src/dom/dom.js | 6 ++++-- src/dom/selector.js | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 95fb238..b2bfd82 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Make sure `_extendedByPrototype`, `_countedByPrototype`, and `prototypeUID` node expandos are accessed with `typeof` to prevent errors in some environments. [#354 state:resolved] (Hilberty, kangax, Andrew Dupont) + * Fix issue where Opera 9.x returns incorrect results on certain Selector queries with descendant combinators. [#395 state:resolved] (Arpan, fearphage, kangax, Andrew Dupont) * Null out references to elements in cache on page unload. Need this in addition to the Event#stopObserving calls to clean up memory leaks. [#425 state:resolved] (ykphuah, mr_justin, Andrew Dupont) diff --git a/src/dom/dom.js b/src/dom/dom.js index 129d794..0b15981 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -1508,7 +1508,9 @@ Element.extend = (function() { var Methods = { }, ByTag = Element.Methods.ByTag; var extend = Object.extend(function(element) { - if (!element || element._extendedByPrototype || + // need to use actual `typeof` operator + // to prevent errors in some environments (when accessing node expandos) + if (!element || typeof element._extendedByPrototype != 'undefined' || element.nodeType != 1 || element == window) return element; var methods = Object.clone(Methods), @@ -1735,7 +1737,7 @@ Element.addMethods({ if (element === window) { uid = 0; } else { - if (Object.isUndefined(element._prototypeUID)) + if (typeof element._prototypeUID === "undefined") element._prototypeUID = [Element.Storage.UID++]; uid = element._prototypeUID[0]; } diff --git a/src/dom/selector.js b/src/dom/selector.js index 0e3e486..b37e539 100644 --- a/src/dom/selector.js +++ b/src/dom/selector.js @@ -439,7 +439,8 @@ Object.extend(Selector, { if (nodes.length == 0) return nodes; var results = [], n; for (var i = 0, l = nodes.length; i < l; i++) - if (!(n = nodes[i])._countedByPrototype) { + // use `typeof` operator to prevent errors + if (typeof (n = nodes[i])._countedByPrototype == 'undefined') { n._countedByPrototype = Prototype.emptyFunction; results.push(Element.extend(n)); }