From 6e6fb030dcc26412f6ad20028ac1634064fb413e Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Thu, 3 Jan 2002 06:49:10 +0000 Subject: [PATCH] Fixing bug 114590. Making table.insertRow() properly throw exceptions per the DOM spec. r=bernd.mielke@snafu.de, r=peterv@netscape.com, sr=jaggernaut@netscape.com --- .../html/content/src/nsHTMLTableElement.cpp | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/content/html/content/src/nsHTMLTableElement.cpp b/content/html/content/src/nsHTMLTableElement.cpp index ac525ba8f01..bbd8619d3b8 100644 --- a/content/html/content/src/nsHTMLTableElement.cpp +++ b/content/html/content/src/nsHTMLTableElement.cpp @@ -565,13 +565,13 @@ nsHTMLTableElement::GetRows(nsIDOMHTMLCollection** aValue) if (!mRows) { // XXX why was this here NS_ADDREF(nsHTMLAtoms::tr); mRows = new TableRowsCollection(this); - NS_ENSURE_TRUE(mRows, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(mRows); // this table's reference, released in the destructor } - mRows->QueryInterface(NS_GET_IID(nsIDOMHTMLCollection), (void **)aValue); + *aValue = mRows; + NS_ADDREF(*aValue); return NS_OK; } @@ -756,27 +756,32 @@ nsHTMLTableElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) insert the new row as its first child */ *aValue = nsnull; + + if (aIndex < 0) { + return NS_ERROR_DOM_INDEX_SIZE_ERR; + } + nsresult rv; - // use local variable refIndex so we can remember original aIndex - PRInt32 refIndex = aIndex; - - if (0>refIndex) // negative aIndex treated as 0 - refIndex=0; - - nsIDOMHTMLCollection *rows; - GetRows(&rows); + nsCOMPtr rows; + GetRows(getter_AddRefs(rows)); PRUint32 rowCount; - rows->GetLength(&rowCount); - if (0 rowCount) { + return NS_ERROR_DOM_INDEX_SIZE_ERR; + } + + // use local variable refIndex so we can remember original aIndex + PRUint32 refIndex = (PRUint32)aIndex; + + if (rowCount > 0) { + if (refIndex == rowCount) { // we set refIndex to the last row so we can get the last row's // parent we then do an AppendChild below if (rowCount refRow; @@ -822,7 +827,7 @@ nsHTMLTableElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) GenericElementCollection head(this, nsHTMLAtoms::thead); - PRUint32 length=0; + PRUint32 length = 0; head.GetLength(&length); @@ -832,22 +837,22 @@ nsHTMLTableElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) else { GenericElementCollection body(this, nsHTMLAtoms::tbody); - length=0; + length = 0; body.GetLength(&length); - if (0 != length) { + if (length > 0) { body.Item(0, getter_AddRefs(rowGroup)); } else { GenericElementCollection foot(this, nsHTMLAtoms::tfoot); - length=0; + length = 0; foot.GetLength(&length); - if (0 != length) { + if (length > 0) { foot.Item(0, getter_AddRefs(rowGroup)); } }