Bug 120248 - Element child and descendant iterators
Summary: Element child and descendant iterators
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-24 09:33 PDT by Antti Koivisto
Modified: 2013-08-25 14:30 PDT (History)
9 users (show)

See Also:


Attachments
maybe something along these lines (9.35 KB, patch)
2013-08-24 12:39 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
patch (31.80 KB, patch)
2013-08-25 11:48 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
another (31.88 KB, patch)
2013-08-25 11:51 PDT, Antti Koivisto
webkit-ews: commit-queue-
Details | Formatted Diff | Diff
yet another (36.26 KB, patch)
2013-08-25 13:56 PDT, Antti Koivisto
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Koivisto 2013-08-24 09:33:46 PDT
Better approach to iterating.
Comment 1 Antti Koivisto 2013-08-24 12:39:52 PDT
Created attachment 209551 [details]
maybe something along these lines
Comment 2 Andreas Kling 2013-08-24 12:50:13 PDT
Comment on attachment 209551 [details]
maybe something along these lines

I think this would be absolutely magical with C++11 range-based for loops.

I also think get() should return an Element& and we can have something like getPtr() for Element*. (This to encourage ourselves to use references.)
Comment 3 Darin Adler 2013-08-24 14:46:17 PDT
Will look nice in C++11 for loops.

When we use element pointers, it’s well defined what happens if the document changes while we are iterating. For iterators, we’d want to define what happens in that case. What our hash tables do with iterators is that in debug versions they invalidate iterators when changes are made to the underlying data structure. Maybe we could do some variation on that.
Comment 4 Darin Adler 2013-08-24 14:46:55 PDT
(In reply to comment #2)
> I also think get() should return an Element& and we can have something like getPtr() for Element*. (This to encourage ourselves to use references.)

C++ iterators normally use *iterator, not iterator.get().
Comment 5 Andreas Kling 2013-08-24 14:48:53 PDT
Comment on attachment 209551 [details]
maybe something along these lines

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

> Source/WebCore/dom/ElementTraversal.h:107
> +    bool operator!=(const ElementDescendantIterator& other) const { return m_current != other.m_current; }

This method could assert that both iterators have the same root.
Comment 6 Antti Koivisto 2013-08-24 23:43:49 PDT
(In reply to comment #3)
> Will look nice in C++11 for loops.
> 
> When we use element pointers, it’s well defined what happens if the document changes while we are iterating. For iterators, we’d want to define what happens in that case. What our hash tables do with iterators is that in debug versions they invalidate iterators when changes are made to the underlying data structure. Maybe we could do some variation on that.

Yeah. I think we should assert that there are no tree mutations during iteration. Not just in the current subtree, in the entire tree.
Comment 7 Darin Adler 2013-08-24 23:49:25 PDT
(In reply to comment #6)
> Yeah. I think we should assert that there are no tree mutations during iteration. Not just in the current subtree, in the entire tree.

Should probably go further and also assert that no DOM events were dispatched. An event handler could have mutated the tree; just because it didn’t actually happen does not mean the code is OK.
Comment 8 Antti Koivisto 2013-08-25 11:48:09 PDT
Created attachment 209595 [details]
patch
Comment 9 Antti Koivisto 2013-08-25 11:51:54 PDT
Created attachment 209596 [details]
another
Comment 10 Early Warning System Bot 2013-08-25 11:59:38 PDT
Comment on attachment 209596 [details]
another

Attachment 209596 [details] did not pass qt-ews (qt):
Output: http://webkit-queues.appspot.com/results/1564277
Comment 11 Early Warning System Bot 2013-08-25 12:01:53 PDT
Comment on attachment 209596 [details]
another

Attachment 209596 [details] did not pass qt-wk2-ews (qt-wk2):
Output: http://webkit-queues.appspot.com/results/1561584
Comment 12 EFL EWS Bot 2013-08-25 12:07:56 PDT
Comment on attachment 209596 [details]
another

Attachment 209596 [details] did not pass efl-wk2-ews (efl-wk2):
Output: http://webkit-queues.appspot.com/results/1544952
Comment 13 EFL EWS Bot 2013-08-25 12:14:15 PDT
Comment on attachment 209596 [details]
another

Attachment 209596 [details] did not pass efl-ews (efl):
Output: http://webkit-queues.appspot.com/results/1562424
Comment 14 kov's GTK+ EWS bot 2013-08-25 12:56:17 PDT
Comment on attachment 209596 [details]
another

Attachment 209596 [details] did not pass gtk-ews (gtk):
Output: http://webkit-queues.appspot.com/results/1564290
Comment 15 kov's GTK+ EWS bot 2013-08-25 13:35:16 PDT
Comment on attachment 209596 [details]
another

Attachment 209596 [details] did not pass gtk-ews (gtk):
Output: http://webkit-queues.appspot.com/results/1559658
Comment 16 Antti Koivisto 2013-08-25 13:56:06 PDT
Created attachment 209603 [details]
yet another
Comment 17 Sam Weinig 2013-08-25 14:00:49 PDT
Comment on attachment 209603 [details]
yet another

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

> Source/WebCore/WebCore.vcxproj/WebCore.vcxproj:-1
> -<?xml version="1.0" encoding="utf-8"?>

Removing this was probably a mistake.
Comment 18 Antti Koivisto 2013-08-25 14:30:37 PDT
https://trac.webkit.org/r154581