Fixing bug 38357. Passing a document node to nsRange::SelectNode() crashed mozilla, now it properly throws the exception INVALID_NODE_TYPE_ERR if the node type is incorrect. r=akkana@netscape.com

This commit is contained in:
jst%netscape.com 2000-05-11 01:44:44 +00:00
parent ecdfe3c5ca
commit 327decd731
2 changed files with 28 additions and 2 deletions

View File

@ -1073,9 +1073,22 @@ nsresult nsRange::Unposition()
nsresult nsRange::SelectNode(nsIDOMNode* aN)
{
if (!aN) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDOMNode> parent;
nsCOMPtr<nsIDOMNode> theNode( do_QueryInterface(aN) );
if (!aN) return NS_ERROR_NULL_POINTER;
PRUint16 type = 0;
aN->GetNodeType(&type);
switch (type) {
case nsIDOMNode::ATTRIBUTE_NODE :
case nsIDOMNode::ENTITY_NODE :
case nsIDOMNode::DOCUMENT_NODE :
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE :
case nsIDOMNode::NOTATION_NODE :
return NS_ERROR_DOM_RANGE_INVALID_NODE_TYPE_ERR;
}
nsresult res = aN->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(res)) return res;
PRInt32 indx = IndexOf(theNode);

View File

@ -1073,9 +1073,22 @@ nsresult nsRange::Unposition()
nsresult nsRange::SelectNode(nsIDOMNode* aN)
{
if (!aN) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDOMNode> parent;
nsCOMPtr<nsIDOMNode> theNode( do_QueryInterface(aN) );
if (!aN) return NS_ERROR_NULL_POINTER;
PRUint16 type = 0;
aN->GetNodeType(&type);
switch (type) {
case nsIDOMNode::ATTRIBUTE_NODE :
case nsIDOMNode::ENTITY_NODE :
case nsIDOMNode::DOCUMENT_NODE :
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE :
case nsIDOMNode::NOTATION_NODE :
return NS_ERROR_DOM_RANGE_INVALID_NODE_TYPE_ERR;
}
nsresult res = aN->GetParentNode(getter_AddRefs(parent));
if (NS_FAILED(res)) return res;
PRInt32 indx = IndexOf(theNode);