Bug 91334 - REGRESSION(r122660): Cannot iterate over HTMLCollection that contains non-child descendent nodes in some conditions
Summary: REGRESSION(r122660): Cannot iterate over HTMLCollection that contains non-chi...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords:
Depends on: 91306
Blocks: 91335
  Show dependency treegraph
 
Reported: 2012-07-14 22:07 PDT by Ryosuke Niwa
Modified: 2012-07-18 14:31 PDT (History)
5 users (show)

See Also:


Attachments
Patch (4.88 KB, patch)
2012-07-14 22:17 PDT, Ryosuke Niwa
ojan: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2012-07-14 22:07:09 PDT
REGRESSION(r122660): Cannot iterate over HTMLCollection that contains non-child descendent nodes in some conditions
Comment 1 Ryosuke Niwa 2012-07-14 22:17:55 PDT
Created attachment 152449 [details]
Patch
Comment 2 Ryosuke Niwa 2012-07-14 22:19:39 PDT
My attempt to unify HTMLCollection & DynamicNodeList revealed a regression.
Comment 3 Ojan Vafai 2012-07-15 09:32:06 PDT
Comment on attachment 152449 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=152449&action=review

Please make the test actually assert that we're iterating in the right order before committing.

> Source/WebCore/ChangeLog:10
> +        which is visited traverseNextNode immeidatley before reaching the root node.

typo: immediately

> Source/WebCore/html/HTMLCollection.cpp:254
> +    node = node->lastChild();
> +    for (Node* current = node; current; current = current->lastChild())
> +        node = current;
> +    return node;

nit: i think this would be more readable as a while loop:
Node* node = 0;
while(Node* next = node->lastChild())
    node = next;
return node;

> LayoutTests/fast/dom/htmlcollection-backwards-subtree-iteration-expected.txt:1
> +Tests that HTMLCollection of a subtree (as supposed to direct children) can be iterated backwards.

s/supposed/opposed

> LayoutTests/fast/dom/htmlcollection-backwards-subtree-iteration.html:10
> +    images[0].class = 'foo';
> +    images[i - 1].class = 'foo';

Would be nice if you asserted that you're getting the image elements in the right order. You could put an ID on each one in order to verify it's location.
Comment 4 Ryosuke Niwa 2012-07-15 19:00:18 PDT
Comment on attachment 152449 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=152449&action=review

>> Source/WebCore/html/HTMLCollection.cpp:254
>> +    return node;
> 
> nit: i think this would be more readable as a while loop:
> Node* node = 0;
> while(Node* next = node->lastChild())
>     node = next;
> return node;

That'll just crash. Note that we need to return 0 when node->lastChild() is 0, not node.
Comment 5 Ryosuke Niwa 2012-07-15 19:26:08 PDT
Committed r122689: <http://trac.webkit.org/changeset/122689>
Comment 6 Ojan Vafai 2012-07-18 14:18:44 PDT
(In reply to comment #4)
> (From update of attachment 152449 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=152449&action=review
> 
> >> Source/WebCore/html/HTMLCollection.cpp:254
> >> +    return node;
> > 
> > nit: i think this would be more readable as a while loop:
> > Node* node = 0;
> > while(Node* next = node->lastChild())
> >     node = next;
> > return node;
> 
> That'll just crash. Note that we need to return 0 when node->lastChild() is 0, not node.

Isn't that what this code does? I don't see where the crash is.
Comment 7 Ryosuke Niwa 2012-07-18 14:20:26 PDT
(In reply to comment #6)
> (In reply to comment #4)
> > (From update of attachment 152449 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=152449&action=review
> > 
> > >> Source/WebCore/html/HTMLCollection.cpp:254
> > >> +    return node;
> > > 
> > > nit: i think this would be more readable as a while loop:
> > > Node* node = 0;
> > > while(Node* next = node->lastChild())
> > >     node = next;
> > > return node;
> > 
> > That'll just crash. Note that we need to return 0 when node->lastChild() is 0, not node.
> 
> Isn't that what this code does? I don't see where the crash is.

You're initializing node to 0. The first call to node->lastChild() will result in a null pointer access.
Comment 8 Ojan Vafai 2012-07-18 14:31:51 PDT
Comment on attachment 152449 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=152449&action=review

>>>>> Source/WebCore/html/HTMLCollection.cpp:254
>>>>> +    return node;
>>>> 
>>>> nit: i think this would be more readable as a while loop:
>>>> Node* node = 0;
>>>> while(Node* next = node->lastChild())
>>>>     node = next;
>>>> return node;
>>> 
>>> That'll just crash. Note that we need to return 0 when node->lastChild() is 0, not node.
>> 
>> Isn't that what this code does? I don't see where the crash is.
> 
> You're initializing node to 0. The first call to node->lastChild() will result in a null pointer access.

lol. whoops.