Bug 59461
| Summary: | WebKitDOMNodeList's internal order is modified when iterating it | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Xavier Claessens <xclaesse> |
| Component: | WebKitGTK | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED INVALID | ||
| Severity: | Normal | CC: | sam, xan.lopez |
| Priority: | P2 | ||
| Version: | 528+ (Nightly build) | ||
| Hardware: | PC | ||
| OS: | Linux | ||
Xavier Claessens
I have an issue when trying to implement adium theme "focus" feature in Empathy[1]
My code needs to list all nodes having "focus" in its classes, like <div class="foo focus bar"> and then remove focus from the list. So basically like this:
dom = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
nodes = webkit_dom_document_get_elements_by_class_name (dom, "focus");
for (i = 0; i < webkit_dom_node_list_get_length (nodes); i++) {
webkit_dom_html_element_set_class_name (element, new_class_name);
}
This problem with that code is that it will update only one node op 2. My guess is that when a node is modified, it gets moved to the end of the nodes list. This seems really weird behaviour... Note that adium does exactly the same code using the MacOS objective-C API of webkit and it works as expected.
[1] https://bugzilla.gnome.org/show_bug.cgi?id=443884
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Xavier Claessens
oohh, actually the is a small difference in adium's code, it uses querySelectorAll. And that actually work with gtk API too, like that:
nodes = webkit_dom_document_query_selector_all (dom, ".focus", NULL);
This is really confusing...
Sam Weinig
This is how NodeLists work in the DOM. The ones returned from getElementsByClassName are live (http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyclassname) (meaning they update due to DOM modifications) while the ones returned from querySelectorAll (http://www.w3.org/TR/selectors-api/#queryselectorall) are static.
Xavier Claessens
Is that documented in the API? Feel free to close as INVALID then.
Xan Lopez
As Sam suggests, we just do whatever the underlying DOM implementation does, so we should be faithful to the spec here. Closing!