Bug 1549264 - Mark EditorBase::SplitNodeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 07 May 2019 22:34:28 +0000
changeset 531810 93efde688b8c6869c30e2e50c9b755989d4e6e57
parent 531809 36ab55f6cd91191eb913d95049996094789297d7
child 531811 5a44b50a07cfcbc201d54f9adab7993a5815c34d
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1549264
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 1549264 - Mark EditorBase::SplitNodeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D30039
editor/libeditor/EditorBase.h
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLEditorCommands.cpp
editor/libeditor/HTMLEditorDataTransfer.cpp
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
editor/libeditor/TextEditor.h
editor/libeditor/WSRunObject.cpp
editor/nsIEditor.idl
editor/nsIHTMLEditor.idl
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1067,17 +1067,17 @@ class EditorBase : public nsIEditor,
    * @param aStartOfRightNode   The point to split.  Its container will be
    *                            the right node, i.e., become the new node's
    *                            next sibling.  And the point will be start
    *                            of the right node.
    * @param aError              If succeed, returns no error.  Otherwise, an
    *                            error.
    */
   template <typename PT, typename CT>
-  already_AddRefed<nsIContent> SplitNodeWithTransaction(
+  MOZ_CAN_RUN_SCRIPT already_AddRefed<nsIContent> SplitNodeWithTransaction(
       const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
       ErrorResult& aResult);
 
   /**
    * 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.
    *
@@ -1381,17 +1381,17 @@ class EditorBase : public nsIEditor,
    *                                    split point is start or end of an
    *                                    element.
    * @return                            SplitPoint() returns split point in
    *                                    aMostAncestorToSplit.  The point must
    *                                    be good to insert something if the
    *                                    caller want to do it.
    */
   template <typename PT, typename CT>
-  SplitNodeResult SplitNodeDeepWithTransaction(
+  MOZ_CAN_RUN_SCRIPT SplitNodeResult SplitNodeDeepWithTransaction(
       nsIContent& aMostAncestorToSplit,
       const EditorDOMPointBase<PT, CT>& aDeepestStartOfRightNode,
       SplitAtEdges aSplitAtEdges);
 
   /**
    * JoinNodesDeepWithTransaction() joins aLeftNode and aRightNode "deeply".
    * First, they are joined simply, then, new right node is assumed as the
    * child at length of the left node before joined and new left node is
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -1457,19 +1457,19 @@ nsresult HTMLEditRules::WillInsertText(E
           subStrLen = tString.Length() - oldPos;
           pos = tString.Length();
         }
 
         nsDependentSubstring subStr(tString, oldPos, subStrLen);
 
         // is it a return?
         if (subStr.Equals(newlineStr)) {
-          RefPtr<Element> brElement =
-              HTMLEditorRef().InsertBrElementWithTransaction(currentPoint,
-                                                             nsIEditor::eNone);
+          RefPtr<Element> brElement = MOZ_KnownLive(HTMLEditorRef())
+                                          .InsertBrElementWithTransaction(
+                                              currentPoint, nsIEditor::eNone);
           if (NS_WARN_IF(!CanHandleEditAction())) {
             return NS_ERROR_EDITOR_DESTROYED;
           }
           if (NS_WARN_IF(!brElement)) {
             return NS_ERROR_FAILURE;
           }
           pos++;
           if (brElement->GetNextSibling()) {
@@ -1829,17 +1829,18 @@ EditActionResult HTMLEditRules::WillInse
   // contains the word "text".  The user selects "text" and types return.
   // "Text" is deleted leaving an empty block.  We want to put in one br to
   // make block have a line.  Then code further below will put in a second br.)
   if (IsEmptyBlockElement(*blockParent, IgnoreSingleBR::eNo)) {
     AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
     EditorRawDOMPoint endOfBlockParent;
     endOfBlockParent.SetToEndOf(blockParent);
     RefPtr<Element> brElement =
-        HTMLEditorRef().InsertBrElementWithTransaction(endOfBlockParent);
+        MOZ_KnownLive(HTMLEditorRef())
+            .InsertBrElementWithTransaction(endOfBlockParent);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
     }
     if (NS_WARN_IF(!brElement)) {
       return EditActionIgnored(NS_ERROR_FAILURE);
     }
   }
 
@@ -1916,17 +1917,18 @@ nsresult HTMLEditRules::InsertBRElement(
   }
 
   bool brElementIsAfterBlock = false;
   bool brElementIsBeforeBlock = false;
 
   // First, insert a <br> element.
   RefPtr<Element> brElement;
   if (IsPlaintextEditor()) {
-    brElement = HTMLEditorRef().InsertBrElementWithTransaction(aPointToBreak);
+    brElement = MOZ_KnownLive(HTMLEditorRef())
+                    .InsertBrElementWithTransaction(aPointToBreak);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       return NS_ERROR_EDITOR_DESTROYED;
     }
     if (NS_WARN_IF(!brElement)) {
       return NS_ERROR_FAILURE;
     }
   } else {
     EditorDOMPoint pointToBreak(aPointToBreak);
@@ -1941,19 +1943,20 @@ nsresult HTMLEditRules::InsertBRElement(
       brElementIsBeforeBlock = true;
     }
     // If the container of the break is a link, we need to split it and
     // insert new <br> between the split links.
     RefPtr<Element> linkNode =
         HTMLEditor::GetLinkElement(pointToBreak.GetContainer());
     if (linkNode) {
       SplitNodeResult splitLinkNodeResult =
-          HTMLEditorRef().SplitNodeDeepWithTransaction(
-              *linkNode, pointToBreak,
-              SplitAtEdges::eDoNotCreateEmptyContainer);
+          MOZ_KnownLive(HTMLEditorRef())
+              .SplitNodeDeepWithTransaction(
+                  *linkNode, pointToBreak,
+                  SplitAtEdges::eDoNotCreateEmptyContainer);
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(splitLinkNodeResult.Failed())) {
         return splitLinkNodeResult.Rv();
       }
       pointToBreak = splitLinkNodeResult.SplitPoint();
     }
@@ -2089,18 +2092,20 @@ EditActionResult HTMLEditRules::SplitMai
                          "Failed to advance offset to after the visible node");
   }
 
   if (NS_WARN_IF(!pointToSplit.GetContainerAsContent())) {
     return EditActionIgnored(NS_ERROR_FAILURE);
   }
 
   SplitNodeResult splitCiteNodeResult =
-      HTMLEditorRef().SplitNodeDeepWithTransaction(
-          *citeNode, pointToSplit, SplitAtEdges::eDoNotCreateEmptyContainer);
+      MOZ_KnownLive(HTMLEditorRef())
+          .SplitNodeDeepWithTransaction(
+              *citeNode, pointToSplit,
+              SplitAtEdges::eDoNotCreateEmptyContainer);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
   }
   if (NS_WARN_IF(splitCiteNodeResult.Failed())) {
     return EditActionIgnored(splitCiteNodeResult.Rv());
   }
   pointToSplit.Clear();
 
@@ -2119,32 +2124,33 @@ EditActionResult HTMLEditRules::SplitMai
       previousNodeOfSplitPoint->GetPrimaryFrame() &&
       previousNodeOfSplitPoint->GetPrimaryFrame()->IsBlockFrameOrSubclass()) {
     nsCOMPtr<nsINode> lastChild = previousNodeOfSplitPoint->GetLastChild();
     if (lastChild && !lastChild->IsHTMLElement(nsGkAtoms::br)) {
       // We ignore the result here.
       EditorRawDOMPoint endOfPreviousNodeOfSplitPoint;
       endOfPreviousNodeOfSplitPoint.SetToEndOf(previousNodeOfSplitPoint);
       RefPtr<Element> invisibleBrElement =
-          HTMLEditorRef().InsertBrElementWithTransaction(
-              endOfPreviousNodeOfSplitPoint);
+          MOZ_KnownLive(HTMLEditorRef())
+              .InsertBrElementWithTransaction(endOfPreviousNodeOfSplitPoint);
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
       }
       NS_WARNING_ASSERTION(invisibleBrElement,
                            "Failed to create an invisible <br> element");
     }
   }
 
   // In most cases, <br> should be inserted after current cite.  However, if
   // left cite hasn't been created because the split point was start of the
   // cite node, <br> should be inserted before the current cite.
   EditorRawDOMPoint pointToInsertBrNode(splitCiteNodeResult.SplitPoint());
   RefPtr<Element> brElement =
-      HTMLEditorRef().InsertBrElementWithTransaction(pointToInsertBrNode);
+      MOZ_KnownLive(HTMLEditorRef())
+          .InsertBrElementWithTransaction(pointToInsertBrNode);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
   }
   if (NS_WARN_IF(!brElement)) {
     return EditActionIgnored(NS_ERROR_FAILURE);
   }
   // Now, offset of pointToInsertBrNode is invalid.  Let's clear it.
   pointToInsertBrNode.Clear();
@@ -2184,18 +2190,18 @@ EditActionResult HTMLEditRules::SplitMai
       NS_WARNING_ASSERTION(advanced,
                            "Failed to advance offset after the <br> node");
       WSRunObject wsObjAfterBR(&HTMLEditorRef(), pointAfterNewBrNode);
       wsObjAfterBR.NextVisibleNode(pointAfterNewBrNode, &wsType);
       if (wsType == WSType::normalWS || wsType == WSType::text ||
           wsType == WSType::special ||
           // In case we're at the very end.
           wsType == WSType::thisBlock) {
-        brElement = HTMLEditorRef().InsertBrElementWithTransaction(
-            pointToCreateNewBrNode);
+        brElement = MOZ_KnownLive(HTMLEditorRef())
+                        .InsertBrElementWithTransaction(pointToCreateNewBrNode);
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
         }
         if (NS_WARN_IF(!brElement)) {
           return EditActionIgnored(NS_ERROR_FAILURE);
         }
         // Now, those points may be invalid.
         pointToCreateNewBrNode.Clear();
@@ -3172,18 +3178,19 @@ nsresult HTMLEditRules::InsertBRIfNeeded
   if (((wsObj.mStartReason & WSType::block) ||
        (wsObj.mStartReason & WSType::br)) &&
       (wsObj.mEndReason & WSType::block)) {
     // if we are tucked between block boundaries then insert a br
     // first check that we are allowed to
     if (HTMLEditorRef().CanContainTag(*atStartOfSelection.GetContainer(),
                                       *nsGkAtoms::br)) {
       RefPtr<Element> brElement =
-          HTMLEditorRef().InsertBrElementWithTransaction(atStartOfSelection,
-                                                         nsIEditor::ePrevious);
+          MOZ_KnownLive(HTMLEditorRef())
+              .InsertBrElementWithTransaction(atStartOfSelection,
+                                              nsIEditor::ePrevious);
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(!brElement)) {
         return NS_ERROR_FAILURE;
       }
       return NS_OK;
     }
@@ -3493,19 +3500,21 @@ EditActionResult HTMLEditRules::TryToJoi
       // previous content, we split the previous content's style.
 
       RefPtr<Element> editorRoot = HTMLEditorRef().GetEditorRoot();
       if (!editorRoot || &aLeftNode != editorRoot) {
         nsCOMPtr<nsIContent> splittedPreviousContent;
         nsCOMPtr<nsINode> previousContentParent =
             previousContent.GetContainer();
         int32_t previousContentOffset = previousContent.Offset();
-        rv = HTMLEditorRef().SplitStyleAbovePoint(
-            address_of(previousContentParent), &previousContentOffset, nullptr,
-            nullptr, nullptr, getter_AddRefs(splittedPreviousContent));
+        rv = MOZ_KnownLive(HTMLEditorRef())
+                 .SplitStyleAbovePoint(address_of(previousContentParent),
+                                       &previousContentOffset, nullptr, nullptr,
+                                       nullptr,
+                                       getter_AddRefs(splittedPreviousContent));
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return EditActionIgnored(NS_ERROR_EDITOR_DESTROYED);
         }
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return EditActionIgnored(rv);
         }
 
         if (splittedPreviousContent) {
@@ -3792,17 +3801,18 @@ nsresult HTMLEditRules::DidDeleteSelecti
           return NS_ERROR_EDITOR_DESTROYED;
         }
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       if (atCiteNode.IsSet() && seenBR) {
         RefPtr<Element> brElement =
-            HTMLEditorRef().InsertBrElementWithTransaction(atCiteNode);
+            MOZ_KnownLive(HTMLEditorRef())
+                .InsertBrElementWithTransaction(atCiteNode);
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return NS_ERROR_EDITOR_DESTROYED;
         }
         if (NS_WARN_IF(!brElement)) {
           return NS_ERROR_FAILURE;
         }
         IgnoredErrorResult error;
         SelectionRefPtr()->Collapse(EditorRawDOMPoint(brElement), error);
@@ -4076,17 +4086,18 @@ nsresult HTMLEditRules::MakeList(nsAtom&
         // list item is in wrong type of list. if we don't have a curList,
         // split the old list and make a new list of correct type.
         if (!curList || EditorUtils::IsDescendantOf(*curNode, *curList)) {
           if (NS_WARN_IF(!atCurNode.GetContainerAsContent())) {
             return NS_ERROR_FAILURE;
           }
           ErrorResult error;
           nsCOMPtr<nsIContent> newLeftNode =
-              HTMLEditorRef().SplitNodeWithTransaction(atCurNode, error);
+              MOZ_KnownLive(HTMLEditorRef())
+                  .SplitNodeWithTransaction(atCurNode, error);
           if (NS_WARN_IF(!CanHandleEditAction())) {
             error.SuppressException();
             return NS_ERROR_EDITOR_DESTROYED;
           }
           if (NS_WARN_IF(error.Failed())) {
             return error.StealNSResult();
           }
           newBlock = newLeftNode ? newLeftNode->AsElement() : nullptr;
@@ -4437,29 +4448,30 @@ nsresult HTMLEditRules::MakeBasicBlock(n
           return NS_ERROR_EDITOR_DESTROYED;
         }
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       // Do the splits!
       SplitNodeResult splitNodeResult =
-          HTMLEditorRef().SplitNodeDeepWithTransaction(
-              *curBlock, pointToInsertBlock,
-              SplitAtEdges::eDoNotCreateEmptyContainer);
+          MOZ_KnownLive(HTMLEditorRef())
+              .SplitNodeDeepWithTransaction(
+                  *curBlock, pointToInsertBlock,
+                  SplitAtEdges::eDoNotCreateEmptyContainer);
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(splitNodeResult.Failed())) {
         return splitNodeResult.Rv();
       }
       EditorRawDOMPoint pointToInsertBrNode(splitNodeResult.SplitPoint());
       // Put a <br> element at the split point
-      brContent =
-          HTMLEditorRef().InsertBrElementWithTransaction(pointToInsertBrNode);
+      brContent = MOZ_KnownLive(HTMLEditorRef())
+                      .InsertBrElementWithTransaction(pointToInsertBrNode);
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(!brContent)) {
         return NS_ERROR_FAILURE;
       }
       // Put selection at the split point
       EditorRawDOMPoint atBrNode(brContent);
@@ -4567,17 +4579,18 @@ nsresult HTMLEditRules::DidMakeBasicBloc
   nsRange* firstRange = SelectionRefPtr()->GetRangeAt(0);
   if (NS_WARN_IF(!firstRange)) {
     return NS_ERROR_FAILURE;
   }
   const RangeBoundary& atStartOfSelection = firstRange->StartRef();
   if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
     return NS_ERROR_FAILURE;
   }
-  nsresult rv = InsertMozBRIfNeeded(*atStartOfSelection.Container());
+  nsresult rv =
+      InsertMozBRIfNeeded(MOZ_KnownLive(*atStartOfSelection.Container()));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult HTMLEditRules::WillIndent(bool* aCancel, bool* aHandled) {
   MOZ_ASSERT(IsEditorDataAvailable());
@@ -4800,18 +4813,18 @@ nsresult HTMLEditRules::IndentAroundSele
         sibling = HTMLEditorRef().GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList)) {
         nsAtom* containerName =
             atCurNode.GetContainer()->NodeInfo()->NameAtom();
         // Create a new nested list of correct type.
         SplitNodeResult splitNodeResult =
-            MaybeSplitAncestorsForInsertWithTransaction(*containerName,
-                                                        atCurNode);
+            MaybeSplitAncestorsForInsertWithTransaction(
+                MOZ_KnownLive(*containerName), atCurNode);
         if (NS_WARN_IF(splitNodeResult.Failed())) {
           return splitNodeResult.Rv();
         }
         curList = HTMLEditorRef().CreateNodeWithTransaction(
             *containerName, splitNodeResult.SplitPoint());
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return NS_ERROR_EDITOR_DESTROYED;
         }
@@ -5072,18 +5085,18 @@ nsresult HTMLEditRules::IndentAroundSele
         sibling = HTMLEditorRef().GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList)) {
         nsAtom* containerName =
             atCurNode.GetContainer()->NodeInfo()->NameAtom();
         // Create a new nested list of correct type.
         SplitNodeResult splitNodeResult =
-            MaybeSplitAncestorsForInsertWithTransaction(*containerName,
-                                                        atCurNode);
+            MaybeSplitAncestorsForInsertWithTransaction(
+                MOZ_KnownLive(*containerName), atCurNode);
         if (NS_WARN_IF(splitNodeResult.Failed())) {
           return splitNodeResult.Rv();
         }
         curList = HTMLEditorRef().CreateNodeWithTransaction(
             *containerName, splitNodeResult.SplitPoint());
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return NS_ERROR_EDITOR_DESTROYED;
         }
@@ -5134,18 +5147,18 @@ nsresult HTMLEditRules::IndentAroundSele
         EditorDOMPoint atListItem(listItem);
         if (NS_WARN_IF(!listItem)) {
           return NS_ERROR_FAILURE;
         }
         nsAtom* containerName =
             atListItem.GetContainer()->NodeInfo()->NameAtom();
         // Create a new nested list of correct type.
         SplitNodeResult splitNodeResult =
-            MaybeSplitAncestorsForInsertWithTransaction(*containerName,
-                                                        atListItem);
+            MaybeSplitAncestorsForInsertWithTransaction(
+                MOZ_KnownLive(*containerName), atListItem);
         if (NS_WARN_IF(splitNodeResult.Failed())) {
           return splitNodeResult.Rv();
         }
         curList = HTMLEditorRef().CreateNodeWithTransaction(
             *containerName, splitNodeResult.SplitPoint());
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return NS_ERROR_EDITOR_DESTROYED;
         }
@@ -5632,32 +5645,35 @@ SplitRangeOffFromNodeResult HTMLEditRule
 
   // aStartOfMiddleElement and aEndOfMiddleElement must be exclusive
   // descendants of aBlockElement.
   MOZ_ASSERT(EditorUtils::IsDescendantOf(aStartOfMiddleElement, aBlockElement));
   MOZ_ASSERT(EditorUtils::IsDescendantOf(aEndOfMiddleElement, aBlockElement));
 
   // Split at the start.
   SplitNodeResult splitAtStartResult =
-      HTMLEditorRef().SplitNodeDeepWithTransaction(
-          aBlockElement, EditorRawDOMPoint(&aStartOfMiddleElement),
-          SplitAtEdges::eDoNotCreateEmptyContainer);
+      MOZ_KnownLive(HTMLEditorRef())
+          .SplitNodeDeepWithTransaction(
+              aBlockElement, EditorRawDOMPoint(&aStartOfMiddleElement),
+              SplitAtEdges::eDoNotCreateEmptyContainer);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
   }
   NS_WARNING_ASSERTION(splitAtStartResult.Succeeded(),
                        "Failed to split aBlockElement at start");
 
   // Split at after the end
   EditorRawDOMPoint atAfterEnd(&aEndOfMiddleElement);
   DebugOnly<bool> advanced = atAfterEnd.AdvanceOffset();
   NS_WARNING_ASSERTION(advanced, "Failed to advance offset after the end node");
   SplitNodeResult splitAtEndResult =
-      HTMLEditorRef().SplitNodeDeepWithTransaction(
-          aBlockElement, atAfterEnd, SplitAtEdges::eDoNotCreateEmptyContainer);
+      MOZ_KnownLive(HTMLEditorRef())
+          .SplitNodeDeepWithTransaction(
+              aBlockElement, atAfterEnd,
+              SplitAtEdges::eDoNotCreateEmptyContainer);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
   }
   NS_WARNING_ASSERTION(splitAtEndResult.Succeeded(),
                        "Failed to split aBlockElement at after end");
 
   return SplitRangeOffFromNodeResult(splitAtStartResult, splitAtEndResult);
 }
@@ -5799,19 +5815,20 @@ nsresult HTMLEditRules::CreateStyleForIn
   item = HTMLEditorRef().mTypeInState->TakeSetProperty();
 
   if (item || relFontSize) {
     // we have at least one style to add; make a new text node to insert style
     // nodes above.
     if (RefPtr<Text> text = node->GetAsText()) {
       // if we are in a text node, split it
       SplitNodeResult splitTextNodeResult =
-          HTMLEditorRef().SplitNodeDeepWithTransaction(
-              *text, EditorRawDOMPoint(text, offset),
-              SplitAtEdges::eAllowToCreateEmptyContainer);
+          MOZ_KnownLive(HTMLEditorRef())
+              .SplitNodeDeepWithTransaction(
+                  *text, EditorRawDOMPoint(text, offset),
+                  SplitAtEdges::eAllowToCreateEmptyContainer);
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(splitTextNodeResult.Failed())) {
         return splitTextNodeResult.Rv();
       }
       EditorRawDOMPoint splitPoint(splitTextNodeResult.SplitPoint());
       node = splitPoint.GetContainer();
@@ -6344,17 +6361,18 @@ nsresult HTMLEditRules::MaybeDeleteTopMo
       EditorDOMPoint atBlockParent(blockParent);
       if (NS_WARN_IF(!atBlockParent.IsSet())) {
         return NS_ERROR_FAILURE;
       }
       // If the grand parent IS a list element, we'll adjust Selection in
       // AfterEdit().
       if (!HTMLEditUtils::IsList(atBlockParent.GetContainer())) {
         RefPtr<Element> brElement =
-            HTMLEditorRef().InsertBrElementWithTransaction(atBlockParent);
+            MOZ_KnownLive(HTMLEditorRef())
+                .InsertBrElementWithTransaction(atBlockParent);
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return NS_ERROR_EDITOR_DESTROYED;
         }
         if (NS_WARN_IF(!brElement)) {
           return NS_ERROR_FAILURE;
         }
         ErrorResult error;
         SelectionRefPtr()->Collapse(EditorRawDOMPoint(brElement), error);
@@ -7110,17 +7128,18 @@ nsresult HTMLEditRules::GetNodesForOpera
       if (NS_WARN_IF(!atEnd.IsSet()) || !atEnd.IsInTextNode()) {
         continue;
       }
 
       if (!atEnd.IsStartOfContainer() && !atEnd.IsEndOfContainer()) {
         // Split the text node.
         ErrorResult error;
         nsCOMPtr<nsIContent> newLeftNode =
-            HTMLEditorRef().SplitNodeWithTransaction(atEnd, error);
+            MOZ_KnownLive(HTMLEditorRef())
+                .SplitNodeWithTransaction(atEnd, error);
         if (NS_WARN_IF(!CanHandleEditAction())) {
           error.SuppressException();
           return NS_ERROR_EDITOR_DESTROYED;
         }
         if (NS_WARN_IF(error.Failed())) {
           return error.StealNSResult();
         }
 
@@ -7440,20 +7459,22 @@ nsresult HTMLEditRules::BustUpInlinesAtR
 
   nsCOMPtr<nsIContent> endInline =
       GetHighestInlineParent(*aRangeItem.mEndContainer);
 
   // XXX Oh, then, if the range is collapsed, we don't need to call
   //     GetHighestInlineParent(), isn't it?
   if (endInline && !isCollapsed) {
     SplitNodeResult splitEndInlineResult =
-        HTMLEditorRef().SplitNodeDeepWithTransaction(
-            *endInline,
-            EditorRawDOMPoint(aRangeItem.mEndContainer, aRangeItem.mEndOffset),
-            SplitAtEdges::eDoNotCreateEmptyContainer);
+        MOZ_KnownLive(HTMLEditorRef())
+            .SplitNodeDeepWithTransaction(
+                *endInline,
+                EditorRawDOMPoint(aRangeItem.mEndContainer,
+                                  aRangeItem.mEndOffset),
+                SplitAtEdges::eDoNotCreateEmptyContainer);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       return NS_ERROR_EDITOR_DESTROYED;
     }
     if (NS_WARN_IF(splitEndInlineResult.Failed())) {
       return splitEndInlineResult.Rv();
     }
     EditorRawDOMPoint splitPointAtEnd(splitEndInlineResult.SplitPoint());
     if (NS_WARN_IF(!splitPointAtEnd.IsSet())) {
@@ -7463,21 +7484,22 @@ nsresult HTMLEditRules::BustUpInlinesAtR
     aRangeItem.mEndOffset = splitPointAtEnd.Offset();
   }
 
   nsCOMPtr<nsIContent> startInline =
       GetHighestInlineParent(*aRangeItem.mStartContainer);
 
   if (startInline) {
     SplitNodeResult splitStartInlineResult =
-        HTMLEditorRef().SplitNodeDeepWithTransaction(
-            *startInline,
-            EditorRawDOMPoint(aRangeItem.mStartContainer,
-                              aRangeItem.mStartOffset),
-            SplitAtEdges::eDoNotCreateEmptyContainer);
+        MOZ_KnownLive(HTMLEditorRef())
+            .SplitNodeDeepWithTransaction(
+                *startInline,
+                EditorRawDOMPoint(aRangeItem.mStartContainer,
+                                  aRangeItem.mStartOffset),
+                SplitAtEdges::eDoNotCreateEmptyContainer);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       return NS_ERROR_EDITOR_DESTROYED;
     }
     if (NS_WARN_IF(splitStartInlineResult.Failed())) {
       return splitStartInlineResult.Rv();
     }
     // XXX If we split only here because of collapsed range, we're modifying
     //     only start point of aRangeItem.  Shouldn't we modify end point here
@@ -7512,18 +7534,20 @@ nsresult HTMLEditRules::BustUpInlinesAtB
   // Else we need to bust up aNode along all the breaks
   nsCOMPtr<nsIContent> nextNode = &aNode;
   for (OwningNonNull<nsINode>& brNode : arrayOfBreaks) {
     EditorRawDOMPoint atBrNode(brNode);
     if (NS_WARN_IF(!atBrNode.IsSet())) {
       return NS_ERROR_FAILURE;
     }
     SplitNodeResult splitNodeResult =
-        HTMLEditorRef().SplitNodeDeepWithTransaction(
-            *nextNode, atBrNode, SplitAtEdges::eAllowToCreateEmptyContainer);
+        MOZ_KnownLive(HTMLEditorRef())
+            .SplitNodeDeepWithTransaction(
+                *nextNode, atBrNode,
+                SplitAtEdges::eAllowToCreateEmptyContainer);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       return NS_ERROR_EDITOR_DESTROYED;
     }
     if (NS_WARN_IF(splitNodeResult.Failed())) {
       return splitNodeResult.Rv();
     }
 
     // Put previous node at the split point.
@@ -7706,19 +7730,20 @@ nsresult HTMLEditRules::ReturnInHeader(E
     return rv;
   }
   if (NS_WARN_IF(!node->IsContent())) {
     return NS_ERROR_FAILURE;
   }
 
   // Split the header
   SplitNodeResult splitHeaderResult =
-      HTMLEditorRef().SplitNodeDeepWithTransaction(
-          aHeader, EditorRawDOMPoint(node, aOffset),
-          SplitAtEdges::eAllowToCreateEmptyContainer);
+      MOZ_KnownLive(HTMLEditorRef())
+          .SplitNodeDeepWithTransaction(
+              aHeader, EditorRawDOMPoint(node, aOffset),
+              SplitAtEdges::eAllowToCreateEmptyContainer);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return NS_ERROR_EDITOR_DESTROYED;
   }
   NS_WARNING_ASSERTION(splitHeaderResult.Succeeded(),
                        "Failed to split aHeader");
 
   // If the previous heading of split point is empty, put a mozbr into it.
   nsCOMPtr<nsIContent> prevItem = HTMLEditorRef().GetPriorHTMLSibling(&aHeader);
@@ -7767,18 +7792,18 @@ nsresult HTMLEditRules::ReturnInHeader(E
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(!pNode)) {
         return NS_ERROR_FAILURE;
       }
 
       // Append a <br> to it
       RefPtr<Element> brElement =
-          HTMLEditorRef().InsertBrElementWithTransaction(
-              EditorRawDOMPoint(pNode, 0));
+          MOZ_KnownLive(HTMLEditorRef())
+              .InsertBrElementWithTransaction(EditorRawDOMPoint(pNode, 0));
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(!brElement)) {
         return NS_ERROR_FAILURE;
       }
 
       // Set selection to before the break
@@ -7937,18 +7962,18 @@ EditActionResult HTMLEditRules::ReturnIn
                              "Failed to advance offset to after the container "
                              "of selection start");
         brContent = nullptr;
       }
     } else {
       if (doesCRCreateNewP) {
         ErrorResult error;
         nsCOMPtr<nsIContent> newLeftDivOrP =
-            HTMLEditorRef().SplitNodeWithTransaction(pointToSplitParentDivOrP,
-                                                     error);
+            MOZ_KnownLive(HTMLEditorRef())
+                .SplitNodeWithTransaction(pointToSplitParentDivOrP, error);
         if (NS_WARN_IF(!CanHandleEditAction())) {
           error.SuppressException();
           return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
         }
         if (NS_WARN_IF(error.Failed())) {
           return EditActionResult(error.StealNSResult());
         }
         pointToSplitParentDivOrP.SetToEndOf(newLeftDivOrP);
@@ -7982,17 +8007,18 @@ EditActionResult HTMLEditRules::ReturnIn
     }
   }
   if (pointToInsertBR.IsSet()) {
     // if CR does not create a new P, default to BR creation
     if (NS_WARN_IF(!doesCRCreateNewP)) {
       return EditActionResult(NS_OK);
     }
 
-    brContent = HTMLEditorRef().InsertBrElementWithTransaction(pointToInsertBR);
+    brContent = MOZ_KnownLive(HTMLEditorRef())
+                    .InsertBrElementWithTransaction(pointToInsertBR);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
     }
     NS_WARNING_ASSERTION(brContent, "Failed to create a <br> element");
     if (splitAfterNewBR) {
       // We split the parent after the br we've just inserted.
       pointToSplitParentDivOrP.Set(brContent);
       DebugOnly<bool> advanced = pointToSplitParentDivOrP.AdvanceOffset();
@@ -8028,19 +8054,20 @@ nsresult HTMLEditRules::SplitParagraph(
     return rv;
   }
   if (NS_WARN_IF(!selNode->IsContent())) {
     return NS_ERROR_FAILURE;
   }
 
   // Split the paragraph.
   SplitNodeResult splitDivOrPResult =
-      HTMLEditorRef().SplitNodeDeepWithTransaction(
-          aParentDivOrP, EditorRawDOMPoint(selNode, selOffset),
-          SplitAtEdges::eAllowToCreateEmptyContainer);
+      MOZ_KnownLive(HTMLEditorRef())
+          .SplitNodeDeepWithTransaction(
+              aParentDivOrP, EditorRawDOMPoint(selNode, selOffset),
+              SplitAtEdges::eAllowToCreateEmptyContainer);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return NS_ERROR_EDITOR_DESTROYED;
   }
   if (NS_WARN_IF(splitDivOrPResult.Failed())) {
     return splitDivOrPResult.Rv();
   }
   if (NS_WARN_IF(!splitDivOrPResult.DidSplit())) {
     return NS_ERROR_FAILURE;
@@ -8069,21 +8096,21 @@ nsresult HTMLEditRules::SplitParagraph(
   }
 
   // We need to ensure to both paragraphs visible even if they are empty.
   // However, moz-<br> element isn't useful in this case because moz-<br>
   // elements will be ignored by PlaintextSerializer.  Additionally,
   // moz-<br> will be exposed as <br> with Element.innerHTML.  Therefore,
   // we can use normal <br> elements for placeholder in this case.
   // Note that Chromium also behaves so.
-  rv = InsertBRIfNeeded(*splitDivOrPResult.GetPreviousNode());
+  rv = InsertBRIfNeeded(MOZ_KnownLive(*splitDivOrPResult.GetPreviousNode()));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
-  rv = InsertBRIfNeeded(*splitDivOrPResult.GetNextNode());
+  rv = InsertBRIfNeeded(MOZ_KnownLive(*splitDivOrPResult.GetNextNode()));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // selection to beginning of right hand para;
   // look inside any containers that are up front.
   nsIContent* child = HTMLEditorRef().GetLeftmostChild(&aParentDivOrP, true);
   if (EditorBase::IsTextNode(child) || HTMLEditorRef().IsContainer(child)) {
@@ -8123,18 +8150,18 @@ nsresult HTMLEditRules::ReturnInListItem
   if (mReturnInEmptyLIKillsList && host != aListItem.GetParentElement() &&
       IsEmptyBlockElement(aListItem, IgnoreSingleBR::eYes)) {
     nsCOMPtr<nsIContent> leftListNode = aListItem.GetParent();
     // Are we the last list item in the list?
     if (!HTMLEditorRef().IsLastEditableChild(&aListItem)) {
       // We need to split the list!
       EditorRawDOMPoint atListItem(&aListItem);
       ErrorResult error;
-      leftListNode =
-          HTMLEditorRef().SplitNodeWithTransaction(atListItem, error);
+      leftListNode = MOZ_KnownLive(HTMLEditorRef())
+                         .SplitNodeWithTransaction(atListItem, error);
       if (NS_WARN_IF(!CanHandleEditAction())) {
         error.SuppressException();
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(error.Failed())) {
         return error.StealNSResult();
       }
     }
@@ -8185,18 +8212,18 @@ nsresult HTMLEditRules::ReturnInListItem
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(!pNode)) {
         return NS_ERROR_FAILURE;
       }
 
       // Append a <br> to it
       RefPtr<Element> brElement =
-          HTMLEditorRef().InsertBrElementWithTransaction(
-              EditorRawDOMPoint(pNode, 0));
+          MOZ_KnownLive(HTMLEditorRef())
+              .InsertBrElementWithTransaction(EditorRawDOMPoint(pNode, 0));
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(!brElement)) {
         return NS_ERROR_FAILURE;
       }
 
       // Set selection to before the break
@@ -8225,19 +8252,20 @@ nsresult HTMLEditRules::ReturnInListItem
     return rv;
   }
   if (NS_WARN_IF(!selNode->IsContent())) {
     return NS_ERROR_FAILURE;
   }
 
   // Now split the list item.
   SplitNodeResult splitListItemResult =
-      HTMLEditorRef().SplitNodeDeepWithTransaction(
-          aListItem, EditorRawDOMPoint(selNode, aOffset),
-          SplitAtEdges::eAllowToCreateEmptyContainer);
+      MOZ_KnownLive(HTMLEditorRef())
+          .SplitNodeDeepWithTransaction(
+              aListItem, EditorRawDOMPoint(selNode, aOffset),
+              SplitAtEdges::eAllowToCreateEmptyContainer);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return NS_ERROR_EDITOR_DESTROYED;
   }
   NS_WARNING_ASSERTION(splitListItemResult.Succeeded(),
                        "Failed to split the list item");
 
   // Hack: until I can change the damaged doc range code back to being
   // extra-inclusive, I have to manually detect certain list items that may be
@@ -8779,17 +8807,17 @@ SplitNodeResult HTMLEditRules::MaybeSpli
   // The point must be descendant of editing host.
   if (NS_WARN_IF(aStartOfDeepestRightNode.GetContainer() != host &&
                  !EditorUtils::IsDescendantOf(
                      *aStartOfDeepestRightNode.GetContainer(), *host))) {
     return SplitNodeResult(NS_ERROR_INVALID_ARG);
   }
 
   // Look for a node that can legally contain the tag.
-  EditorRawDOMPoint pointToInsert(aStartOfDeepestRightNode);
+  EditorDOMPoint pointToInsert(aStartOfDeepestRightNode);
   for (; pointToInsert.IsSet();
        pointToInsert.Set(pointToInsert.GetContainer())) {
     // We cannot split active editing host and its ancestor.  So, there is
     // no element to contain the specified element.
     if (NS_WARN_IF(pointToInsert.GetChild() == host)) {
       return SplitNodeResult(NS_ERROR_FAILURE);
     }
 
@@ -8804,19 +8832,21 @@ SplitNodeResult HTMLEditRules::MaybeSpli
   // If the point itself can contain the tag, we don't need to split any
   // ancestor nodes.  In this case, we should return the given split point
   // as is.
   if (pointToInsert.GetContainer() == aStartOfDeepestRightNode.GetContainer()) {
     return SplitNodeResult(aStartOfDeepestRightNode);
   }
 
   SplitNodeResult splitNodeResult =
-      HTMLEditorRef().SplitNodeDeepWithTransaction(
-          *pointToInsert.GetChild(), aStartOfDeepestRightNode,
-          SplitAtEdges::eAllowToCreateEmptyContainer);
+      MOZ_KnownLive(HTMLEditorRef())
+          .SplitNodeDeepWithTransaction(
+              MOZ_KnownLive(*pointToInsert.GetChild()),
+              aStartOfDeepestRightNode,
+              SplitAtEdges::eAllowToCreateEmptyContainer);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return SplitNodeResult(NS_ERROR_EDITOR_DESTROYED);
   }
   NS_WARNING_ASSERTION(splitNodeResult.Succeeded(),
                        "Failed to split the node for insert the element");
   return splitNodeResult;
 }
 
@@ -9587,18 +9617,18 @@ nsresult HTMLEditRules::RemoveEmptyNodes
     rv = HTMLEditorRef().IsEmptyNode(delNode, &isEmptyNode, false, true);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     if (!isEmptyNode) {
       // We are deleting a cite that has just a br.  We want to delete cite,
       // but preserve br.
       RefPtr<Element> brElement =
-          HTMLEditorRef().InsertBrElementWithTransaction(
-              EditorRawDOMPoint(delNode));
+          MOZ_KnownLive(HTMLEditorRef())
+              .InsertBrElementWithTransaction(EditorRawDOMPoint(delNode));
       if (NS_WARN_IF(!CanHandleEditAction())) {
         return NS_ERROR_EDITOR_DESTROYED;
       }
       if (NS_WARN_IF(!brElement)) {
         return NS_ERROR_FAILURE;
       }
     }
     rv = MOZ_KnownLive(HTMLEditorRef()).DeleteNodeWithTransaction(*delNode);
@@ -9719,17 +9749,18 @@ nsresult HTMLEditRules::PopListItem(nsIC
   nsCOMPtr<nsIContent> listItem(&aListItem);
   if (!isFirstListItem && !isLastListItem) {
     EditorDOMPoint atListItem(listItem);
     if (NS_WARN_IF(!atListItem.IsSet())) {
       return NS_ERROR_INVALID_ARG;
     }
     MOZ_ASSERT(atListItem.IsSetAndValid());
     ErrorResult error;
-    leftListNode = HTMLEditorRef().SplitNodeWithTransaction(atListItem, error);
+    leftListNode = MOZ_KnownLive(HTMLEditorRef())
+                       .SplitNodeWithTransaction(atListItem, error);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       error.SuppressException();
       return NS_ERROR_EDITOR_DESTROYED;
     }
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
   }
@@ -10309,17 +10340,18 @@ nsresult HTMLEditRules::MakeSureElemStar
   if (!foundCR) {
     EditorRawDOMPoint pointToInsert;
     if (!aStarts) {
       pointToInsert.SetToEndOf(&aNode);
     } else {
       pointToInsert.Set(&aNode, 0);
     }
     RefPtr<Element> brElement =
-        HTMLEditorRef().InsertBrElementWithTransaction(pointToInsert);
+        MOZ_KnownLive(HTMLEditorRef())
+            .InsertBrElementWithTransaction(pointToInsert);
     if (NS_WARN_IF(!CanHandleEditAction())) {
       return NS_ERROR_EDITOR_DESTROYED;
     }
     if (NS_WARN_IF(!brElement)) {
       return NS_ERROR_FAILURE;
     }
   }
   return NS_OK;
@@ -10615,18 +10647,18 @@ nsresult HTMLEditRules::PrepareToMakeEle
         sibling = HTMLEditorRef().GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList)) {
         nsAtom* containerName =
             atCurNode.GetContainer()->NodeInfo()->NameAtom();
         // Create a new nested list of correct type.
         SplitNodeResult splitNodeResult =
-            MaybeSplitAncestorsForInsertWithTransaction(*containerName,
-                                                        atCurNode);
+            MaybeSplitAncestorsForInsertWithTransaction(
+                MOZ_KnownLive(*containerName), atCurNode);
         if (NS_WARN_IF(splitNodeResult.Failed())) {
           return splitNodeResult.Rv();
         }
         if (!curPositionedDiv) {
           curPositionedDiv = HTMLEditorRef().CreateNodeWithTransaction(
               *nsGkAtoms::div, splitNodeResult.SplitPoint());
           if (NS_WARN_IF(!CanHandleEditAction())) {
             return NS_ERROR_EDITOR_DESTROYED;
@@ -10684,18 +10716,18 @@ nsresult HTMLEditRules::PrepareToMakeEle
         EditorDOMPoint atListItem(listItem);
         if (NS_WARN_IF(!atListItem.IsSet())) {
           return NS_ERROR_FAILURE;
         }
         nsAtom* containerName =
             atListItem.GetContainer()->NodeInfo()->NameAtom();
         // Create a new nested list of correct type
         SplitNodeResult splitNodeResult =
-            MaybeSplitAncestorsForInsertWithTransaction(*containerName,
-                                                        atListItem);
+            MaybeSplitAncestorsForInsertWithTransaction(
+                MOZ_KnownLive(*containerName), atListItem);
         if (NS_WARN_IF(splitNodeResult.Failed())) {
           return splitNodeResult.Rv();
         }
         if (!curPositionedDiv) {
           EditorRawDOMPoint atListItemParent(atListItem.GetContainer());
           curPositionedDiv = HTMLEditorRef().CreateNodeWithTransaction(
               *nsGkAtoms::div, atListItemParent);
           if (NS_WARN_IF(!CanHandleEditAction())) {
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -117,16 +117,17 @@ class HTMLEditRules : public TextEditRul
    * MakeSureElemStartsAndEndsOnCR() inserts <br> element at start (and/or end)
    * of aNode if neither:
    * - first (last) editable child of aNode is a block or a <br>,
    * - previous (next) sibling of aNode is block or a <br>
    * - nor no previous (next) sibling of aNode.
    *
    * @param aNode               The node which may be inserted <br> elements.
    */
+  MOZ_CAN_RUN_SCRIPT
   MOZ_MUST_USE nsresult MakeSureElemStartsAndEndsOnCR(nsINode& aNode);
 
   void DidCreateNode(Element& aNewElement);
   void DidInsertNode(nsIContent& aNode);
   void WillDeleteNode(nsINode& aChild);
   void DidSplitNode(nsINode& aExistingRightNode, nsINode& aNewLeftNode);
   void WillJoinNodes(nsINode& aLeftNode, nsINode& aRightNode);
   void DidJoinNodes(nsINode& aLeftNode, nsINode& aRightNode);
@@ -257,50 +258,51 @@ class HTMLEditRules : public TextEditRul
    */
   MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidDeleteSelection();
 
   /**
    * InsertBRIfNeeded() determines if a br is needed for current selection to
    * not be spastic.  If so, it inserts one.  Callers responsibility to only
    * call with collapsed selection.
    */
-  MOZ_MUST_USE nsresult InsertBRIfNeeded();
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult InsertBRIfNeeded();
 
   /**
    * CanContainParagraph() returns true if aElement can have a <p> element as
    * its child or its descendant.
    */
   bool CanContainParagraph(Element& aElement) const;
 
   /**
    * Insert normal <br> element into aNode when aNode is a block and it has
    * no children.
    */
-  MOZ_MUST_USE nsresult InsertBRIfNeeded(nsINode& aNode) {
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult InsertBRIfNeeded(nsINode& aNode) {
     return InsertBRIfNeededInternal(aNode, false);
   }
 
   /**
    * Insert moz-<br> element (<br type="_moz">) into aNode when aNode is a
    * block and it has no children.
    */
-  MOZ_MUST_USE nsresult InsertMozBRIfNeeded(nsINode& aNode) {
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult InsertMozBRIfNeeded(nsINode& aNode) {
     return InsertBRIfNeededInternal(aNode, true);
   }
 
   /**
    * Insert a normal <br> element or a moz-<br> element to aNode when
    * aNode is a block and it has no children.  Use InsertBRIfNeeded() or
    * InsertMozBRIfNeeded() instead.
    *
    * @param aNode           Reference to a block parent.
    * @param aInsertMozBR    true if this should insert a moz-<br> element.
    *                        Otherwise, i.e., this should insert a normal <br>
    *                        element, false.
    */
+  MOZ_CAN_RUN_SCRIPT
   MOZ_MUST_USE nsresult InsertBRIfNeededInternal(nsINode& aNode,
                                                  bool aInsertMozBR);
 
   /**
    * GetGoodSelPointForNode() finds where at a node you would want to set the
    * selection if you were trying to have a caret next to it.  Always returns a
    * valid value (unless mHTMLEditor has gone away).
    *
@@ -535,17 +537,17 @@ class HTMLEditRules : public TextEditRul
   MOZ_CAN_RUN_SCRIPT
   MOZ_MUST_USE nsresult MakeBasicBlock(nsAtom& aBlockType);
 
   /**
    * Called after creating a basic block, indenting, outdenting or aligning
    * contents.  This method inserts moz-<br> element if start container of
    * Selection needs it.
    */
-  MOZ_MUST_USE nsresult DidMakeBasicBlock();
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidMakeBasicBlock();
 
   /**
    * Called before changing an element to absolute positioned.
    * This method only prepares the operation since DidAbsolutePosition() will
    * change it actually later.  mNewBlock is set to the target element and
    * if necessary, some ancestor nodes of selection may be split.
    *
    * @param aCancel             Returns true if the operation is canceled.
@@ -778,16 +780,17 @@ class HTMLEditRules : public TextEditRul
    * SplitRangeOffFromBlock() splits aBlock at two points, before aStartChild
    * and after aEndChild.  If they are very start or very end of aBlcok, this
    * won't create empty block.
    *
    * @param aBlockElement           A block element which will be split.
    * @param aStartOfMiddleElement   Start node of middle block element.
    * @param aEndOfMiddleElement     End node of middle block element.
    */
+  MOZ_CAN_RUN_SCRIPT
   MOZ_MUST_USE SplitRangeOffFromNodeResult SplitRangeOffFromBlock(
       Element& aBlockElement, nsIContent& aStartOfMiddleElement,
       nsIContent& aEndOfMiddleElement);
 
   /**
    * OutdentPartOfBlock() outdents the nodes between aStartOfOutdent and
    * aEndOfOutdent.  This splits the range off from aBlockElement first.
    * Then, removes the middle element if aIsBlockIndentedWithCSS is false.
@@ -985,16 +988,17 @@ class HTMLEditRules : public TextEditRul
    * aRangeItem.  If this splits at every point, this modifies aRangeItem
    * to point each split point (typically, right node).  Note that this splits
    * nodes only in highest inline element at every point.
    *
    * @param aRangeItem          One or two DOM points where should be split.
    *                            Will be modified to split point if they're
    *                            split.
    */
+  MOZ_CAN_RUN_SCRIPT
   MOZ_MUST_USE nsresult BustUpInlinesAtRangeEndpoints(RangeItem& aRangeItem);
 
   /**
    * BustUpInlinesAtBRs() splits before all <br> elements in aNode.  All <br>
    * nodes will be moved before right node at splitting its parent.  Finally,
    * this returns all <br> elements, every left node and aNode with
    * aOutArrayNodes.
    *
@@ -1079,17 +1083,18 @@ class HTMLEditRules : public TextEditRul
    *                                    after calling this method.
    * @param aStartOfDeepestRightNode    The start point of deepest right node.
    *                                    This point must be descendant of
    *                                    active editing host.
    * @return                            When succeeded, SplitPoint() returns
    *                                    the point to insert the element.
    */
   template <typename PT, typename CT>
-  MOZ_MUST_USE SplitNodeResult MaybeSplitAncestorsForInsertWithTransaction(
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE SplitNodeResult
+  MaybeSplitAncestorsForInsertWithTransaction(
       nsAtom& aTag, const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode);
 
   /**
    * JoinNearestEditableNodesWithTransaction() joins two editable nodes which
    * are themselves or the nearest editable node of aLeftNode and aRightNode.
    * XXX This method's behavior is odd.  For example, if user types Backspace
    *     key at the second editable paragraph in this case:
    *     <div contenteditable>
@@ -1164,17 +1169,17 @@ class HTMLEditRules : public TextEditRul
   MOZ_MUST_USE nsresult ReapplyCachedStyles();
 
   void ClearCachedStyles();
 
   /**
    * InsertBRElementToEmptyListItemsAndTableCellsInChangedRange() inserts
    * <br> element into empty list item or table cell elements.
    */
-  MOZ_MUST_USE nsresult
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
   InsertBRElementToEmptyListItemsAndTableCellsInChangedRange();
 
   /**
    * PinSelectionToNewBlock() may collapse Selection around mNewNode if it's
    * necessary,
    */
   MOZ_MUST_USE nsresult PinSelectionToNewBlock();
 
@@ -1182,17 +1187,18 @@ class HTMLEditRules : public TextEditRul
 
   /**
    * AdjustSelection() may adjust Selection range to nearest editable content.
    * Despite of the name, this may change the DOM tree.  If it needs to create
    * a <br> to put caret, this tries to create a <br> element.
    *
    * @param aAction     Maybe used to look for a good point to put caret.
    */
-  MOZ_MUST_USE nsresult AdjustSelection(nsIEditor::EDirection aAction);
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
+  AdjustSelection(nsIEditor::EDirection aAction);
 
   /**
    * FindNearEditableNode() tries to find an editable node near aPoint.
    *
    * @param aPoint      The DOM point where to start to search from.
    * @param aDirection  If nsIEditor::ePrevious is set, this searches an
    *                    editable node from next nodes.  Otherwise, from
    *                    previous nodes.
@@ -1273,16 +1279,17 @@ class HTMLEditRules : public TextEditRul
    * - first (last) editable child of aNode is a block or a <br>,
    * - previous (next) sibling of aNode is block or a <br>
    * - nor no previous (next) sibling of aNode.
    *
    * @param aNode               The node which may be inserted <br> element.
    * @param aStarts             true for trying to insert <br> to the start.
    *                            false for trying to insert <br> to the end.
    */
+  MOZ_CAN_RUN_SCRIPT
   MOZ_MUST_USE nsresult MakeSureElemStartsOrEndsOnCR(nsINode& aNode,
                                                      bool aStarts);
 
   /**
    * AlignBlock() resets align attribute, text-align property, etc first.
    * Then, aligns contents of aElement on aAlignType.
    *
    * @param aElement            The element whose contents will be aligned.
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1687,18 +1687,19 @@ EditorDOMPoint HTMLEditor::InsertNodeInt
       pointToInsert = aPointToInsert;
       break;
     }
   }
 
   if (pointToInsert != aPointToInsert) {
     // We need to split some levels above the original selection parent.
     MOZ_ASSERT(pointToInsert.GetChild());
-    SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
-        *pointToInsert.GetChild(), aPointToInsert, aSplitAtEdges);
+    SplitNodeResult splitNodeResult =
+        SplitNodeDeepWithTransaction(MOZ_KnownLive(*pointToInsert.GetChild()),
+                                     aPointToInsert, aSplitAtEdges);
     if (NS_WARN_IF(splitNodeResult.Failed())) {
       return EditorDOMPoint();
     }
     pointToInsert = splitNodeResult.SplitPoint();
     MOZ_ASSERT(pointToInsert.IsSet());
   }
 
   {
@@ -2134,17 +2135,17 @@ HTMLEditor::MakeOrChangeList(const nsASt
           NS_WARN_IF(!pointToInsertList.GetContainerAsContent())) {
         return NS_ERROR_FAILURE;
       }
     }
 
     if (pointToInsertList.GetContainer() != atStartOfSelection.GetContainer()) {
       // We need to split up to the child of parent.
       SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
-          *pointToInsertList.GetChild(), atStartOfSelection,
+          MOZ_KnownLive(*pointToInsertList.GetChild()), atStartOfSelection,
           SplitAtEdges::eAllowToCreateEmptyContainer);
       if (NS_WARN_IF(splitNodeResult.Failed())) {
         return splitNodeResult.Rv();
       }
       pointToInsertList = splitNodeResult.SplitPoint();
       if (NS_WARN_IF(!pointToInsertList.IsSet())) {
         return NS_ERROR_FAILURE;
       }
@@ -2311,17 +2312,17 @@ nsresult HTMLEditor::InsertBasicBlockWit
         return NS_ERROR_FAILURE;
       }
     }
 
     if (pointToInsertBlock.GetContainer() !=
         atStartOfSelection.GetContainer()) {
       // We need to split up to the child of the point to insert a block.
       SplitNodeResult splitBlockResult = SplitNodeDeepWithTransaction(
-          *pointToInsertBlock.GetChild(), atStartOfSelection,
+          MOZ_KnownLive(*pointToInsertBlock.GetChild()), atStartOfSelection,
           SplitAtEdges::eAllowToCreateEmptyContainer);
       if (NS_WARN_IF(splitBlockResult.Failed())) {
         return splitBlockResult.Rv();
       }
       pointToInsertBlock = splitBlockResult.SplitPoint();
       if (NS_WARN_IF(!pointToInsertBlock.IsSet())) {
         return NS_ERROR_FAILURE;
       }
@@ -2452,18 +2453,18 @@ nsresult HTMLEditor::IndentOrOutdentAsSu
         return NS_ERROR_FAILURE;
       }
     }
 
     if (pointToInsertBlockquote.GetContainer() !=
         atStartOfSelection.GetContainer()) {
       // We need to split up to the child of parent.
       SplitNodeResult splitBlockquoteResult = SplitNodeDeepWithTransaction(
-          *pointToInsertBlockquote.GetChild(), atStartOfSelection,
-          SplitAtEdges::eAllowToCreateEmptyContainer);
+          MOZ_KnownLive(*pointToInsertBlockquote.GetChild()),
+          atStartOfSelection, SplitAtEdges::eAllowToCreateEmptyContainer);
       if (NS_WARN_IF(splitBlockquoteResult.Failed())) {
         return splitBlockquoteResult.Rv();
       }
       pointToInsertBlockquote = splitBlockquoteResult.SplitPoint();
       if (NS_WARN_IF(!pointToInsertBlockquote.IsSet())) {
         return NS_ERROR_FAILURE;
       }
     }
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -203,18 +203,18 @@ class HTMLEditor final : public TextEdit
    * @return                    Newly created element.
    */
   MOZ_CAN_RUN_SCRIPT
   already_AddRefed<Element> CreateElementWithDefaults(const nsAtom& aTagName);
 
   /**
    * Indent or outdent content around Selection.
    */
-  nsresult IndentAsAction();
-  nsresult OutdentAsAction();
+  MOZ_CAN_RUN_SCRIPT nsresult IndentAsAction();
+  MOZ_CAN_RUN_SCRIPT nsresult OutdentAsAction();
 
   /**
    * event callback when a mouse button is pressed
    * @param aX      [IN] horizontal position of the pointer
    * @param aY      [IN] vertical position of the pointer
    * @param aTarget [IN] the element triggering the event
    * @param aMouseEvent [IN] the event
    */
@@ -783,16 +783,17 @@ class HTMLEditor final : public TextEdit
   nsresult RelativeFontChangeOnTextNode(FontSize aDir, Text& aTextNode,
                                         int32_t aStartOffset,
                                         int32_t aEndOffset);
 
   MOZ_CAN_RUN_SCRIPT
   nsresult SetInlinePropertyOnNode(nsIContent& aNode, nsAtom& aProperty,
                                    nsAtom* aAttribute, const nsAString& aValue);
 
+  MOZ_CAN_RUN_SCRIPT
   nsresult SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
                                 nsAtom* aProperty, nsAtom* aAttribute,
                                 nsIContent** aOutLeftNode = nullptr,
                                 nsIContent** aOutRightNode = nullptr);
 
   nsIContent* GetPriorHTMLSibling(nsINode* aNode);
 
   nsIContent* GetNextHTMLSibling(nsINode* aNode);
@@ -946,19 +947,18 @@ class HTMLEditor final : public TextEdit
   nsresult GetInlinePropertyBase(nsAtom& aProperty, nsAtom* aAttribute,
                                  const nsAString* aValue, bool* aFirst,
                                  bool* aAny, bool* aAll, nsAString* outValue);
 
   MOZ_CAN_RUN_SCRIPT
   nsresult ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
                       nsAtom* aProperty, nsAtom* aAttribute);
 
-  nsresult SetPositionToAbsolute(Element& aElement);
-  MOZ_CAN_RUN_SCRIPT
-  nsresult SetPositionToStatic(Element& aElement);
+  MOZ_CAN_RUN_SCRIPT nsresult SetPositionToAbsolute(Element& aElement);
+  MOZ_CAN_RUN_SCRIPT nsresult SetPositionToStatic(Element& aElement);
 
   /**
    * OnModifyDocument() is called when the editor is changed.  This should
    * be called only by HTMLEditRules::DocumentModifiedWorker() to call
    * HTMLEditRules::OnModifyDocument() with AutoEditActionDataSetter
    * instance.
    */
   MOZ_CAN_RUN_SCRIPT void OnModifyDocument();
@@ -1505,16 +1505,17 @@ class HTMLEditor final : public TextEdit
   /**
    * IndentOrOutdentAsSubAction() indents or outdents the content around
    * Selection.  Callers have to guarantee that there is a placeholder
    * transaction.
    *
    * @param aEditSubAction      Must be EditSubAction::eIndent or
    *                            EditSubAction::eOutdent.
    */
+  MOZ_CAN_RUN_SCRIPT
   nsresult IndentOrOutdentAsSubAction(EditSubAction aEditSubAction);
 
   MOZ_CAN_RUN_SCRIPT
   nsresult LoadHTML(const nsAString& aInputString);
 
   MOZ_CAN_RUN_SCRIPT
   nsresult SetInlinePropertyInternal(nsAtom& aProperty, nsAtom* aAttribute,
                                      const nsAString& aValue);
@@ -2080,16 +2081,17 @@ class HTMLEditor final : public TextEdit
 
   /**
    * InsertBasicBlockWithTransaction() inserts a block element whose name
    * is aTagName at selection.
    *
    * @param aTagName            A block level element name.  Must NOT be
    *                            nsGkAtoms::dt nor nsGkAtoms::dd.
    */
+  MOZ_CAN_RUN_SCRIPT
   nsresult InsertBasicBlockWithTransaction(nsAtom& aTagName);
 
   /**
    * Increase/decrease the font size of selection.
    */
   MOZ_CAN_RUN_SCRIPT
   nsresult RelativeFontChange(FontSize aDir);
 
@@ -2104,16 +2106,17 @@ class HTMLEditor final : public TextEdit
   MOZ_CAN_RUN_SCRIPT
   nsresult SetInlinePropertyOnTextNode(Text& aData, int32_t aStartOffset,
                                        int32_t aEndOffset, nsAtom& aProperty,
                                        nsAtom* aAttribute,
                                        const nsAString& aValue);
 
   nsresult PromoteInlineRange(nsRange& aRange);
   nsresult PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange);
+  MOZ_CAN_RUN_SCRIPT
   nsresult SplitStyleAboveRange(nsRange* aRange, nsAtom* aProperty,
                                 nsAtom* aAttribute);
   MOZ_CAN_RUN_SCRIPT
   nsresult RemoveStyleInside(nsIContent& aNode, nsAtom* aProperty,
                              nsAtom* aAttribute,
                              const bool aChildrenOnly = false);
 
   bool IsAtFrontOfNode(nsINode& aNode, int32_t aOffset);
--- a/editor/libeditor/HTMLEditorCommands.cpp
+++ b/editor/libeditor/HTMLEditorCommands.cpp
@@ -434,17 +434,17 @@ bool IndentCommand::IsCommandEnabled(Com
 }
 
 nsresult IndentCommand::DoCommand(Command aCommand,
                                   TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_OK;
   }
-  nsresult rv = htmlEditor->IndentAsAction();
+  nsresult rv = MOZ_KnownLive(htmlEditor)->IndentAsAction();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult IndentCommand::DoCommandParams(Command aCommand,
                                         nsCommandParams* aParams,
@@ -478,17 +478,17 @@ bool OutdentCommand::IsCommandEnabled(Co
 }
 
 nsresult OutdentCommand::DoCommand(Command aCommand,
                                    TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_OK;
   }
-  nsresult rv = htmlEditor->OutdentAsAction();
+  nsresult rv = MOZ_KnownLive(htmlEditor)->OutdentAsAction();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult OutdentCommand::DoCommandParams(Command aCommand,
                                          nsCommandParams* aParams,
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -345,17 +345,17 @@ nsresult HTMLEditor::DoInsertHTMLWithCon
     }
 
     // Remember if we are in a link.
     bool bStartedInLink = !!GetLinkElement(pointToInsert.GetContainer());
 
     // Are we in a text node? If so, split it.
     if (pointToInsert.IsInTextNode()) {
       SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
-          *pointToInsert.GetContainerAsContent(), pointToInsert,
+          MOZ_KnownLive(*pointToInsert.GetContainerAsContent()), pointToInsert,
           SplitAtEdges::eAllowToCreateEmptyContainer);
       if (NS_WARN_IF(splitNodeResult.Failed())) {
         return splitNodeResult.Rv();
       }
       pointToInsert = splitNodeResult.SplitPoint();
       if (NS_WARN_IF(!pointToInsert.IsSet())) {
         return NS_ERROR_FAILURE;
       }
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1775,17 +1775,18 @@ CreateElementResult TextEditRules::Creat
     const EditorDOMPointBase<PT, CT>& aPointToInsert, bool aCreateMozBR) {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   if (NS_WARN_IF(!aPointToInsert.IsSet())) {
     return CreateElementResult(NS_ERROR_FAILURE);
   }
 
   RefPtr<Element> brElement =
-      TextEditorRef().InsertBrElementWithTransaction(aPointToInsert);
+      MOZ_KnownLive(TextEditorRef())
+          .InsertBrElementWithTransaction(aPointToInsert);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return CreateElementResult(NS_ERROR_EDITOR_DESTROYED);
   }
   if (NS_WARN_IF(!brElement)) {
     return CreateElementResult(NS_ERROR_FAILURE);
   }
 
   // give it special moz attr
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -279,23 +279,22 @@ class TextEditRules : public nsITimerCal
   /**
    * Check for and replace a redundant trailing break.
    */
   MOZ_MUST_USE nsresult RemoveRedundantTrailingBR();
 
   /**
    * Creates a trailing break in the text doc if there is not one already.
    */
-  MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
 
   /**
    * Creates a bogus <br> node if the root element has no editable content.
    */
-  MOZ_CAN_RUN_SCRIPT
-  MOZ_MUST_USE nsresult CreateBogusNodeIfNeeded();
+  MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult CreateBogusNodeIfNeeded();
 
   /**
    * Returns a truncated insertion string if insertion would place us over
    * aMaxLength
    */
   nsresult TruncateInsertionIfNeeded(const nsAString* aInString,
                                      nsAString* aOutString, int32_t aMaxLength,
                                      bool* aTruncated);
@@ -309,18 +308,18 @@ class TextEditRules : public nsITimerCal
    * Create a normal <br> element and insert it to aPointToInsert.
    *
    * @param aPointToInsert  The point where the new <br> element will be
    *                        inserted.
    * @return                Returns created <br> element or an error code
    *                        if couldn't create new <br> element.
    */
   template <typename PT, typename CT>
-  CreateElementResult CreateBR(
-      const EditorDOMPointBase<PT, CT>& aPointToInsert) {
+  MOZ_CAN_RUN_SCRIPT CreateElementResult
+  CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert) {
     CreateElementResult ret = CreateBRInternal(aPointToInsert, false);
 #ifdef DEBUG
     // If editor is destroyed, it must return NS_ERROR_EDITOR_DESTROYED.
     if (!CanHandleEditAction()) {
       MOZ_ASSERT(ret.Rv() == NS_ERROR_EDITOR_DESTROYED);
     }
 #endif  // #ifdef DEBUG
     return ret;
@@ -330,18 +329,18 @@ class TextEditRules : public nsITimerCal
    * Create a moz-<br> element and insert it to aPointToInsert.
    *
    * @param aPointToInsert  The point where the new moz-<br> element will be
    *                        inserted.
    * @return                Returns created <br> element or an error code
    *                        if couldn't create new <br> element.
    */
   template <typename PT, typename CT>
-  CreateElementResult CreateMozBR(
-      const EditorDOMPointBase<PT, CT>& aPointToInsert) {
+  MOZ_CAN_RUN_SCRIPT CreateElementResult
+  CreateMozBR(const EditorDOMPointBase<PT, CT>& aPointToInsert) {
     CreateElementResult ret = CreateBRInternal(aPointToInsert, true);
 #ifdef DEBUG
     // If editor is destroyed, it must return NS_ERROR_EDITOR_DESTROYED.
     if (!CanHandleEditAction()) {
       MOZ_ASSERT(ret.Rv() == NS_ERROR_EDITOR_DESTROYED);
     }
 #endif  // #ifdef DEBUG
     return ret;
@@ -388,17 +387,17 @@ class TextEditRules : public nsITimerCal
    * @param aParentToInsert     The point where the new <br> element will be
    *                            inserted.
    * @param aCreateMozBR        true if the caller wants to create a moz-<br>
    *                            element.  Otherwise, false.
    * @return                    Returns created <br> element and error code.
    *                            If it succeeded, never returns nullptr.
    */
   template <typename PT, typename CT>
-  CreateElementResult CreateBRInternal(
+  MOZ_CAN_RUN_SCRIPT CreateElementResult CreateBRInternal(
       const EditorDOMPointBase<PT, CT>& aPointToInsert, bool aCreateMozBR);
 
  protected:
   /**
    * AutoSafeEditorData grabs editor instance and related instances during
    * handling an edit action.  When this is created, its pointer is set to
    * the mSafeData, and this guarantees the lifetime of grabbing objects
    * until it's destroyed.
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -349,17 +349,17 @@ class TextEditor : public EditorBase, pu
    *                            If eNext, selection will be collapsed after
    *                            the <br> element.
    *                            If ePrevious, selection will be collapsed at
    *                            the <br> element.
    * @return                    The new <br> node.  If failed to create new
    *                            <br> node, returns nullptr.
    */
   template <typename PT, typename CT>
-  already_AddRefed<Element> InsertBrElementWithTransaction(
+  MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> InsertBrElementWithTransaction(
       const EditorDOMPointBase<PT, CT>& aPointToInsert,
       EDirection aSelect = eNone);
 
   /**
    * Extends the selection for given deletion operation
    * If done, also update aAction to what's actually left to do after the
    * extension.
    */
--- a/editor/libeditor/WSRunObject.cpp
+++ b/editor/libeditor/WSRunObject.cpp
@@ -235,17 +235,18 @@ already_AddRefed<Element> WSRunObject::I
       nsresult rv = ReplacePreviousNBSPIfUnncessary(beforeRun, pointToInsert);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return nullptr;
       }
     }
   }
 
   RefPtr<Element> newBrElement =
-      mHTMLEditor->InsertBrElementWithTransaction(pointToInsert, aSelect);
+      MOZ_KnownLive(mHTMLEditor)
+          ->InsertBrElementWithTransaction(pointToInsert, aSelect);
   if (NS_WARN_IF(!newBrElement)) {
     return nullptr;
   }
   return newBrElement.forget();
 }
 
 nsresult WSRunObject::InsertText(Document& aDocument,
                                  const nsAString& aStringToInsert,
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -414,16 +414,17 @@ interface nsIEditor  : nsISupports
    * and split the contents between the two nodes
    * @param aExistingRightNode   the node to split.
    *                             It will become the new node's next sibling.
    * @param aOffset              the offset of aExistingRightNode's
    *                             content|children to do the split at
    * @param aNewLeftNode         [OUT] the new node resulting from the split,
    *                             becomes aExistingRightNode's previous sibling.
    */
+  [can_run_script]
   void splitNode(in Node existingRightNode,
                  in long offset,
                  out Node newLeftNode);
 
   /**
    * joinNodes() takes 2 nodes and merge their content|children.
    * @param aLeftNode     The left node.  It will be deleted.
    * @param aRightNode    The right node. It will remain after the join.
--- a/editor/nsIHTMLEditor.idl
+++ b/editor/nsIHTMLEditor.idl
@@ -206,16 +206,17 @@ interface nsIHTMLEditor : nsISupports
     * @param aElement  An element in the document
     */
   void setCaretAfterElement(in Element aElement);
 
   /**
    * SetParagraphFormat       Insert a block paragraph tag around selection
    * @param aParagraphFormat  "p", "h1" to "h6", "address", "pre", or "blockquote"
    */
+  [can_run_script]
   void setParagraphFormat(in AString aParagraphFormat);
 
   /**
    * getParagraphState returns what block tag paragraph format is in
    * the selection.
    * @param aMixed     True if there is more than one format
    * @return           Name of block tag. "" is returned for none.
    */
@@ -278,31 +279,33 @@ interface nsIHTMLEditor : nsISupports
    */
   [can_run_script]
   void getAlignment(out boolean aMixed, out short aAlign);
 
   /**
    * Document me!
    *
    */
+  [can_run_script]
   void makeOrChangeList(in AString aListType, in boolean entireList,
                         in AString aBulletType);
 
   /**
    * removeList removes list items (<li>, <dd>, and <dt>) and list structures
    * (<ul>, <ol>, and <dl>).
    *
    * @param aListType  Unused.
    */
   void removeList(in AString aListType);
 
   /**
    * Document me!
    *
    */
+  [can_run_script]
   void indent(in AString aIndent);
 
   /**
    * Document me!
    *
    */
   void  align(in AString aAlign);