From f27bb86c9aa63160c3f8bc64a8d7fbb0c612d984 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 5 May 2012 11:00:06 +0200 Subject: [PATCH] Bug 750062 - Assert preconditions in IsVisTextNode; r=ehsan --- editor/libeditor/base/nsEditor.cpp | 3 +++ editor/libeditor/base/nsEditor.h | 3 +++ editor/libeditor/html/nsHTMLEditor.cpp | 13 +++++++------ editor/libeditor/html/nsHTMLEditor.h | 7 +++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 1ad37759101..e67bcb31241 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -3645,6 +3645,9 @@ nsEditor::IsContainer(nsIDOMNode *aNode) bool nsEditor::IsTextInDirtyFrameVisible(nsIContent *aNode) { + MOZ_ASSERT(aNode); + MOZ_ASSERT(aNode->NodeType() == nsIDOMNode::TEXT_NODE); + // virtual method // // If this is a simple non-html editor, diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 79e0b6585da..a2c54054ae0 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -568,6 +568,9 @@ public: bool IsEditable(nsIDOMNode *aNode); bool IsEditable(nsIContent *aNode); + /** + * aNode must be a non-null text node. + */ virtual bool IsTextInDirtyFrameVisible(nsIContent *aNode); /** returns true if aNode is a MozEditorBogus node */ diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 3a2f018f801..072041a5e0b 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -4591,6 +4591,9 @@ nsHTMLEditor::GetLastEditableLeaf(nsIDOMNode *aNode, nsCOMPtr *aOutL bool nsHTMLEditor::IsTextInDirtyFrameVisible(nsIContent *aNode) { + MOZ_ASSERT(aNode); + MOZ_ASSERT(aNode->NodeType() == nsIDOMNode::TEXT_NODE); + bool isEmptyTextNode; nsresult rv = IsVisTextNode(aNode, &isEmptyTextNode, false); if (NS_FAILED(rv)) { @@ -4611,13 +4614,11 @@ nsHTMLEditor::IsVisTextNode(nsIContent* aNode, bool* outIsEmptyNode, bool aSafeToAskFrames) { - NS_ENSURE_TRUE(aNode && outIsEmptyNode, NS_ERROR_NULL_POINTER); - *outIsEmptyNode = true; + MOZ_ASSERT(aNode); + MOZ_ASSERT(aNode->NodeType() == nsIDOMNode::TEXT_NODE); + MOZ_ASSERT(outIsEmptyNode); - // callers job to only call us with text nodes - if (!aNode->IsNodeOfType(nsINode::eTEXT)) { - return NS_ERROR_NULL_POINTER; - } + *outIsEmptyNode = true; PRUint32 length = aNode->TextLength(); if (aSafeToAskFrames) diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index 915cba5f397..8c8e21344dc 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -388,8 +388,15 @@ public: // aSelection is optional -- if null, we get current seletion nsresult CollapseSelectionToDeepestNonTableFirstChild(nsISelection *aSelection, nsIDOMNode *aNode); + /** + * aNode must be a non-null text node. + */ virtual bool IsTextInDirtyFrameVisible(nsIContent *aNode); + /** + * aNode must be a non-null text node. + * outIsEmptyNode must be non-null. + */ nsresult IsVisTextNode(nsIContent* aNode, bool* outIsEmptyNode, bool aSafeToAskFrames);