From be1f4dc4116167c35a6baec7eb25e175f72862af Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Thu, 19 Mar 2020 10:40:10 +0000 Subject: [PATCH] Bug 1623333: part 3) Assert `EditorBase::SelectionRefPtr` has type `eNormal`. r=masayuki Simplifies reasoning about it. Differential Revision: https://phabricator.services.mozilla.com/D67444 --- editor/libeditor/EditorBase.cpp | 6 ++++++ editor/libeditor/EditorBase.h | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp index 9200028f4fd02..82d4dd91c8e69 100644 --- a/editor/libeditor/EditorBase.cpp +++ b/editor/libeditor/EditorBase.cpp @@ -6096,6 +6096,9 @@ EditorBase::AutoEditActionDataSetter::AutoEditActionDataSetter( // If we're nested edit action, copies necessary data from the parent. if (mParentData) { mSelection = mParentData->mSelection; + MOZ_ASSERT(!mSelection || + (mSelection->GetType() == SelectionType::eNormal)); + // If we're eNotEditing, we should inherit the parent's edit action. // This may occur if creator or its callee use public methods which // just returns something. @@ -6115,6 +6118,9 @@ EditorBase::AutoEditActionDataSetter::AutoEditActionDataSetter( if (NS_WARN_IF(!mSelection)) { return; } + + MOZ_ASSERT(mSelection->GetType() == SelectionType::eNormal); + mEditAction = aEditAction; mDirectionOfTopLevelEditSubAction = eNone; if (mEditorBase.mIsHTMLEditorClass) { diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h index f08df6b08fe10..87418c19ab3f9 100644 --- a/editor/libeditor/EditorBase.h +++ b/editor/libeditor/EditorBase.h @@ -874,7 +874,13 @@ class EditorBase : public nsIEditor, bool IsCanceled() const { return mBeforeInputEventCanceled; } - const RefPtr& SelectionRefPtr() const { return mSelection; } + const RefPtr& SelectionRefPtr() const { + MOZ_ASSERT(!mSelection || + (mSelection->GetType() == SelectionType::eNormal)); + + return mSelection; + } + nsIPrincipal* GetPrincipal() const { return mPrincipal; } EditAction GetEditAction() const { return mEditAction; } @@ -1040,6 +1046,8 @@ class EditorBase : public nsIEditor, } void UpdateSelectionCache(Selection& aSelection) { + MOZ_ASSERT(aSelection.GetType() == SelectionType::eNormal); + AutoEditActionDataSetter* actionData = this; while (actionData) { if (actionData->mSelection) { @@ -1217,6 +1225,9 @@ class EditorBase : public nsIEditor, */ const RefPtr& SelectionRefPtr() const { MOZ_ASSERT(mEditActionData); + MOZ_ASSERT(mEditActionData->SelectionRefPtr()->GetType() == + SelectionType::eNormal); + return mEditActionData->SelectionRefPtr(); }