summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/SplitNodeTransaction.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-02-07 21:36:37 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-02-07 21:36:37 +0100
commitd773eca3316f2c99db9a1dd77929bcbd157eeacb (patch)
treebe0efc8413575e2db60480a9ba5991261929b144 /editor/libeditor/SplitNodeTransaction.cpp
parent1e55a5d9188b87da8632e217b238838effb1cdeb (diff)
downloadUXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.gz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.lz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.xz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.zip
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.
Diffstat (limited to 'editor/libeditor/SplitNodeTransaction.cpp')
-rw-r--r--editor/libeditor/SplitNodeTransaction.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/editor/libeditor/SplitNodeTransaction.cpp b/editor/libeditor/SplitNodeTransaction.cpp
index 113ff7a61..8965b5399 100644
--- a/editor/libeditor/SplitNodeTransaction.cpp
+++ b/editor/libeditor/SplitNodeTransaction.cpp
@@ -19,7 +19,7 @@ using namespace dom;
SplitNodeTransaction::SplitNodeTransaction(EditorBase& aEditorBase,
nsIContent& aNode,
int32_t aOffset)
- : mEditorBase(aEditorBase)
+ : mEditorBase(&aEditorBase)
, mExistingRightNode(&aNode)
, mOffset(aOffset)
{
@@ -30,6 +30,7 @@ SplitNodeTransaction::~SplitNodeTransaction()
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(SplitNodeTransaction, EditTransactionBase,
+ mEditorBase,
mParent,
mNewLeftNode)
@@ -41,6 +42,10 @@ NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
NS_IMETHODIMP
SplitNodeTransaction::DoTransaction()
{
+ if (NS_WARN_IF(!mEditorBase)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+
// Create a new node
ErrorResult rv;
// Don't use .downcast directly because AsContent has an assertion we want
@@ -48,16 +53,16 @@ SplitNodeTransaction::DoTransaction()
NS_ASSERTION(!rv.Failed() && clone, "Could not create clone");
NS_ENSURE_TRUE(!rv.Failed() && clone, rv.StealNSResult());
mNewLeftNode = dont_AddRef(clone.forget().take()->AsContent());
- mEditorBase.MarkNodeDirty(mExistingRightNode->AsDOMNode());
+ mEditorBase->MarkNodeDirty(mExistingRightNode->AsDOMNode());
// Get the parent node
mParent = mExistingRightNode->GetParentNode();
NS_ENSURE_TRUE(mParent, NS_ERROR_NULL_POINTER);
// Insert the new node
- rv = mEditorBase.SplitNodeImpl(*mExistingRightNode, mOffset, *mNewLeftNode);
- if (mEditorBase.GetShouldTxnSetSelection()) {
- RefPtr<Selection> selection = mEditorBase.GetSelection();
+ rv = mEditorBase->SplitNodeImpl(*mExistingRightNode, mOffset, *mNewLeftNode);
+ if (mEditorBase->GetShouldTxnSetSelection()) {
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
rv = selection->Collapse(mNewLeftNode, mOffset);
}
@@ -67,10 +72,14 @@ SplitNodeTransaction::DoTransaction()
NS_IMETHODIMP
SplitNodeTransaction::UndoTransaction()
{
- MOZ_ASSERT(mNewLeftNode && mParent);
+ if (NS_WARN_IF(!mEditorBase) ||
+ NS_WARN_IF(!mNewLeftNode) ||
+ NS_WARN_IF(!mParent)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
// This assumes Do inserted the new node in front of the prior existing node
- return mEditorBase.JoinNodesImpl(mExistingRightNode, mNewLeftNode, mParent);
+ return mEditorBase->JoinNodesImpl(mExistingRightNode, mNewLeftNode, mParent);
}
/* Redo cannot simply resplit the right node, because subsequent transactions
@@ -80,7 +89,10 @@ SplitNodeTransaction::UndoTransaction()
NS_IMETHODIMP
SplitNodeTransaction::RedoTransaction()
{
- MOZ_ASSERT(mNewLeftNode && mParent);
+ if (NS_WARN_IF(!mNewLeftNode) ||
+ NS_WARN_IF(!mParent)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
ErrorResult rv;
// First, massage the existing node so it is in its post-split state