summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/InsertNodeTransaction.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/InsertNodeTransaction.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/InsertNodeTransaction.cpp')
-rw-r--r--editor/libeditor/InsertNodeTransaction.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/editor/libeditor/InsertNodeTransaction.cpp b/editor/libeditor/InsertNodeTransaction.cpp
index 6af33b74f..6317b8c15 100644
--- a/editor/libeditor/InsertNodeTransaction.cpp
+++ b/editor/libeditor/InsertNodeTransaction.cpp
@@ -28,7 +28,7 @@ InsertNodeTransaction::InsertNodeTransaction(nsIContent& aNode,
: mNode(&aNode)
, mParent(&aParent)
, mOffset(aOffset)
- , mEditorBase(aEditorBase)
+ , mEditorBase(&aEditorBase)
{
}
@@ -37,6 +37,7 @@ InsertNodeTransaction::~InsertNodeTransaction()
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(InsertNodeTransaction, EditTransactionBase,
+ mEditorBase,
mNode,
mParent)
@@ -48,7 +49,9 @@ NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
NS_IMETHODIMP
InsertNodeTransaction::DoTransaction()
{
- MOZ_ASSERT(mNode && mParent);
+ if (NS_WARN_IF(!mEditorBase) || NS_WARN_IF(!mNode) || NS_WARN_IF(!mParent)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
uint32_t count = mParent->GetChildCount();
if (mOffset > static_cast<int32_t>(count) || mOffset == -1) {
@@ -59,15 +62,15 @@ InsertNodeTransaction::DoTransaction()
// Note, it's ok for ref to be null. That means append.
nsCOMPtr<nsIContent> ref = mParent->GetChildAt(mOffset);
- mEditorBase.MarkNodeDirty(GetAsDOMNode(mNode));
+ mEditorBase->MarkNodeDirty(GetAsDOMNode(mNode));
ErrorResult rv;
mParent->InsertBefore(*mNode, ref, rv);
NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
// Only set selection to insertion point if editor gives permission
- if (mEditorBase.GetShouldTxnSetSelection()) {
- RefPtr<Selection> selection = mEditorBase.GetSelection();
+ if (mEditorBase->GetShouldTxnSetSelection()) {
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
// Place the selection just after the inserted element
selection->Collapse(mParent, mOffset + 1);
@@ -80,8 +83,9 @@ InsertNodeTransaction::DoTransaction()
NS_IMETHODIMP
InsertNodeTransaction::UndoTransaction()
{
- MOZ_ASSERT(mNode && mParent);
-
+ if (NS_WARN_IF(!mNode) || NS_WARN_IF(!mParent)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
ErrorResult rv;
mParent->RemoveChild(*mNode, rv);
return rv.StealNSResult();