浏览代码

LibWeb: Make CSSStyleSheet::m_owner_css_rule a WeakPtr

It's not safe for this to be a raw pointer, as the imported style sheet
can outlive the rule.
Andreas Kling 3 年之前
父节点
当前提交
e8b85b13e2
共有 2 个文件被更改,包括 4 次插入3 次删除
  1. 3 1
      Userland/Libraries/LibWeb/CSS/CSSRule.h
  2. 1 2
      Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h

+ 3 - 1
Userland/Libraries/LibWeb/CSS/CSSRule.h

@@ -8,6 +8,7 @@
 
 #include <AK/RefCounted.h>
 #include <AK/String.h>
+#include <AK/Weakable.h>
 #include <LibWeb/Bindings/Wrappable.h>
 #include <LibWeb/CSS/CSSStyleDeclaration.h>
 #include <LibWeb/CSS/Selector.h>
@@ -16,7 +17,8 @@ namespace Web::CSS {
 
 class CSSRule
     : public RefCounted<CSSRule>
-    , public Bindings::Wrappable {
+    , public Bindings::Wrappable
+    , public Weakable<CSSRule> {
 public:
     using WrapperType = Bindings::CSSRuleWrapper;
 

+ 1 - 2
Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h

@@ -52,8 +52,7 @@ private:
 
     NonnullRefPtr<CSSRuleList> m_rules;
 
-    // FIXME: Use WeakPtr.
-    CSSRule* m_owner_css_rule { nullptr };
+    WeakPtr<CSSRule> m_owner_css_rule;
 };
 
 }