Bug 118286 - is/toHTMLStyleElement should use Element* for its argument
Summary: is/toHTMLStyleElement should use Element* for its argument
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kangil Han
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-02 01:32 PDT by Kangil Han
Modified: 2013-07-02 06:48 PDT (History)
7 users (show)

See Also:


Attachments
Patch (7.04 KB, patch)
2013-07-02 01:35 PDT, Kangil Han
no flags Details | Formatted Diff | Diff
Patch (7.22 KB, patch)
2013-07-02 05:04 PDT, Kangil Han
no flags Details | Formatted Diff | Diff
Patch (7.24 KB, patch)
2013-07-02 05:29 PDT, Kangil Han
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kangil Han 2013-07-02 01:32:13 PDT
is/toHTMLStyleElement should use Element* for its argument
Comment 1 Kangil Han 2013-07-02 01:35:14 PDT
Created attachment 205878 [details]
Patch
Comment 2 Kangil Han 2013-07-02 01:37:55 PDT
I would prefer gradual change of argument not to break bot. :)
Comment 3 Kangil Han 2013-07-02 01:42:32 PDT
For the record, this is a follow up patch for https://bugs.webkit.org/show_bug.cgi?id=118235#c2
Comment 4 Andreas Kling 2013-07-02 04:22:32 PDT
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.
Comment 5 Kangil Han 2013-07-02 05:04:17 PDT
Created attachment 205893 [details]
Patch
Comment 6 Kangil Han 2013-07-02 05:05:46 PDT
(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 7 Andreas Kling 2013-07-02 05:10:06 PDT
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++;
}
Comment 8 Kangil Han 2013-07-02 05:18:49 PDT
(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! :)
Comment 9 Kangil Han 2013-07-02 05:29:48 PDT
Created attachment 205896 [details]
Patch
Comment 10 Kangil Han 2013-07-02 05:31:45 PDT
(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 11 WebKit Commit Bot 2013-07-02 06:48:56 PDT
Comment on attachment 205896 [details]
Patch

Clearing flags on attachment: 205896

Committed r152290: <http://trac.webkit.org/changeset/152290>
Comment 12 WebKit Commit Bot 2013-07-02 06:48:58 PDT
All reviewed patches have been landed.  Closing bug.