Summary: | is/toHTMLStyleElement should use Element* for its argument | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Kangil Han <kangil.han> | ||||||||
Component: | WebCore Misc. | Assignee: | Kangil Han <kangil.han> | ||||||||
Status: | RESOLVED FIXED | ||||||||||
Severity: | Normal | CC: | commit-queue, esprehn+autocc, glenn, kling, koivisto, macpherson, menard | ||||||||
Priority: | P2 | ||||||||||
Version: | 528+ (Nightly build) | ||||||||||
Hardware: | Unspecified | ||||||||||
OS: | Unspecified | ||||||||||
Attachments: |
|
Description
Kangil Han
2013-07-02 01:32:13 PDT
Created attachment 205878 [details]
Patch
I would prefer gradual change of argument not to break bot. :) For the record, this is a follow up patch for https://bugs.webkit.org/show_bug.cgi?id=118235#c2 Comment on attachment 205878 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=205878&action=review > Source/WebCore/css/CSSStyleSheet.cpp:68 > - || isHTMLStyleElement(parentNode) > + || isHTMLStyleElement(toElement(parentNode)) Are we sure that 'parentNode' is always an Element at this point? > Source/WebCore/dom/Node.cpp:2536 > for (Node* child = firstChild(); child; child = child->nextSibling()) { > - if (isHTMLStyleElement(child) && toHTMLStyleElement(child)->isRegisteredAsScoped()) > + if (isHTMLStyleElement(toElement(child)) && toHTMLStyleElement(toElement(child))->isRegisteredAsScoped()) > count++; > } This looks wrong; you're calling toElement() on every child node, wouldn't this assert? Maybe we could rewrite this loop using ElementTraversal instead? Then you wouldn't need to worry about Nodes at all. Created attachment 205893 [details]
Patch
(In reply to comment #4) > > Source/WebCore/css/CSSStyleSheet.cpp:68 > > - || isHTMLStyleElement(parentNode) > > + || isHTMLStyleElement(toElement(parentNode)) > > Are we sure that 'parentNode' is always an Element at this point? > Done. > > Source/WebCore/dom/Node.cpp:2536 > > for (Node* child = firstChild(); child; child = child->nextSibling()) { > > - if (isHTMLStyleElement(child) && toHTMLStyleElement(child)->isRegisteredAsScoped()) > > + if (isHTMLStyleElement(toElement(child)) && toHTMLStyleElement(toElement(child))->isRegisteredAsScoped()) > > count++; > > } > > This looks wrong; you're calling toElement() on every child node, wouldn't this assert? > Maybe we could rewrite this loop using ElementTraversal instead? Then you wouldn't need to worry about Nodes at all. Done. Thx! :) Comment on attachment 205893 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=205893&action=review r=me, but... > Source/WebCore/dom/Node.cpp:2539 > for (Node* child = firstChild(); child; child = child->nextSibling()) { > - if (isHTMLStyleElement(child) && toHTMLStyleElement(child)->isRegisteredAsScoped()) > - count++; > + if (child->isElementNode()) { > + Element* element = toElement(child); > + if (isHTMLStyleElement(element) && toHTMLStyleElement(element)->isRegisteredAsScoped()) > + count++; > + } > } You can simplify this loop by using ElementTraversal: for (Element* element = ElementTraversal::firstWithin(this); element; element = ElementTraversal::next(element, this)) { if (isHTMLStyleElement(element) && toHTMLStyleElement(element)->isRegisteredAsScoped()) count++; } (In reply to comment #7) > > Source/WebCore/dom/Node.cpp:2539 > > for (Node* child = firstChild(); child; child = child->nextSibling()) { > > - if (isHTMLStyleElement(child) && toHTMLStyleElement(child)->isRegisteredAsScoped()) > > - count++; > > + if (child->isElementNode()) { > > + Element* element = toElement(child); > > + if (isHTMLStyleElement(element) && toHTMLStyleElement(element)->isRegisteredAsScoped()) > > + count++; > > + } > > } > > You can simplify this loop by using ElementTraversal: > > for (Element* element = ElementTraversal::firstWithin(this); element; element = ElementTraversal::next(element, this)) { > if (isHTMLStyleElement(element) && toHTMLStyleElement(element)->isRegisteredAsScoped()) > count++; > } Cool! I will try this! :) Created attachment 205896 [details]
Patch
(In reply to comment #7) > You can simplify this loop by using ElementTraversal: > > for (Element* element = ElementTraversal::firstWithin(this); element; element = ElementTraversal::next(element, this)) { > if (isHTMLStyleElement(element) && toHTMLStyleElement(element)->isRegisteredAsScoped()) > count++; > } Done! :) Comment on attachment 205896 [details] Patch Clearing flags on attachment: 205896 Committed r152290: <http://trac.webkit.org/changeset/152290> All reviewed patches have been landed. Closing bug. |