NamedFlowCollection should be a ContextDestructionObserver
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 04:59:23 +0000 (04:59 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 04:59:23 +0000 (04:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=99239

Patch by Hanyee Kim <choco@company100.net> on 2013-02-07
Reviewed by Adam Barth

This patch removes the raw pointer of Document in NamedFlowCollection.
It could be replaced with ContextDestructionObserver.
ContextDestructionObserver has the pointer and clears the pointer
automatically when the document is destroyed.

* dom/Document.cpp:
(WebCore::Document::~Document):
* dom/NamedFlowCollection.cpp:
(WebCore::NamedFlowCollection::NamedFlowCollection):
(WebCore::NamedFlowCollection::ensureFlowWithName):
(WebCore::NamedFlowCollection::discardNamedFlow):
(WebCore::NamedFlowCollection::document):
(WebCore):
* dom/NamedFlowCollection.h:
(NamedFlowCollection):

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

Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/NamedFlowCollection.cpp
Source/WebCore/dom/NamedFlowCollection.h

index b53e2e8060c6600bf15e598fbe9e583ee88a2b26..f1c5704ed5e6b974bdea334a36f811dd3e7f4cc8 100644 (file)
@@ -1,3 +1,26 @@
+2013-02-07  Hanyee Kim  <choco@company100.net>
+
+        NamedFlowCollection should be a ContextDestructionObserver
+        https://bugs.webkit.org/show_bug.cgi?id=99239
+
+        Reviewed by Adam Barth
+
+        This patch removes the raw pointer of Document in NamedFlowCollection.
+        It could be replaced with ContextDestructionObserver.
+        ContextDestructionObserver has the pointer and clears the pointer
+        automatically when the document is destroyed. 
+
+        * dom/Document.cpp:
+        (WebCore::Document::~Document):
+        * dom/NamedFlowCollection.cpp:
+        (WebCore::NamedFlowCollection::NamedFlowCollection):
+        (WebCore::NamedFlowCollection::ensureFlowWithName):
+        (WebCore::NamedFlowCollection::discardNamedFlow):
+        (WebCore::NamedFlowCollection::document):
+        (WebCore):
+        * dom/NamedFlowCollection.h:
+        (NamedFlowCollection):
+
 2013-02-07  Dean Jackson  <dino@apple.com>
 
         Followup review suggestions from Alexey Proskuryakov on
index 6214756bc143893169964deacff72cafa72036b2..8ce399f1c210c8f089774c815b7d1d4acc391af7 100644 (file)
@@ -621,9 +621,6 @@ Document::~Document()
 
     m_styleSheetCollection.clear();
 
-    if (m_namedFlows)
-        m_namedFlows->documentDestroyed();
-
     if (m_elemSheet)
         m_elemSheet->clearOwnerNode();
 
index 4cbefe515800490654f6a92bd04d427e7afc23e7..2bb940c89ee15e399f36197da69168cdb6d500d7 100644 (file)
@@ -40,8 +40,8 @@
 
 namespace WebCore {
 
-NamedFlowCollection::NamedFlowCollection(Document* doc)
-    : m_document(doc)
+NamedFlowCollection::NamedFlowCollection(Document* document)
+    : ContextDestructionObserver(document)
 {
 }
 
@@ -81,7 +81,7 @@ PassRefPtr<WebKitNamedFlow> NamedFlowCollection::ensureFlowWithName(const String
     RefPtr<WebKitNamedFlow> newFlow = WebKitNamedFlow::create(this, flowName);
     m_namedFlows.add(newFlow.get());
 
-    InspectorInstrumentation::didCreateNamedFlow(m_document, newFlow.get());
+    InspectorInstrumentation::didCreateNamedFlow(document(), newFlow.get());
 
     return newFlow.release();
 }
@@ -89,21 +89,24 @@ PassRefPtr<WebKitNamedFlow> NamedFlowCollection::ensureFlowWithName(const String
 void NamedFlowCollection::discardNamedFlow(WebKitNamedFlow* namedFlow)
 {
     // The document is not valid anymore so the collection will be destroyed anyway.
-    if (!m_document)
+    if (!document())
         return;
 
     ASSERT(namedFlow->flowState() == WebKitNamedFlow::FlowStateNull);
     ASSERT(m_namedFlows.contains(namedFlow));
 
-    InspectorInstrumentation::willRemoveNamedFlow(m_document, namedFlow);
+    InspectorInstrumentation::willRemoveNamedFlow(document(), namedFlow);
 
     m_namedFlows.remove(namedFlow);
 }
 
-void NamedFlowCollection::documentDestroyed()
+Document* NamedFlowCollection::document() const
 {
-    m_document = 0;
+    ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();
+    ASSERT(!context || context->isDocument());
+    return static_cast<Document*>(context);
 }
+
 PassRefPtr<DOMNamedFlowCollection> NamedFlowCollection::createCSSOMSnapshot()
 {
     Vector<WebKitNamedFlow*> createdFlows;
index f214d0b3f92e16bd377bb6888dcbbad234608b89..b02404ccb4f7f5260c81d05439d76c1c00800d1c 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef NamedFlowCollection_h
 #define NamedFlowCollection_h
 
+#include "ContextDestructionObserver.h"
 #include "WebKitNamedFlow.h"
 #include <wtf/Forward.h>
 #include <wtf/ListHashSet.h>
@@ -42,7 +43,7 @@ namespace WebCore {
 class Document;
 class DOMNamedFlowCollection;
 
-class NamedFlowCollection : public RefCounted<NamedFlowCollection> {
+class NamedFlowCollection : public RefCounted<NamedFlowCollection>, public ContextDestructionObserver {
 public:
     static PassRefPtr<NamedFlowCollection> create(Document* doc) { return adoptRef(new NamedFlowCollection(doc)); }
 
@@ -52,9 +53,7 @@ public:
 
     void discardNamedFlow(WebKitNamedFlow*);
 
-    void documentDestroyed();
-
-    Document* document() const { return m_document; }
+    Document* document() const;
 
     virtual ~NamedFlowCollection() { }
 
@@ -68,7 +67,6 @@ private:
 
     explicit NamedFlowCollection(Document*);
 
-    Document* m_document;
     NamedFlowSet m_namedFlows;
 };