References from CSSStyleDeclaration to CSSValues should be weak
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2018 23:33:02 +0000 (23:33 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2018 23:33:02 +0000 (23:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180280
<rdar://problem/35804869>

Patch by Tadeu Zagallo <tzagallo@apple.com> on 2018-04-17
Reviewed by Geoffrey Garen.

No new tests - used the existing test to verify the leak

* css/DeprecatedCSSOMValue.h:
(WebCore::DeprecatedCSSOMValue::weakPtrFactory):
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::PropertySetCSSStyleDeclaration::wrapForDeprecatedCSSOM):
* css/PropertySetCSSStyleDeclaration.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230737 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/DeprecatedCSSOMValue.h
Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Source/WebCore/css/PropertySetCSSStyleDeclaration.h

index 9f59c62..a508bbf 100644 (file)
@@ -1,3 +1,19 @@
+2018-04-17  Tadeu Zagallo  <tzagallo@apple.com>
+
+        References from CSSStyleDeclaration to CSSValues should be weak
+        https://bugs.webkit.org/show_bug.cgi?id=180280
+        <rdar://problem/35804869>
+
+        Reviewed by Geoffrey Garen.
+
+        No new tests - used the existing test to verify the leak
+
+        * css/DeprecatedCSSOMValue.h:
+        (WebCore::DeprecatedCSSOMValue::weakPtrFactory):
+        * css/PropertySetCSSStyleDeclaration.cpp:
+        (WebCore::PropertySetCSSStyleDeclaration::wrapForDeprecatedCSSOM):
+        * css/PropertySetCSSStyleDeclaration.h:
+
 2018-04-17  Jonathan Bedard  <jbedard@apple.com>
 
         Unreviewed rollout of r230632. Regression in memory usage.
index ca308e3..77e2e36 100644 (file)
@@ -31,6 +31,7 @@
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 #include <wtf/TypeCasts.h>
+#include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -64,6 +65,8 @@ public:
 
     CSSStyleDeclaration& owner() const { return m_owner; }
 
+    WeakPtrFactory<DeprecatedCSSOMValue>& weakPtrFactory() { return m_weakPtrFactory; }
+
 protected:
     static const size_t ClassTypeBits = 2;
     enum DeprecatedClassType {
@@ -92,6 +95,7 @@ protected:
     unsigned m_classType : ClassTypeBits; // ClassType
     
     Ref<CSSStyleDeclaration> m_owner;
+    WeakPtrFactory<DeprecatedCSSOMValue> m_weakPtrFactory;
 };
 
 class DeprecatedCSSOMComplexValue : public DeprecatedCSSOMValue {
index 084cbca..0e14bdf 100644 (file)
@@ -308,7 +308,7 @@ ExceptionOr<bool> PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropert
     return changed;
 }
 
-DeprecatedCSSOMValue* PropertySetCSSStyleDeclaration::wrapForDeprecatedCSSOM(CSSValue* internalValue)
+RefPtr<DeprecatedCSSOMValue> PropertySetCSSStyleDeclaration::wrapForDeprecatedCSSOM(CSSValue* internalValue)
 {
     if (!internalValue)
         return nullptr;
@@ -316,12 +316,15 @@ DeprecatedCSSOMValue* PropertySetCSSStyleDeclaration::wrapForDeprecatedCSSOM(CSS
     // The map is here to maintain the object identity of the CSSValues over multiple invocations.
     // FIXME: It is likely that the identity is not important for web compatibility and this code should be removed.
     if (!m_cssomValueWrappers)
-        m_cssomValueWrappers = std::make_unique<HashMap<CSSValue*, RefPtr<DeprecatedCSSOMValue>>>();
+        m_cssomValueWrappers = std::make_unique<HashMap<CSSValue*, WeakPtr<DeprecatedCSSOMValue>>>();
     
-    RefPtr<DeprecatedCSSOMValue>& clonedValue = m_cssomValueWrappers->add(internalValue, RefPtr<DeprecatedCSSOMValue>()).iterator->value;
-    if (!clonedValue)
-        clonedValue = internalValue->createDeprecatedCSSOMWrapper(*this);
-    return clonedValue.get();
+    auto& clonedValue = m_cssomValueWrappers->add(internalValue, WeakPtr<DeprecatedCSSOMValue>()).iterator->value;
+    if (clonedValue)
+        return clonedValue.get();
+
+    RefPtr<DeprecatedCSSOMValue> wrapper = internalValue->createDeprecatedCSSOMWrapper(*this);
+    clonedValue = makeWeakPtr(wrapper.get());
+    return wrapper;
 }
 
 StyleSheetContents* PropertySetCSSStyleDeclaration::contextStyleSheet() const
index 0419640..7bc1f6e 100644 (file)
@@ -31,6 +31,7 @@
 #include <memory>
 #include <wtf/HashMap.h>
 #include <wtf/RefPtr.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -57,7 +58,7 @@ protected:
     virtual CSSParserContext cssParserContext() const;
 
     MutableStyleProperties* m_propertySet;
-    std::unique_ptr<HashMap<CSSValue*, RefPtr<DeprecatedCSSOMValue>>> m_cssomValueWrappers;
+    std::unique_ptr<HashMap<CSSValue*, WeakPtr<DeprecatedCSSOMValue>>> m_cssomValueWrappers;
 
 private:
     void ref() override;
@@ -81,7 +82,7 @@ private:
     
     Ref<MutableStyleProperties> copyProperties() const final;
 
-    DeprecatedCSSOMValue* wrapForDeprecatedCSSOM(CSSValue*);
+    RefPtr<DeprecatedCSSOMValue> wrapForDeprecatedCSSOM(CSSValue*);
     
     virtual bool willMutate() WARN_UNUSED_RETURN { return true; }
     virtual void didMutate(MutationType) { }