Title: [265354] trunk/Source/WebCore
Revision
265354
Author
wenson_hs...@apple.com
Date
2020-08-06 17:00:28 -0700 (Thu, 06 Aug 2020)

Log Message

WeakPtr threading assertion on editing/undo-manager/undo-manager-delete-stale-undo-items.html
https://bugs.webkit.org/show_bug.cgi?id=215221
<rdar://problem/66632111>

Reviewed by Devin Rousso.

Refactors `UndoItem` to avoid dereferencing its `m_undoManager` underneath `UndoItem::document`, which is
consulted when computing its JS wrapper's opaque roots. Instead of going through `m_undoManager` to grab the
document, store a `WeakPtr` to the `Document` upon setting the `UndoManager` and return its pointer value
directly in `document()`.

* page/UndoItem.cpp:
(WebCore::UndoItem::setUndoManager):
(WebCore::UndoItem::invalidate):
(WebCore::UndoItem::document const):
* page/UndoItem.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (265353 => 265354)


--- trunk/Source/WebCore/ChangeLog	2020-08-06 23:46:49 UTC (rev 265353)
+++ trunk/Source/WebCore/ChangeLog	2020-08-07 00:00:28 UTC (rev 265354)
@@ -1,3 +1,22 @@
+2020-08-06  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        WeakPtr threading assertion on editing/undo-manager/undo-manager-delete-stale-undo-items.html
+        https://bugs.webkit.org/show_bug.cgi?id=215221
+        <rdar://problem/66632111>
+
+        Reviewed by Devin Rousso.
+
+        Refactors `UndoItem` to avoid dereferencing its `m_undoManager` underneath `UndoItem::document`, which is
+        consulted when computing its JS wrapper's opaque roots. Instead of going through `m_undoManager` to grab the
+        document, store a `WeakPtr` to the `Document` upon setting the `UndoManager` and return its pointer value
+        directly in `document()`.
+
+        * page/UndoItem.cpp:
+        (WebCore::UndoItem::setUndoManager):
+        (WebCore::UndoItem::invalidate):
+        (WebCore::UndoItem::document const):
+        * page/UndoItem.h:
+
 2020-08-06  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Use references instead of pointers for WidthIterator's fonts

Modified: trunk/Source/WebCore/page/UndoItem.cpp (265353 => 265354)


--- trunk/Source/WebCore/page/UndoItem.cpp	2020-08-06 23:46:49 UTC (rev 265353)
+++ trunk/Source/WebCore/page/UndoItem.cpp	2020-08-07 00:00:28 UTC (rev 265354)
@@ -41,14 +41,15 @@
 void UndoItem::setUndoManager(UndoManager* undoManager)
 {
     m_undoManager = makeWeakPtr(undoManager);
+    m_document = makeWeakPtr(undoManager ? &undoManager->document() : nullptr);
 }
 
 void UndoItem::invalidate()
 {
-    if (auto* undoManager = m_undoManager.get()) {
-        undoManager->removeItem(*this);
-        m_undoManager = nullptr;
-    }
+    if (m_undoManager)
+        m_undoManager->removeItem(*this);
+    m_undoManager.clear();
+    m_document.clear();
 }
 
 bool UndoItem::isValid() const
@@ -58,10 +59,7 @@
 
 Document* UndoItem::document() const
 {
-    if (!isValid())
-        return nullptr;
-
-    return &m_undoManager->document();
+    return m_document.get();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/UndoItem.h (265353 => 265354)


--- trunk/Source/WebCore/page/UndoItem.h	2020-08-06 23:46:49 UTC (rev 265353)
+++ trunk/Source/WebCore/page/UndoItem.h	2020-08-07 00:00:28 UTC (rev 265354)
@@ -74,6 +74,7 @@
     Ref<VoidCallback> m_undoHandler;
     Ref<VoidCallback> m_redoHandler;
     WeakPtr<UndoManager> m_undoManager;
+    WeakPtr<Document> m_document;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to