Changeset 161115 in webkit


Ignore:
Timestamp:
Dec 28, 2013 5:36:19 PM (10 years ago)
Author:
akling@apple.com
Message:

Add an owning smart pointer for RenderObjects and start using it.
<https://webkit.org/b/126251>

This patch adds a RenderPtr pointer, essentially an OwnPtr for
RenderObjects. The difference is that RenderPtr destroys the object
by calling destroy() on it.

This is necessary to implement the willBeDestroyed() mechanism in
RenderObject that notifies renderers just before they are about to
be deleted, while they can still do tree traversal, etc.

I also added a make_unique-alike helper so you can write:

auto renderer = createRenderObject<RenderImage>(...);

Put it all to use by making ContentData::createRenderer() return
RenderPtr<RenderObject> instead of raw RenderObject*.

Reviewed by Antti Koivisto.

Location:
trunk/Source/WebCore
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r161113 r161115  
     12013-12-28  Andreas Kling  <akling@apple.com>
     2
     3        Add an owning smart pointer for RenderObjects and start using it.
     4        <https://webkit.org/b/126251>
     5
     6        This patch adds a RenderPtr pointer, essentially an OwnPtr for
     7        RenderObjects. The difference is that RenderPtr destroys the object
     8        by calling destroy() on it.
     9
     10        This is necessary to implement the willBeDestroyed() mechanism in
     11        RenderObject that notifies renderers just before they are about to
     12        be deleted, while they can still do tree traversal, etc.
     13
     14        I also added a make_unique-alike helper so you can write:
     15
     16            auto renderer = createRenderObject<RenderImage>(...);
     17
     18        Put it all to use by making ContentData::createRenderer() return
     19        RenderPtr<RenderObject> instead of raw RenderObject*.
     20
     21        Reviewed by Antti Koivisto.
     22
    1232013-12-28  Benjamin Poulain  <benjamin@webkit.org>
    224
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r161106 r161115  
    1098110981                ADDF1AD41257CD9A0003A759 /* RenderSVGPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGPath.cpp; sourceTree = "<group>"; };
    1098210982                ADDF1AD51257CD9A0003A759 /* RenderSVGPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGPath.h; sourceTree = "<group>"; };
     10983                ADE16736181050C300463A2E /* RenderPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderPtr.h; sourceTree = "<group>"; };
    1098310984                B10B697D140C174000BC1C26 /* WebVTTToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebVTTToken.h; sourceTree = "<group>"; };
    1098410985                B10B697E140C174000BC1C26 /* WebVTTTokenizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebVTTTokenizer.cpp; sourceTree = "<group>"; };
     
    2132521326                                A43BF59A1149292800C643CA /* RenderProgress.cpp */,
    2132621327                                A43BF59B1149292800C643CA /* RenderProgress.h */,
     21328                                ADE16736181050C300463A2E /* RenderPtr.h */,
    2132721329                                5A574F22131DB93900471B88 /* RenderQuote.cpp */,
    2132821330                                5A574F23131DB93900471B88 /* RenderQuote.h */,
  • trunk/Source/WebCore/dom/PseudoElement.cpp

    r159989 r161115  
    8484        return;
    8585
    86     RenderStyle& style = renderer->style();
     86    const RenderStyle& style = renderer->style();
    8787    ASSERT(style.contentData());
    8888
    8989    for (const ContentData* content = style.contentData(); content; content = content->next()) {
    90         RenderObject* child = content->createRenderer(document(), style);
     90        RenderPtr<RenderObject> child = content->createRenderer(document(), style);
    9191        if (renderer->isChildAllowed(*child, style)) {
    92             renderer->addChild(child);
    93             if (child->isQuote())
    94                 toRenderQuote(child)->attachQuote();
    95         } else
    96             child->destroy();
     92            auto* childPtr = child.get();
     93            renderer->addChild(child.leakPtr());
     94            if (childPtr->isQuote())
     95                toRenderQuote(childPtr)->attachQuote();
     96        }
    9797    }
    9898}
  • trunk/Source/WebCore/rendering/style/ContentData.cpp

    r159989 r161115  
    4848}
    4949
    50 RenderObject* ImageContentData::createRenderer(Document& document, RenderStyle& pseudoStyle) const
     50RenderPtr<RenderObject> ImageContentData::createRenderer(Document& document, const RenderStyle& pseudoStyle) const
    5151{
    52     RenderImage* image = new RenderImage(document, RenderImage::createStyleInheritingFromPseudoStyle(pseudoStyle));
     52    auto image = createRenderObject<RenderImage>(document, RenderImage::createStyleInheritingFromPseudoStyle(pseudoStyle));
    5353    image->initializeStyle();
    5454    image->setAltText(altText());
     
    5757    else
    5858        image->setImageResource(RenderImageResource::create());
    59     return image;
     59    return std::move(image);
    6060}
    6161
    62 RenderObject* TextContentData::createRenderer(Document& document, RenderStyle&) const
     62RenderPtr<RenderObject> TextContentData::createRenderer(Document& document, const RenderStyle&) const
    6363{
    64     RenderTextFragment* fragment = new RenderTextFragment(document, m_text);
     64    auto fragment = createRenderObject<RenderTextFragment>(document, m_text);
    6565    fragment->setAltText(altText());
    66     return fragment;
     66    return std::move(fragment);
    6767}
    6868
    69 RenderObject* CounterContentData::createRenderer(Document& document, RenderStyle&) const
     69RenderPtr<RenderObject> CounterContentData::createRenderer(Document& document, const RenderStyle&) const
    7070{
    71     return new RenderCounter(document, *m_counter);
     71    return createRenderObject<RenderCounter>(document, *m_counter);
    7272}
    7373
    74 RenderObject* QuoteContentData::createRenderer(Document& document, RenderStyle&) const
     74RenderPtr<RenderObject> QuoteContentData::createRenderer(Document& document, const RenderStyle&) const
    7575{
    76     return new RenderQuote(document, m_quote);
     76    return createRenderObject<RenderQuote>(document, m_quote);
    7777}
    7878
  • trunk/Source/WebCore/rendering/style/ContentData.h

    r159591 r161115  
    2828#include "CounterContent.h"
    2929#include "StyleImage.h"
     30#include "RenderPtr.h"
    3031#include <wtf/OwnPtr.h>
    3132
     
    4647    virtual bool isText() const { return false; }
    4748
    48     virtual RenderObject* createRenderer(Document&, RenderStyle&) const = 0;
     49    virtual RenderPtr<RenderObject> createRenderer(Document&, const RenderStyle&) const = 0;
    4950
    5051    std::unique_ptr<ContentData> clone() const;
     
    7778
    7879    virtual bool isImage() const OVERRIDE { return true; }
    79     virtual RenderObject* createRenderer(Document&, RenderStyle&) const OVERRIDE;
     80    virtual RenderPtr<RenderObject> createRenderer(Document&, const RenderStyle&) const OVERRIDE;
    8081
    8182    virtual bool equals(const ContentData& data) const OVERRIDE
     
    108109
    109110    virtual bool isText() const OVERRIDE { return true; }
    110     virtual RenderObject* createRenderer(Document&, RenderStyle&) const OVERRIDE;
     111    virtual RenderPtr<RenderObject> createRenderer(Document&, const RenderStyle&) const OVERRIDE;
    111112
    112113    virtual bool equals(const ContentData& data) const OVERRIDE
     
    134135
    135136    virtual bool isCounter() const OVERRIDE { return true; }
    136     virtual RenderObject* createRenderer(Document&, RenderStyle&) const OVERRIDE;
     137    virtual RenderPtr<RenderObject> createRenderer(Document&, const RenderStyle&) const OVERRIDE;
    137138
    138139private:
     
    164165
    165166    virtual bool isQuote() const OVERRIDE { return true; }
    166     virtual RenderObject* createRenderer(Document&, RenderStyle&) const OVERRIDE;
     167    virtual RenderPtr<RenderObject> createRenderer(Document&, const RenderStyle&) const OVERRIDE;
    167168
    168169    virtual bool equals(const ContentData& data) const OVERRIDE
Note: See TracChangeset for help on using the changeset viewer.