Title: [157698] trunk/Source/WebCore
Revision
157698
Author
[email protected]
Date
2013-10-20 03:49:10 -0700 (Sun, 20 Oct 2013)

Log Message

Use PassRef for constructing StyleRules.
<https://webkit.org/b/123072>

Let functions that return newly-constructed StyleRuleFoo objects
vend PassRef<StyleRuleFoo> instead of PassRefPtr.

Since StyleRuleBase::copy() has to return something, we can't rely
on ASSERT_NOT_REACHED() + return nullptr anymore, so I've replaced
those with CRASH(). No call sites actually handled null anyway.

Reviewed by Sam Weinig.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (157697 => 157698)


--- trunk/Source/WebCore/ChangeLog	2013-10-20 05:42:46 UTC (rev 157697)
+++ trunk/Source/WebCore/ChangeLog	2013-10-20 10:49:10 UTC (rev 157698)
@@ -1,3 +1,17 @@
+2013-10-19  Andreas Kling  <[email protected]>
+
+        Use PassRef for constructing StyleRules.
+        <https://webkit.org/b/123072>
+
+        Let functions that return newly-constructed StyleRuleFoo objects
+        vend PassRef<StyleRuleFoo> instead of PassRefPtr.
+
+        Since StyleRuleBase::copy() has to return something, we can't rely
+        on ASSERT_NOT_REACHED() + return nullptr anymore, so I've replaced
+        those with CRASH(). No call sites actually handled null anyway.
+
+        Reviewed by Sam Weinig.
+
 2013-10-19  Jer Noble  <[email protected]>
 
         Unreviewed roll out of r157695; broke Mac builds.

Modified: trunk/Source/WebCore/css/CSSGroupingRule.cpp (157697 => 157698)


--- trunk/Source/WebCore/css/CSSGroupingRule.cpp	2013-10-20 05:42:46 UTC (rev 157697)
+++ trunk/Source/WebCore/css/CSSGroupingRule.cpp	2013-10-20 10:49:10 UTC (rev 157698)
@@ -89,7 +89,7 @@
     }
     CSSStyleSheet::RuleMutationScope mutationScope(this);
 
-    m_groupRule->wrapperInsertRule(index, newRule);
+    m_groupRule->wrapperInsertRule(index, newRule.releaseNonNull());
 
     m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
     return index;

Modified: trunk/Source/WebCore/css/StyleRule.cpp (157697 => 157698)


--- trunk/Source/WebCore/css/StyleRule.cpp	2013-10-20 05:42:46 UTC (rev 157697)
+++ trunk/Source/WebCore/css/StyleRule.cpp	2013-10-20 10:49:10 UTC (rev 157698)
@@ -115,7 +115,7 @@
     ASSERT_NOT_REACHED();
 }
 
-PassRefPtr<StyleRuleBase> StyleRuleBase::copy() const
+PassRef<StyleRuleBase> StyleRuleBase::copy() const
 {
     switch (type()) {
     case Style:
@@ -134,10 +134,6 @@
     case Region:
         return static_cast<const StyleRuleRegion*>(this)->copy();
 #endif
-    case Import:
-        // FIXME: Copy import rules.
-        ASSERT_NOT_REACHED();
-        return 0;
     case Keyframes:
         return static_cast<const StyleRuleKeyframes*>(this)->copy();
 #if ENABLE(SHADOW_DOM)
@@ -152,17 +148,20 @@
     case Filter:
         return static_cast<const StyleRuleFilter*>(this)->copy();
 #endif
+    case Import:
+        // FIXME: Copy import rules.
+        break;
     case Unknown:
     case Charset:
     case Keyframe:
 #if !ENABLE(CSS_REGIONS)
     case Region:
 #endif
-        ASSERT_NOT_REACHED();
-        return 0;
+        break;
     }
-    ASSERT_NOT_REACHED();
-    return 0;
+    CRASH();
+    // HACK: EFL won't build without this (old GCC with crappy -Werror=return-type)
+    return PassRef<StyleRuleBase>(*static_cast<StyleRuleBase*>(nullptr));
 }
 
 PassRefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const
@@ -256,15 +255,15 @@
     return static_cast<MutableStylePropertySet&>(m_properties.get());
 }
 
-PassRefPtr<StyleRule> StyleRule::create(int sourceLine, const Vector<const CSSSelector*>& selectors, PassRef<StylePropertySet> properties)
+PassRef<StyleRule> StyleRule::create(int sourceLine, const Vector<const CSSSelector*>& selectors, PassRef<StylePropertySet> properties)
 {
     CSSSelector* selectorListArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * selectors.size()));
     for (unsigned i = 0; i < selectors.size(); ++i)
         new (NotNull, &selectorListArray[i]) CSSSelector(*selectors.at(i));
     selectorListArray[selectors.size() - 1].setLastInSelectorList();
-    RefPtr<StyleRule> rule = StyleRule::create(sourceLine, std::move(properties));
-    rule->parserAdoptSelectorArray(selectorListArray);
-    return rule.release();
+    auto rule = StyleRule::create(sourceLine, std::move(properties));
+    rule.get().parserAdoptSelectorArray(selectorListArray);
+    return rule;
 }
 
 Vector<RefPtr<StyleRule>> StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount(unsigned maxCount) const
@@ -348,15 +347,15 @@
 
 StyleRuleGroup::StyleRuleGroup(const StyleRuleGroup& o)
     : StyleRuleBase(o)
-    , m_childRules(o.m_childRules.size())
 {
-    for (unsigned i = 0; i < m_childRules.size(); ++i)
-        m_childRules[i] = o.m_childRules[i]->copy();
+    m_childRules.reserveInitialCapacity(o.m_childRules.size());
+    for (unsigned i = 0, size = o.m_childRules.size(); i < size; ++i)
+        m_childRules.uncheckedAppend(o.m_childRules[i]->copy());
 }
 
-void StyleRuleGroup::wrapperInsertRule(unsigned index, PassRefPtr<StyleRuleBase> rule)
+void StyleRuleGroup::wrapperInsertRule(unsigned index, PassRef<StyleRuleBase> rule)
 {
-    m_childRules.insert(index, rule);
+    m_childRules.insert(index, std::move(rule));
 }
     
 void StyleRuleGroup::wrapperRemoveRule(unsigned index)

Modified: trunk/Source/WebCore/css/StyleRule.h (157697 => 157698)


--- trunk/Source/WebCore/css/StyleRule.h	2013-10-20 05:42:46 UTC (rev 157697)
+++ trunk/Source/WebCore/css/StyleRule.h	2013-10-20 10:49:10 UTC (rev 157698)
@@ -86,7 +86,7 @@
     bool isFilterRule() const { return type() == Filter; }
 #endif
 
-    PassRefPtr<StyleRuleBase> copy() const;
+    PassRef<StyleRuleBase> copy() const;
 
     int sourceLine() const { return m_sourceLine; }
 
@@ -118,9 +118,9 @@
 class StyleRule : public StyleRuleBase {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassRefPtr<StyleRule> create(int sourceLine, PassRef<StylePropertySet> properties)
+    static PassRef<StyleRule> create(int sourceLine, PassRef<StylePropertySet> properties)
     {
-        return adoptRef(new StyleRule(sourceLine, std::move(properties)));
+        return adoptRef(*new StyleRule(sourceLine, std::move(properties)));
     }
     
     ~StyleRule();
@@ -133,7 +133,7 @@
     void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
     void parserAdoptSelectorArray(CSSSelector* selectors) { m_selectorList.adoptSelectorArray(selectors); }
 
-    PassRefPtr<StyleRule> copy() const { return adoptRef(new StyleRule(*this)); }
+    PassRef<StyleRule> copy() const { return adoptRef(*new StyleRule(*this)); }
 
     Vector<RefPtr<StyleRule>> splitIntoMultipleRulesWithMaximumSelectorComponentCount(unsigned) const;
 
@@ -143,7 +143,7 @@
     StyleRule(int sourceLine, PassRef<StylePropertySet>);
     StyleRule(const StyleRule&);
 
-    static PassRefPtr<StyleRule> create(int sourceLine, const Vector<const CSSSelector*>&, PassRef<StylePropertySet>);
+    static PassRef<StyleRule> create(int sourceLine, const Vector<const CSSSelector*>&, PassRef<StylePropertySet>);
 
     Ref<StylePropertySet> m_properties;
     CSSSelectorList m_selectorList;
@@ -157,14 +157,14 @@
 
 class StyleRuleFontFace : public StyleRuleBase {
 public:
-    static PassRefPtr<StyleRuleFontFace> create(PassRef<StylePropertySet> properties) { return adoptRef(new StyleRuleFontFace(std::move(properties))); }
+    static PassRef<StyleRuleFontFace> create(PassRef<StylePropertySet> properties) { return adoptRef(*new StyleRuleFontFace(std::move(properties))); }
     
     ~StyleRuleFontFace();
 
     const StylePropertySet& properties() const { return m_properties.get(); }
     MutableStylePropertySet& mutableProperties();
 
-    PassRefPtr<StyleRuleFontFace> copy() const { return adoptRef(new StyleRuleFontFace(*this)); }
+    PassRef<StyleRuleFontFace> copy() const { return adoptRef(*new StyleRuleFontFace(*this)); }
 
 
 private:
@@ -176,7 +176,7 @@
 
 class StyleRulePage : public StyleRuleBase {
 public:
-    static PassRefPtr<StyleRulePage> create(PassRef<StylePropertySet> properties) { return adoptRef(new StyleRulePage(std::move(properties))); }
+    static PassRef<StyleRulePage> create(PassRef<StylePropertySet> properties) { return adoptRef(*new StyleRulePage(std::move(properties))); }
 
     ~StyleRulePage();
 
@@ -187,7 +187,7 @@
     void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector>>& selectors) { m_selectorList.adoptSelectorVector(selectors); }
     void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
 
-    PassRefPtr<StyleRulePage> copy() const { return adoptRef(new StyleRulePage(*this)); }
+    PassRef<StyleRulePage> copy() const { return adoptRef(*new StyleRulePage(*this)); }
 
 private:
     StyleRulePage(PassRef<StylePropertySet>);
@@ -201,7 +201,7 @@
 public:
     const Vector<RefPtr<StyleRuleBase>>& childRules() const { return m_childRules; }
     
-    void wrapperInsertRule(unsigned, PassRefPtr<StyleRuleBase>);
+    void wrapperInsertRule(unsigned, PassRef<StyleRuleBase>);
     void wrapperRemoveRule(unsigned);
     
 protected:
@@ -214,14 +214,14 @@
 
 class StyleRuleMedia : public StyleRuleGroup {
 public:
-    static PassRefPtr<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+    static PassRef<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
     {
-        return adoptRef(new StyleRuleMedia(media, adoptRules));
+        return adoptRef(*new StyleRuleMedia(media, adoptRules));
     }
 
     MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
 
-    PassRefPtr<StyleRuleMedia> copy() const { return adoptRef(new StyleRuleMedia(*this)); }
+    PassRef<StyleRuleMedia> copy() const { return adoptRef(*new StyleRuleMedia(*this)); }
 
 private:
     StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase>>& adoptRules);
@@ -233,14 +233,14 @@
 #if ENABLE(CSS3_CONDITIONAL_RULES)
 class StyleRuleSupports : public StyleRuleGroup {
 public:
-    static PassRefPtr<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+    static PassRef<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules)
     {
-        return adoptRef(new StyleRuleSupports(conditionText, conditionIsSupported, adoptRules));
+        return adoptRef(*new StyleRuleSupports(conditionText, conditionIsSupported, adoptRules));
     }
 
     String conditionText() const { return m_conditionText; }
     bool conditionIsSupported() const { return m_conditionIsSupported; }
-    PassRefPtr<StyleRuleSupports> copy() const { return adoptRef(new StyleRuleSupports(*this)); }
+    PassRef<StyleRuleSupports> copy() const { return adoptRef(*new StyleRuleSupports(*this)); }
 
 private:
     StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules);
@@ -253,14 +253,14 @@
 
 class StyleRuleRegion : public StyleRuleGroup {
 public:
-    static PassRefPtr<StyleRuleRegion> create(Vector<OwnPtr<CSSParserSelector>>* selectors, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+    static PassRef<StyleRuleRegion> create(Vector<OwnPtr<CSSParserSelector>>* selectors, Vector<RefPtr<StyleRuleBase>>& adoptRules)
     {
-        return adoptRef(new StyleRuleRegion(selectors, adoptRules));
+        return adoptRef(*new StyleRuleRegion(selectors, adoptRules));
     }
 
     const CSSSelectorList& selectorList() const { return m_selectorList; }
 
-    PassRefPtr<StyleRuleRegion> copy() const { return adoptRef(new StyleRuleRegion(*this)); }
+    PassRef<StyleRuleRegion> copy() const { return adoptRef(*new StyleRuleRegion(*this)); }
 
 private:
     StyleRuleRegion(Vector<OwnPtr<CSSParserSelector>>*, Vector<RefPtr<StyleRuleBase>>& adoptRules);
@@ -272,12 +272,12 @@
 #if ENABLE(SHADOW_DOM)
 class StyleRuleHost : public StyleRuleGroup {
 public:
-    static PassRefPtr<StyleRuleHost> create(Vector<RefPtr<StyleRuleBase>>& adoptRules)
+    static PassRef<StyleRuleHost> create(Vector<RefPtr<StyleRuleBase>>& adoptRules)
     {
-        return adoptRef(new StyleRuleHost(adoptRules));
+        return adoptRef(*new StyleRuleHost(adoptRules));
     }
 
-    PassRefPtr<StyleRuleHost> copy() const { return adoptRef(new StyleRuleHost(*this)); }
+    PassRef<StyleRuleHost> copy() const { return adoptRef(*new StyleRuleHost(*this)); }
 
 private:
     StyleRuleHost(Vector<RefPtr<StyleRuleBase>>& adoptRules) : StyleRuleGroup(HostInternal, adoptRules) { }
@@ -288,14 +288,14 @@
 #if ENABLE(CSS_DEVICE_ADAPTATION)
 class StyleRuleViewport : public StyleRuleBase {
 public:
-    static PassRefPtr<StyleRuleViewport> create(PassRef<StylePropertySet> properties) { return adoptRef(new StyleRuleViewport(std::move(properties))); }
+    static PassRef<StyleRuleViewport> create(PassRef<StylePropertySet> properties) { return adoptRef(*new StyleRuleViewport(std::move(properties))); }
 
     ~StyleRuleViewport();
 
     const StylePropertySet& properties() const { return m_properties.get(); }
     MutableStylePropertySet& mutableProperties();
 
-    PassRefPtr<StyleRuleViewport> copy() const { return adoptRef(new StyleRuleViewport(*this)); }
+    PassRef<StyleRuleViewport> copy() const { return adoptRef(*new StyleRuleViewport(*this)); }
 
 private:
     StyleRuleViewport(PassRef<StylePropertySet>);
@@ -328,9 +328,9 @@
 #if ENABLE(CSS_SHADERS)
 class StyleRuleFilter : public StyleRuleBase {
 public:
-    static PassRefPtr<StyleRuleFilter> create(const String& filterName, PassRef<StylePropertySet> properties)
+    static PassRef<StyleRuleFilter> create(const String& filterName, PassRef<StylePropertySet> properties)
     {
-        return adoptRef(new StyleRuleFilter(filterName, std::move(properties)));
+        return adoptRef(*new StyleRuleFilter(filterName, std::move(properties)));
     }
 
     ~StyleRuleFilter();
@@ -340,7 +340,7 @@
     const StylePropertySet& properties() const { return m_properties.get(); }
     MutableStylePropertySet& mutableProperties();
 
-    PassRefPtr<StyleRuleFilter> copy() const { return adoptRef(new StyleRuleFilter(*this)); }
+    PassRef<StyleRuleFilter> copy() const { return adoptRef(*new StyleRuleFilter(*this)); }
 
 private:
     StyleRuleFilter(const String&, PassRef<StylePropertySet>);

Modified: trunk/Source/WebCore/css/StyleRuleImport.cpp (157697 => 157698)


--- trunk/Source/WebCore/css/StyleRuleImport.cpp	2013-10-20 05:42:46 UTC (rev 157697)
+++ trunk/Source/WebCore/css/StyleRuleImport.cpp	2013-10-20 10:49:10 UTC (rev 157698)
@@ -34,9 +34,9 @@
 
 namespace WebCore {
 
-PassRefPtr<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefPtr<MediaQuerySet> media)
+PassRef<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefPtr<MediaQuerySet> media)
 {
-    return adoptRef(new StyleRuleImport(href, media));
+    return adoptRef(*new StyleRuleImport(href, media));
 }
 
 StyleRuleImport::StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet> media)

Modified: trunk/Source/WebCore/css/StyleRuleImport.h (157697 => 157698)


--- trunk/Source/WebCore/css/StyleRuleImport.h	2013-10-20 05:42:46 UTC (rev 157697)
+++ trunk/Source/WebCore/css/StyleRuleImport.h	2013-10-20 10:49:10 UTC (rev 157698)
@@ -35,7 +35,7 @@
 class StyleRuleImport : public StyleRuleBase {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassRefPtr<StyleRuleImport> create(const String& href, PassRefPtr<MediaQuerySet>);
+    static PassRef<StyleRuleImport> create(const String& href, PassRefPtr<MediaQuerySet>);
 
     ~StyleRuleImport();
     

Modified: trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h (157697 => 157698)


--- trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h	2013-10-20 05:42:46 UTC (rev 157697)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h	2013-10-20 10:49:10 UTC (rev 157698)
@@ -39,7 +39,7 @@
 
 class StyleRuleKeyframes : public StyleRuleBase {
 public:
-    static PassRefPtr<StyleRuleKeyframes> create() { return adoptRef(new StyleRuleKeyframes()); }
+    static PassRef<StyleRuleKeyframes> create() { return adoptRef(*new StyleRuleKeyframes()); }
     
     ~StyleRuleKeyframes();
     
@@ -54,7 +54,7 @@
     
     int findKeyframeIndex(const String& key) const;
 
-    PassRefPtr<StyleRuleKeyframes> copy() const { return adoptRef(new StyleRuleKeyframes(*this)); }
+    PassRef<StyleRuleKeyframes> copy() const { return adoptRef(*new StyleRuleKeyframes(*this)); }
 
 private:
     StyleRuleKeyframes();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to