Bug 1549268 - Mark EditorBase::JoinNodesWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 May 2019 02:29:43 +0000
changeset 534879 efc64ba2b311e18d16820a00e98572807ee724a0
parent 534878 5a44b50a07cfcbc201d54f9adab7993a5815c34d
child 534880 3db2c18f995048c3c7f2dc494ce7e582e9f374c1
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1549268
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1549268 - Mark EditorBase::JoinNodesWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D30041
editor/libeditor/EditorBase.h
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/nsIEditor.idl
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1080,16 +1080,17 @@ class EditorBase : public nsIEditor,
    * JoinNodesWithTransaction() joins aLeftNode and aRightNode.  Content of
    * aLeftNode will be merged into aRightNode.  Actual implemenation of this
    * method is JoinNodesImpl().  So, see its explanation for the detail.
    *
    * @param aLeftNode   Will be removed from the DOM tree.
    * @param aRightNode  The node which will be new container of the content of
    *                    aLeftNode.
    */
+  MOZ_CAN_RUN_SCRIPT
   nsresult JoinNodesWithTransaction(nsINode& aLeftNode, nsINode& aRightNode);
 
   /**
    * MoveNodeWithTransaction() moves aContent to aPointToInsert.
    *
    * @param aContent        The node to be moved.
    */
   template <typename PT, typename CT>
@@ -1398,16 +1399,17 @@ class EditorBase : public nsIEditor,
    * assumed as its previous sibling.  Then, they will be joined again.
    * And then, these steps are repeated.
    *
    * @param aLeftNode   The node which will be removed form the tree.
    * @param aRightNode  The node which will be inserted the contents of
    *                    aLeftNode.
    * @return            The point of the first child of the last right node.
    */
+  MOZ_CAN_RUN_SCRIPT
   EditorDOMPoint JoinNodesDeepWithTransaction(nsIContent& aLeftNode,
                                               nsIContent& aRightNode);
 
   nsresult DoTransactionInternal(nsITransaction* aTxn);
 
   virtual bool IsBlockNode(nsINode* aNode);
 
   /**
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -507,17 +507,19 @@ nsresult HTMLEditRules::AfterEditInner(E
     }
     NS_WARNING_ASSERTION(
         NS_SUCCEEDED(rv),
         "Failed to insert <br> elements to empty list items and table cells");
 
     // merge any adjacent text nodes
     if (aEditSubAction != EditSubAction::eInsertText &&
         aEditSubAction != EditSubAction::eInsertTextComingFromIME) {
-      nsresult rv = HTMLEditorRef().CollapseAdjacentTextNodes(mDocChangeRange);
+      RefPtr<nsRange> docChangeRange = mDocChangeRange;
+      nsresult rv = MOZ_KnownLive(HTMLEditorRef())
+                        .CollapseAdjacentTextNodes(docChangeRange);
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
@@ -2969,18 +2971,19 @@ nsresult HTMLEditRules::WillDeleteSelect
                    .DeleteSelectionWithTransaction(aAction, aStripWrappers);
           if (NS_WARN_IF(!CanHandleEditAction())) {
             return NS_ERROR_EDITOR_DESTROYED;
           }
           if (NS_WARN_IF(NS_FAILED(rv))) {
             return rv;
           }
           // Join blocks
-          EditorDOMPoint pt = HTMLEditorRef().JoinNodesDeepWithTransaction(
-              *leftParent, *rightParent);
+          EditorDOMPoint pt =
+              MOZ_KnownLive(HTMLEditorRef())
+                  .JoinNodesDeepWithTransaction(*leftParent, *rightParent);
           if (NS_WARN_IF(!CanHandleEditAction())) {
             return NS_ERROR_EDITOR_DESTROYED;
           }
           if (NS_WARN_IF(!pt.IsSet())) {
             return NS_ERROR_FAILURE;
           }
           // Fix up selection
           ErrorResult error;
@@ -8878,18 +8881,18 @@ nsresult HTMLEditRules::JoinNearestEdita
     }
   }
 
   EditorDOMPoint ret(&aNodeRight, aNodeLeft.Length());
 
   // Separate join rules for differing blocks
   if (HTMLEditUtils::IsList(&aNodeLeft) || aNodeLeft.GetAsText()) {
     // For lists, merge shallow (wouldn't want to combine list items)
-    nsresult rv =
-        HTMLEditorRef().JoinNodesWithTransaction(aNodeLeft, aNodeRight);
+    nsresult rv = MOZ_KnownLive(HTMLEditorRef())
+                      .JoinNodesWithTransaction(aNodeLeft, aNodeRight);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       return NS_ERROR_EDITOR_DESTROYED;
     }
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     *aNewFirstChildOfRightNode = std::move(ret);
     return NS_OK;
@@ -8904,17 +8907,18 @@ nsresult HTMLEditRules::JoinNearestEdita
 
   nsCOMPtr<nsIContent> firstRight =
       HTMLEditorRef().GetFirstEditableChild(aNodeRight);
   if (NS_WARN_IF(!firstRight)) {
     return NS_ERROR_FAILURE;
   }
 
   // For list items, divs, etc., merge smart
-  nsresult rv = HTMLEditorRef().JoinNodesWithTransaction(aNodeLeft, aNodeRight);
+  nsresult rv = MOZ_KnownLive(HTMLEditorRef())
+                    .JoinNodesWithTransaction(aNodeLeft, aNodeRight);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return NS_ERROR_EDITOR_DESTROYED;
   }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (lastLeft && firstRight &&
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -3773,17 +3773,18 @@ nsresult HTMLEditor::CollapseAdjacentTex
     nsINode* leftTextNode = textNodes[0];
     nsINode* rightTextNode = textNodes[1];
     NS_ASSERTION(leftTextNode && rightTextNode,
                  "left or rightTextNode null in CollapseAdjacentTextNodes");
 
     // get the prev sibling of the right node, and see if its leftTextNode
     nsCOMPtr<nsINode> prevSibOfRightNode = rightTextNode->GetPreviousSibling();
     if (prevSibOfRightNode && prevSibOfRightNode == leftTextNode) {
-      nsresult rv = JoinNodesWithTransaction(*leftTextNode, *rightTextNode);
+      nsresult rv = JoinNodesWithTransaction(MOZ_KnownLive(*leftTextNode),
+                                             MOZ_KnownLive(*rightTextNode));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
     textNodes.RemoveElementAt(
         0);  // remove the leftmost text node from the list
   }
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -706,17 +706,17 @@ class HTMLEditor final : public TextEdit
   /**
    * Returns true if aNode is a container.
    */
   virtual bool IsContainer(nsINode* aNode) override;
 
   /**
    * Join together any adjacent editable text nodes in the range.
    */
-  nsresult CollapseAdjacentTextNodes(nsRange* aRange);
+  MOZ_CAN_RUN_SCRIPT nsresult CollapseAdjacentTextNodes(nsRange* aRange);
 
   /**
    * IsInVisibleTextFrames() returns true if all text in aText is in visible
    * text frames.  Callers have to guarantee that there is no pending reflow.
    */
   bool IsInVisibleTextFrames(dom::Text& aText);
 
   /**
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -429,16 +429,17 @@ interface nsIEditor  : nsISupports
    * @param aLeftNode     The left node.  It will be deleted.
    * @param aRightNode    The right node. It will remain after the join.
    * @param aParent       The parent of aExistingRightNode
    *
    *                      There is no requirement that the two nodes be
    *                      of the same type.  However, a text node can be
    *                      merged only with another text node.
    */
+  [can_run_script]
   void joinNodes(in Node leftNode,
                  in Node rightNode,
                  in Node parent);
 
   /**
    * deleteNode removes aChild from aParent.
    * @param aChild    The node to delete
    */