prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.54k stars 640 forks source link

Exception in stopObservingElement in IE8 #198

Open jwestbrook opened 10 years ago

jwestbrook commented 10 years ago

previous lighthouse ticket #1329 by Victor


stopObservingElement() raises exception 'responder is null or not an object' in IE8:

 function stopObservingElement(element) {
    var registry = getRegistryForElement(element); // creates empty registry {element: element}
    destroyRegistryForElement(element);

    var entries, i;
    for (var eventName in registry) { // property `element` is enumerated
      entries = registry[eventName];  // entries = registry['element'] == e.g. HTMLCommentElement
      i = entries.length;             // element has non-zero length
      while (i--)
        removeEvent(element, eventName, entries[i].responder); // error: entries[i] is undefined!
    }
  }
  1. I am invoking Element#update(), it collects child elements (and comments in IE!) and calls purgeElement() for each element.
  2. Then purgeElement() calls stopObservingElement() for comment element.
  3. Prototype unnecessarily creates new registry (here may be performance improvement for all browsers) with {element: element}, property element of registry is successfully enumerated in for ... in loop, and comment element has non-zero length property, but indexed access returns undefined.

Resume:

  1. There is no need to create new empty registry and create for loop when element has no registry.
  2. There should be some additional checks for element in for loop.
savetheclocktower commented 9 years ago

Marking as bug, but I have yet to investigate this one.