RESOLVED FIXED 144822
Element Traversal is not just Elements anymore
https://bugs.webkit.org/show_bug.cgi?id=144822
Summary Element Traversal is not just Elements anymore
Sam Weinig
Reported 2015-05-08 18:03:46 PDT
Element Traversal is not just Elements anymore
Attachments
Patch (20.99 KB, patch)
2015-05-08 18:09 PDT, Sam Weinig
simon.fraser: review+
Sam Weinig
Comment 1 2015-05-08 18:09:22 PDT
Sam Weinig
Comment 2 2015-05-08 18:15:37 PDT
Darin Adler
Comment 3 2015-05-08 19:51:00 PDT
Comment on attachment 252760 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252760&action=review > Source/WebCore/dom/CharacterData.idl:44 > + // From the NonDocumentTypeChildNode interface - https://dom.spec.whatwg.org/#nondocumenttypechildnode > + // FIXME: Move this to a seperate NonDocumentTypeChildNode IDL file when one exists. > + readonly attribute Element previousElementSibling; > + readonly attribute Element nextElementSibling; Is there a reason not to put these in Node.idl instead? There’s a misspelling in all these comments, by the way, separate with an e instead of an a. > Source/WebCore/dom/ContainerNode.cpp:916 > + ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this)); Why do we need to assert this? > Source/WebCore/dom/ContainerNode.cpp:923 > + ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this)); Why do we need to assert this? > Source/WebCore/dom/ContainerNode.cpp:930 > + ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this)); Why do we need to assert this? > Source/WebCore/dom/ContainerNode.cpp:937 > + Node* n = firstChild(); > + while (n) { > + count += n->isElementNode(); > + n = n->nextSibling(); > + } Since you moved this, how about a for loop instead of a while loop? > Source/WebCore/dom/Node.cpp:435 > + ASSERT(is<CharacterData>(*this) || is<Element>(*this)); Why do we need to assert this? > Source/WebCore/dom/Node.cpp:442 > + ASSERT(is<CharacterData>(*this) || is<Element>(*this)); Why do we need to assert this?
Andreas Kling
Comment 4 2015-05-08 19:57:08 PDT
Chris Dumez
Comment 5 2015-05-08 21:36:02 PDT
Comment on attachment 252760 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252760&action=review >> Source/WebCore/dom/CharacterData.idl:44 >> + readonly attribute Element nextElementSibling; > > Is there a reason not to put these in Node.idl instead? > > There’s a misspelling in all these comments, by the way, separate with an e instead of an a. Based on the name, these should not be exposed on Document so having them in Node.idl would cause this. However, I don't understand why we don't create this new NonDocumentTypeChildNode interface. I believe I added support for implements idl statements to our Bindings generator iirc so it should be trivial and it would avoid the IDL code duplication.
Chris Dumez
Comment 6 2015-05-08 21:43:37 PDT
Comment on attachment 252760 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252760&action=review >> Source/WebCore/dom/ContainerNode.cpp:937 >> + } > > Since you moved this, how about a for loop instead of a while loop? for (auto& element : childrenOfType<Element>(*this)) ++count;
Chris Dumez
Comment 7 2015-05-08 21:52:00 PDT
Comment on attachment 252760 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252760&action=review > Source/WebCore/dom/Element.idl:130 > + // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode We already have ChildNode.idl, we should definitely add ParentNode.idl and avoid the IDL duplication.
Alexey Proskuryakov
Comment 8 2015-05-08 22:38:04 PDT
> This broke js/dom/dom-static-property-for-in-iteration.html in a mostly harmless looking way: And EWS would have told you that. Landed new results in r184036. Please consider addressing comments from Darin and Chris though.
Chris Dumez
Comment 9 2015-05-08 22:57:48 PDT
Comment on attachment 252760 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252760&action=review >>> Source/WebCore/dom/CharacterData.idl:44 >>> + readonly attribute Element nextElementSibling; >> >> Is there a reason not to put these in Node.idl instead? >> >> There’s a misspelling in all these comments, by the way, separate with an e instead of an a. > > Based on the name, these should not be exposed on Document so having them in Node.idl would cause this. However, I don't understand why we don't create this new NonDocumentTypeChildNode interface. I believe I added support for implements idl statements to our Bindings generator iirc so it should be trivial and it would avoid the IDL code duplication. I'll do the split in https://bugs.webkit.org/show_bug.cgi?id=144825. >> Source/WebCore/dom/Element.idl:130 >> + // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode > > We already have ChildNode.idl, we should definitely add ParentNode.idl and avoid the IDL duplication. I'll do the split in https://bugs.webkit.org/show_bug.cgi?id=144825.
Sam Weinig
Comment 10 2015-05-09 15:02:33 PDT
(In reply to comment #3) > Comment on attachment 252760 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=252760&action=review > > > Source/WebCore/dom/CharacterData.idl:44 > > + // From the NonDocumentTypeChildNode interface - https://dom.spec.whatwg.org/#nondocumenttypechildnode > > + // FIXME: Move this to a seperate NonDocumentTypeChildNode IDL file when one exists. > > + readonly attribute Element previousElementSibling; > > + readonly attribute Element nextElementSibling; > > Is there a reason not to put these in Node.idl instead? They should not be exposed on all Nodes as per the DOM spec. > > There’s a misspelling in all these comments, by the way, separate with an e > instead of an a. > > > Source/WebCore/dom/ContainerNode.cpp:916 > > + ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this)); > > Why do we need to assert this? > > > Source/WebCore/dom/ContainerNode.cpp:923 > > + ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this)); > > Why do we need to assert this? Since these functions are really only for exposing to the web (internally, we use our own traversal and iteration functions, these assert the intent of what type of Nodes these should be exposed on. Another way to do this, which I might do at some point, is to add new classes that represent the ParentNode and NonDocumentTypeChildNode interfaces and use inheritance to enforce this. > > > Source/WebCore/dom/ContainerNode.cpp:937 > > + Node* n = firstChild(); > > + while (n) { > > + count += n->isElementNode(); > > + n = n->nextSibling(); > > + } > > Since you moved this, how about a for loop instead of a while loop? Seems like a good idea. Or use our modern iterators.
Note You need to log in before you can comment on or make changes to this bug.