From d773eca3316f2c99db9a1dd77929bcbd157eeacb Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 7 Feb 2018 21:36:37 +0100 Subject: Edit transactions should store their editor instance with strong reference Edit transactions should store their editor instance with a strong reference, and they should be released when the editor is destroyed. --- editor/libeditor/CompositionTransaction.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'editor/libeditor/CompositionTransaction.cpp') diff --git a/editor/libeditor/CompositionTransaction.cpp b/editor/libeditor/CompositionTransaction.cpp index 25938fa60..bde53d2e5 100644 --- a/editor/libeditor/CompositionTransaction.cpp +++ b/editor/libeditor/CompositionTransaction.cpp @@ -33,7 +33,7 @@ CompositionTransaction::CompositionTransaction( , mReplaceLength(aReplaceLength) , mRanges(aTextRangeArray) , mStringToInsert(aStringToInsert) - , mEditorBase(aEditorBase) + , mEditorBase(&aEditorBase) , mRangeUpdater(aRangeUpdater) , mFixed(false) { @@ -45,6 +45,7 @@ CompositionTransaction::~CompositionTransaction() } NS_IMPL_CYCLE_COLLECTION_INHERITED(CompositionTransaction, EditTransactionBase, + mEditorBase, mTextNode) // mRangeList can't lead to cycles @@ -60,9 +61,13 @@ NS_IMPL_RELEASE_INHERITED(CompositionTransaction, EditTransactionBase) NS_IMETHODIMP CompositionTransaction::DoTransaction() { + if (NS_WARN_IF(!mEditorBase)) { + return NS_ERROR_NOT_INITIALIZED; + } + // Fail before making any changes if there's no selection controller nsCOMPtr selCon; - mEditorBase.GetSelectionController(getter_AddRefs(selCon)); + mEditorBase->GetSelectionController(getter_AddRefs(selCon)); NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED); // Advance caret: This requires the presentation shell to get the selection. @@ -108,9 +113,13 @@ CompositionTransaction::DoTransaction() NS_IMETHODIMP CompositionTransaction::UndoTransaction() { + if (NS_WARN_IF(!mEditorBase)) { + return NS_ERROR_NOT_INITIALIZED; + } + // Get the selection first so we'll fail before making any changes if we // can't get it - RefPtr selection = mEditorBase.GetSelection(); + RefPtr selection = mEditorBase->GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED); nsresult rv = mTextNode->DeleteData(mOffset, mStringToInsert.Length()); @@ -171,7 +180,10 @@ CompositionTransaction::GetTxnDescription(nsAString& aString) nsresult CompositionTransaction::SetSelectionForRanges() { - return SetIMESelection(mEditorBase, mTextNode, mOffset, + if (NS_WARN_IF(!mEditorBase)) { + return NS_ERROR_NOT_INITIALIZED; + } + return SetIMESelection(*mEditorBase, mTextNode, mOffset, mStringToInsert.Length(), mRanges); } -- cgit v1.2.3