Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10150 (closed defect: fixed)

Opened 6 months ago

Last modified 5 days ago

[PATCH] [TEST] Element#descendantOf(element, document) throws error in IE

Reported by: splintor Assigned to: kangax
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: normal Keywords: descendantOf ancestor document IE
Cc:

Description

Since it is not mentioned anywhere that the ancestor cannot be document, I thought it would be OK to simply check if the element is a descendant of a frame's document. This used to work in Prototype 1.5.x, but not in Prototype 1.6, where the Element.descendantOf method was improved.

In any case, the new code of Element.descendantOf looks strange:

      if (!nextAncestor) {
        do { ancestor = ancestor.parentNode; }
        while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);
      }

nextAncestor is initialized ancestor.nextSibling, but if it is not defined, or null ("if (!nextAncestor)"), ancestor is assigned to "ancestor.parentNode" (which, as we recall, is undefined/null) in a loop, where the loop condition checks ancestor.nextSibling. However, the check is first done after the next execution, which is too late, since ancestor was already assigned to null/undefined.

An obvious simply workaround is to call Element.descendantOf(document.body) which solves the problem in most of the cases, but there is still a problem.

Attachments

descendantOf_document_patch_test.diff (1.2 kB) - added by kangax on 03/28/08 01:57:56.

Change History

11/13/07 09:10:32 changed by splintor

OK, I missed the difference between nextSibling and parentNode. So the code is not that strange. It seems that the do...while loop is problematic in case ancestor is document, since then, ancestor.parentNode is null, and the loop condition, that assumes ancestor is not null, fails.

11/18/07 21:51:30 changed by david

  • milestone changed from 2.0 to 2.x.

03/28/08 01:57:56 changed by kangax

  • attachment descendantOf_document_patch_test.diff added.

03/28/08 01:59:00 changed by kangax

  • owner changed from sam to kangax.
  • summary changed from Element.descendantOf(document) causes an Object Required exception in Internet Explorer to [PATCH] [TEST] Element#descendantOf(element, document) throws error in IE.

05/07/08 19:15:12 changed by jdalton

  • status changed from new to closed.
  • resolution set to fixed.