diff --git a/editor/libeditor/EditAggregateTransaction.cpp b/editor/libeditor/EditAggregateTransaction.cpp index 5493e649d189..28a59b2d8923 100644 --- a/editor/libeditor/EditAggregateTransaction.cpp +++ b/editor/libeditor/EditAggregateTransaction.cpp @@ -22,8 +22,8 @@ NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase) NS_IMETHODIMP EditAggregateTransaction::DoTransaction() { // FYI: It's legal (but not very useful) to have an empty child list. - AutoTArray, 10> children(mChildren); - for (OwningNonNull& childTransaction : children) { + for (const OwningNonNull& childTransaction : + CopyableAutoTArray, 10>(mChildren)) { nsresult rv = MOZ_KnownLive(childTransaction)->DoTransaction(); if (NS_FAILED(rv)) { NS_WARNING("EditTransactionBase::DoTransaction() failed"); @@ -36,8 +36,9 @@ NS_IMETHODIMP EditAggregateTransaction::DoTransaction() { NS_IMETHODIMP EditAggregateTransaction::UndoTransaction() { // FYI: It's legal (but not very useful) to have an empty child list. // Undo goes through children backwards. - AutoTArray, 10> children(mChildren); - for (OwningNonNull& childTransaction : + const CopyableAutoTArray, 10> children( + mChildren); + for (const OwningNonNull& childTransaction : Reversed(children)) { nsresult rv = MOZ_KnownLive(childTransaction)->UndoTransaction(); if (NS_FAILED(rv)) { @@ -50,8 +51,9 @@ NS_IMETHODIMP EditAggregateTransaction::UndoTransaction() { NS_IMETHODIMP EditAggregateTransaction::RedoTransaction() { // It's legal (but not very useful) to have an empty child list. - AutoTArray, 10> children(mChildren); - for (OwningNonNull& childTransaction : children) { + const CopyableAutoTArray, 10> children( + mChildren); + for (const OwningNonNull& childTransaction : children) { nsresult rv = MOZ_KnownLive(childTransaction)->RedoTransaction(); if (NS_FAILED(rv)) { NS_WARNING("EditTransactionBase::RedoTransaction() failed"); diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp index df40d2fad7c8..0577f7da814d 100644 --- a/editor/libeditor/EditorBase.cpp +++ b/editor/libeditor/EditorBase.cpp @@ -1490,8 +1490,7 @@ already_AddRefed EditorBase::CreateNodeWithTransaction( } if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { DebugOnly rvIgnored = listener->DidCreateNode( nsDependentAtomString(&aTagName), newElement, rv); NS_WARNING_ASSERTION( @@ -1564,8 +1563,7 @@ nsresult EditorBase::InsertNodeWithTransaction( } if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { DebugOnly rvIgnored = listener->DidInsertNode(&aContentToInsert, rv); NS_WARNING_ASSERTION( @@ -1666,8 +1664,7 @@ nsresult EditorBase::DeleteNodeWithTransaction(nsIContent& aContent) { } if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { DebugOnly rvIgnored = listener->DidDeleteNode(&aContent, rv); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), @@ -1753,7 +1750,7 @@ void EditorBase::NotifyEditorObservers( if (!mEditorObservers.IsEmpty()) { // Copy the observers since EditAction()s can modify mEditorObservers. - AutoEditorObserverArray observers(mEditorObservers); + AutoEditorObserverArray observers(mEditorObservers.Clone()); for (auto& observer : observers) { DebugOnly rvIgnored = observer->EditAction(); NS_WARNING_ASSERTION( @@ -2544,8 +2541,7 @@ nsresult EditorBase::InsertTextIntoTextNodeWithTransaction( // let listeners know what happened if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { // TODO: might need adaptation because of mutation event listeners called // during `DoTransactionInternal`. DebugOnly rvIgnored = @@ -2612,7 +2608,8 @@ nsresult EditorBase::NotifyDocumentListeners( } // Needs to store all listeners before notifying ComposerCommandsUpdate // since notifying it might change mDocStateListeners. - const AutoDocumentStateListenerArray listeners(mDocStateListeners); + const AutoDocumentStateListenerArray listeners( + mDocStateListeners.Clone()); if (composerCommandsUpdate) { composerCommandsUpdate->OnBeforeHTMLEditorDestroyed(); } @@ -2653,7 +2650,8 @@ nsresult EditorBase::NotifyDocumentListeners( } // Needs to store all listeners before notifying ComposerCommandsUpdate // since notifying it might change mDocStateListeners. - const AutoDocumentStateListenerArray listeners(mDocStateListeners); + const AutoDocumentStateListenerArray listeners( + mDocStateListeners.Clone()); if (composerCommandsUpdate) { composerCommandsUpdate->OnHTMLEditorDirtyStateChanged(mDocDirtyState); } @@ -2690,8 +2688,7 @@ nsresult EditorBase::SetTextNodeWithoutTransaction(const nsAString& aString, // Let listeners know what's up if (!mActionListeners.IsEmpty() && length) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { DebugOnly rvIgnored = listener->WillDeleteText(&aTextNode, 0, length); if (NS_WARN_IF(Destroyed())) { @@ -2727,8 +2724,7 @@ nsresult EditorBase::SetTextNodeWithoutTransaction(const nsAString& aString, // Let listeners know what happened if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { if (length) { DebugOnly rvIgnored = listener->DidDeleteText(&aTextNode, 0, length, NS_OK); @@ -2779,8 +2775,7 @@ nsresult EditorBase::DeleteTextWithTransaction(Text& aTextNode, // Let listeners know what's up if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { DebugOnly rvIgnored = listener->WillDeleteText(&aTextNode, aOffset, aLength); NS_WARNING_ASSERTION( @@ -2800,8 +2795,7 @@ nsresult EditorBase::DeleteTextWithTransaction(Text& aTextNode, // Let listeners know what happened if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { DebugOnly rvIgnored = listener->DidDeleteText(&aTextNode, aOffset, aLength, rv); NS_WARNING_ASSERTION( @@ -4133,7 +4127,7 @@ nsresult EditorBase::DeleteSelectionWithTransaction( // Notify nsIEditActionListener::WillDelete[Selection|Text] if (!mActionListeners.IsEmpty()) { if (!deleteContent) { - AutoActionListenerArray listeners(mActionListeners); + AutoActionListenerArray listeners(mActionListeners.Clone()); for (auto& listener : listeners) { DebugOnly rvIgnored = listener->WillDeleteSelection(SelectionRefPtr()); @@ -4145,7 +4139,7 @@ nsresult EditorBase::DeleteSelectionWithTransaction( "must not destroy the editor"); } } else if (deleteCharData) { - AutoActionListenerArray listeners(mActionListeners); + AutoActionListenerArray listeners(mActionListeners.Clone()); for (auto& listener : listeners) { // XXX Why don't we notify listeners of actual length? DebugOnly rvIgnored = @@ -4184,7 +4178,7 @@ nsresult EditorBase::DeleteSelectionWithTransaction( } // Notify nsIEditActionListener::DidDelete[Selection|Text|Node] - AutoActionListenerArray listeners(mActionListeners); + AutoActionListenerArray listeners(mActionListeners.Clone()); if (!deleteContent) { for (auto& listener : mActionListeners) { DebugOnly rvIgnored = diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 252993859b59..6f17a7923fe3 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -4084,8 +4084,7 @@ already_AddRefed HTMLEditor::SplitNodeWithTransaction( } if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { DebugOnly rvIgnored = listener->DidSplitNode( aStartOfRightNode.GetContainer(), newLeftContent); NS_WARNING_ASSERTION( @@ -4458,8 +4457,7 @@ nsresult HTMLEditor::JoinNodesWithTransaction(nsINode& aLeftNode, } if (!mActionListeners.IsEmpty()) { - AutoActionListenerArray listeners(mActionListeners); - for (auto& listener : listeners) { + for (auto& listener : mActionListeners.Clone()) { DebugOnly rvIgnored = listener->DidJoinNodes(&aLeftNode, &aRightNode, parent, rv); NS_WARNING_ASSERTION( diff --git a/editor/libeditor/SelectionState.cpp b/editor/libeditor/SelectionState.cpp index 82d265dc2723..04c19bf46d9f 100644 --- a/editor/libeditor/SelectionState.cpp +++ b/editor/libeditor/SelectionState.cpp @@ -77,8 +77,8 @@ nsresult SelectionState::RestoreSelection(Selection& aSelection) { aSelection.SetDirection(mDirection); ErrorResult error; - AutoTArray, 10> rangeItems(mArray); - for (RefPtr& rangeItem : rangeItems) { + const CopyableAutoTArray, 10> rangeItems(mArray); + for (const RefPtr& rangeItem : rangeItems) { RefPtr range = rangeItem->GetRange(); if (!range) { NS_WARNING("RangeItem::GetRange() failed"); diff --git a/editor/libeditor/SelectionState.h b/editor/libeditor/SelectionState.h index 4dd56ad47bc8..0efe0b0ccff8 100644 --- a/editor/libeditor/SelectionState.h +++ b/editor/libeditor/SelectionState.h @@ -98,7 +98,7 @@ class SelectionState final { bool IsEmpty() const; private: - AutoTArray, 1> mArray; + CopyableAutoTArray, 1> mArray; nsDirection mDirection; friend class RangeUpdater;