Bug 738654 - Part b: RemoveChildAt can't fail; r=sicking

This commit is contained in:
Ms2ger 2012-03-29 23:09:07 +02:00
parent 84f17e5f45
commit 968425f97e
25 changed files with 55 additions and 95 deletions

View File

@ -291,8 +291,8 @@ private:
// IID for the nsINode interface
#define NS_INODE_IID \
{ 0xce310d6d, 0x46b5, 0x46a2, \
{ 0x86, 0x3d, 0x59, 0x16, 0x6b, 0x81, 0x00, 0x67 } }
{ 0x458300ed, 0xe418, 0x4577, \
{ 0x89, 0xd7, 0xfe, 0xf1, 0x34, 0xf3, 0x52, 0x19 } }
/**
* An internal interface that abstracts some DOMNode-related parts that both
@ -587,12 +587,10 @@ public:
* @param aNotify whether to notify the document (current document for
* nsIContent, and |this| for nsIDocument) that the remove has
* occurred
* @param aMutationEvent whether to fire a mutation event
*
* Note: If there is no child at aIndex, this method will simply do nothing.
*/
virtual nsresult RemoveChildAt(PRUint32 aIndex,
bool aNotify) = 0;
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify) = 0;
/**
* Get a property associated with this node.

View File

@ -697,11 +697,11 @@ nsDOMAttribute::AppendChildTo(nsIContent* aKid, bool aNotify)
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
void
nsDOMAttribute::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
if (aIndex != 0 || !mChild) {
return NS_OK;
return;
}
doRemoveChild(aNotify);
@ -709,7 +709,6 @@ nsDOMAttribute::RemoveChildAt(PRUint32 aIndex, bool aNotify)
nsString nullString;
SetDOMStringToNull(nullString);
SetValue(nullString);
return NS_OK;
}
nsresult

View File

@ -90,7 +90,7 @@ public:
virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
bool aNotify);
virtual nsresult AppendChildTo(nsIContent* aKid, bool aNotify);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual already_AddRefed<nsIURI> GetBaseURI() const;

View File

@ -3517,12 +3517,12 @@ nsDocument::AppendChildTo(nsIContent* aKid, bool aNotify)
return nsDocument::InsertChildAt(aKid, GetChildCount(), aNotify);
}
nsresult
void
nsDocument::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
nsCOMPtr<nsIContent> oldKid = GetChildAt(aIndex);
if (!oldKid) {
return NS_OK;
return;
}
if (oldKid->IsElement()) {
@ -3532,7 +3532,6 @@ nsDocument::RemoveChildAt(PRUint32 aIndex, bool aNotify)
doRemoveChildAt(aIndex, aNotify, oldKid, mChildren);
mCachedRootElement = nsnull;
return NS_OK;
}
PRInt32
@ -5988,7 +5987,6 @@ BlastFunc(nsAttrHashKey::KeyType aKey, nsDOMAttribute *aData, void* aUserArg)
static void
BlastSubtreeToPieces(nsINode *aNode)
{
PRUint32 i, count;
if (aNode->IsElement()) {
nsGenericElement *element = static_cast<nsGenericElement*>(aNode);
const nsDOMAttributeMap *map = element->GetAttributeMap();
@ -6010,16 +6008,10 @@ BlastSubtreeToPieces(nsINode *aNode)
}
}
count = aNode->GetChildCount();
for (i = 0; i < count; ++i) {
PRUint32 count = aNode->GetChildCount();
for (PRUint32 i = 0; i < count; ++i) {
BlastSubtreeToPieces(aNode->GetFirstChild());
#ifdef DEBUG
nsresult rv =
#endif
aNode->RemoveChildAt(0, false);
// XXX Should we abort here?
NS_ASSERTION(NS_SUCCEEDED(rv), "Uhoh, RemoveChildAt shouldn't fail!");
aNode->RemoveChildAt(0, false);
}
}
@ -6123,8 +6115,7 @@ nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
// Remove from parent.
nsCOMPtr<nsINode> parent = adoptedNode->GetNodeParent();
if (parent) {
rv = parent->RemoveChildAt(parent->IndexOf(adoptedNode), true);
NS_ENSURE_SUCCESS(rv, rv);
parent->RemoveChildAt(parent->IndexOf(adoptedNode), true);
}
break;

View File

@ -724,7 +724,7 @@ public:
virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
bool aNotify);
virtual nsresult AppendChildTo(nsIContent* aKid, bool aNotify);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
{
return NS_ERROR_NOT_IMPLEMENTED;

View File

@ -680,10 +680,9 @@ nsGenericDOMDataNode::InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
return NS_OK;
}
nsresult
void
nsGenericDOMDataNode::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
return NS_OK;
}
nsIContent *

View File

@ -170,7 +170,7 @@ public:
virtual PRInt32 IndexOf(nsINode* aPossibleChild) const;
virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
bool aNotify);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
NS_IMETHOD GetTextContent(nsAString &aTextContent)
{
nsresult rv = GetNodeValue(aTextContent);

View File

@ -535,7 +535,8 @@ nsINode::RemoveChild(nsINode *aOldChild)
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
return RemoveChildAt(index, true);
RemoveChildAt(index, true);
return NS_OK;
}
nsresult
@ -3848,7 +3849,7 @@ nsINode::doInsertChildAt(nsIContent* aKid, PRUint32 aIndex,
return NS_OK;
}
nsresult
void
nsGenericElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
@ -3857,8 +3858,6 @@ nsGenericElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
if (oldKid) {
doRemoveChildAt(aIndex, aNotify, oldKid, mAttrsAndChildren);
}
return NS_OK;
}
void
@ -4271,12 +4270,9 @@ nsINode::ReplaceOrInsertBefore(bool aReplace, nsINode* aNewChild,
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
nsresult res;
// If we're replacing
if (aReplace) {
res = RemoveChildAt(insPos, true);
NS_ENSURE_SUCCESS(res, res);
RemoveChildAt(insPos, true);
}
if (newContent->IsRootOfAnonymousSubtree()) {
@ -4296,8 +4292,7 @@ nsINode::ReplaceOrInsertBefore(bool aReplace, nsINode* aNewChild,
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
res = oldParent->RemoveChildAt(removeIndex, true);
NS_ENSURE_SUCCESS(res, res);
oldParent->RemoveChildAt(removeIndex, true);
// Adjust insert index if the node we ripped out was a sibling
// of the node we're inserting before
@ -4306,6 +4301,7 @@ nsINode::ReplaceOrInsertBefore(bool aReplace, nsINode* aNewChild,
}
}
nsresult res = NS_OK;
// Move new child over to our document if needed. Do this after removing
// it from its parent so that AdoptNode doesn't fire DOMNodeRemoved
// DocumentType nodes are the only nodes that can have a null

View File

@ -263,7 +263,7 @@ public:
virtual PRInt32 IndexOf(nsINode* aPossibleChild) const;
virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
bool aNotify);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
NS_IMETHOD GetTextContent(nsAString &aTextContent);
NS_IMETHOD SetTextContent(const nsAString& aTextContent);

View File

@ -220,7 +220,7 @@ nsHTMLFieldSetElement::InsertChildAt(nsIContent* aChild, PRUint32 aIndex,
return rv;
}
nsresult
void
nsHTMLFieldSetElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
bool firstLegendHasChanged = false;
@ -239,14 +239,11 @@ nsHTMLFieldSetElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
}
}
nsresult rv = nsGenericHTMLFormElement::RemoveChildAt(aIndex, aNotify);
NS_ENSURE_SUCCESS(rv, rv);
nsGenericHTMLFormElement::RemoveChildAt(aIndex, aNotify);
if (firstLegendHasChanged) {
NotifyElementsForFirstLegendChange(aNotify);
}
return rv;
}
void

View File

@ -84,7 +84,7 @@ public:
virtual nsresult InsertChildAt(nsIContent* aChild, PRUint32 aIndex,
bool aNotify);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
// nsIFormControl
NS_IMETHOD_(PRUint32) GetType() const { return NS_FORM_FIELDSET; }

View File

@ -72,10 +72,10 @@ public:
// nsIDOMHTMLOptGroupElement
NS_DECL_NSIDOMHTMLOPTGROUPELEMENT
// nsGenericElement
// nsINode
virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
bool aNotify);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
// nsIContent
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
@ -187,16 +187,12 @@ nsHTMLOptGroupElement::InsertChildAt(nsIContent* aKid,
return rv;
}
nsresult
void
nsHTMLOptGroupElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
nsSafeOptionListMutation safeMutation(GetSelect(), this, nsnull, aIndex,
aNotify);
nsresult rv = nsGenericHTMLElement::RemoveChildAt(aIndex, aNotify);
if (NS_FAILED(rv)) {
safeMutation.MutationFailed();
}
return rv;
nsGenericHTMLElement::RemoveChildAt(aIndex, aNotify);
}
nsEventStates

View File

@ -230,15 +230,11 @@ nsHTMLSelectElement::InsertChildAt(nsIContent* aKid,
return rv;
}
nsresult
void
nsHTMLSelectElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
nsSafeOptionListMutation safeMutation(this, this, nsnull, aIndex, aNotify);
nsresult rv = nsGenericHTMLFormElement::RemoveChildAt(aIndex, aNotify);
if (NS_FAILED(rv)) {
safeMutation.MutationFailed();
}
return rv;
nsGenericHTMLFormElement::RemoveChildAt(aIndex, aNotify);
}

View File

@ -296,7 +296,7 @@ public:
virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, PRInt32 *aTabIndex);
virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
bool aNotify);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
// Overriden nsIFormControl methods
NS_IMETHOD_(PRUint32) GetType() const { return NS_FORM_SELECT; }

View File

@ -126,14 +126,11 @@ nsSVGSwitchElement::InsertChildAt(nsIContent* aKid,
return rv;
}
nsresult
void
nsSVGSwitchElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
nsresult rv = nsSVGSwitchElementBase::RemoveChildAt(aIndex, aNotify);
if (NS_SUCCEEDED(rv)) {
MaybeInvalidate();
}
return rv;
nsSVGSwitchElementBase::RemoveChildAt(aIndex, aNotify);
MaybeInvalidate();
}
//----------------------------------------------------------------------

View File

@ -75,7 +75,7 @@ public:
// nsINode
virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
bool aNotify);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
// nsIContent
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;

View File

@ -691,8 +691,7 @@ txMozillaXMLOutput::createTxWrapper()
++j;
}
else {
rv = mDocument->RemoveChildAt(j, true);
NS_ENSURE_SUCCESS(rv, rv);
mDocument->RemoveChildAt(j, true);
rv = wrapper->AppendChildTo(childContent, true);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -270,16 +270,14 @@ nsXTFElementWrapper::InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
return rv;
}
nsresult
void
nsXTFElementWrapper::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
nsresult rv;
if (mNotificationMask & nsIXTFElement::NOTIFY_WILL_REMOVE_CHILD)
GetXTFElement()->WillRemoveChild(aIndex);
rv = nsXTFElementWrapperBase::RemoveChildAt(aIndex, aNotify);
nsXTFElementWrapperBase::RemoveChildAt(aIndex, aNotify);
if (mNotificationMask & nsIXTFElement::NOTIFY_CHILD_REMOVED)
GetXTFElement()->ChildRemoved(aIndex);
return rv;
}
nsIAtom *

View File

@ -84,7 +84,7 @@ public:
bool aNullParent = true);
nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
bool aNotify);
nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
void RemoveChildAt(PRUint32 aIndex, bool aNotify);
nsIAtom *GetIDAttributeName() const;
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,

View File

@ -189,7 +189,8 @@ nsXULContextMenuBuilder::UndoAddSeparator()
return NS_OK;
}
return mCurrentNode->RemoveChildAt(count - 1, false);
mCurrentNode->RemoveChildAt(count - 1, false);
return NS_OK;
}
NS_IMETHODIMP

View File

@ -925,13 +925,12 @@ nsXULElement::UnbindFromTree(bool aDeep, bool aNullParent)
nsStyledElement::UnbindFromTree(aDeep, aNullParent);
}
nsresult
void
nsXULElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
{
nsresult rv;
nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
if (!oldKid) {
return NS_OK;
return;
}
// On the removal of a <treeitem>, <treechildren>, or <treecell> element,
@ -954,7 +953,7 @@ nsXULElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
// If it's not, look at our parent
if (!controlElement)
rv = GetParentTree(getter_AddRefs(controlElement));
GetParentTree(getter_AddRefs(controlElement));
nsCOMPtr<nsIDOMElement> oldKidElem = do_QueryInterface(oldKid);
if (controlElement && oldKidElem) {
@ -994,7 +993,7 @@ nsXULElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
}
}
rv = nsStyledElement::RemoveChildAt(aIndex, aNotify);
nsStyledElement::RemoveChildAt(aIndex, aNotify);
if (newCurrentIndex == -2)
controlElement->SetCurrentItem(nsnull);
@ -1022,8 +1021,6 @@ nsXULElement::RemoveChildAt(PRUint32 aIndex, bool aNotify)
false,
true);
}
return rv;
}
void

View File

@ -482,7 +482,7 @@ public:
nsIContent* aBindingParent,
bool aCompileEventHandlers);
virtual void UnbindFromTree(bool aDeep, bool aNullParent);
virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual void RemoveChildAt(PRUint32 aIndex, bool aNotify);
virtual bool GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsAString& aResult) const;
virtual bool HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const;

View File

@ -4085,15 +4085,13 @@ nsXULDocument::OverlayForwardReference::Merge(nsIContent* aTargetNode,
// The element matches. "Go Deep!"
rv = Merge(elementInDocument, currContent, aNotify);
if (NS_FAILED(rv)) return rv;
rv = aOverlayNode->RemoveChildAt(0, false);
if (NS_FAILED(rv)) return rv;
aOverlayNode->RemoveChildAt(0, false);
continue;
}
}
rv = aOverlayNode->RemoveChildAt(0, false);
if (NS_FAILED(rv)) return rv;
aOverlayNode->RemoveChildAt(0, false);
rv = InsertElement(aTargetNode, currContent, aNotify);
if (NS_FAILED(rv)) return rv;
@ -4473,7 +4471,8 @@ nsXULDocument::RemoveElement(nsIContent* aParent, nsIContent* aChild)
{
PRInt32 nodeOffset = aParent->IndexOf(aChild);
return aParent->RemoveChildAt(nodeOffset, true);
aParent->RemoveChildAt(nodeOffset, true);
return NS_OK;
}
//----------------------------------------------------------------------

View File

@ -956,8 +956,7 @@ nsXULContentBuilder::RemoveMember(nsIContent* aContent)
// Note: RemoveChildAt sets |child|'s document to null so that
// it'll get knocked out of the XUL doc's resource-to-element
// map.
nsresult rv = parent->RemoveChildAt(pos, true);
if (NS_FAILED(rv)) return rv;
parent->RemoveChildAt(pos, true);
}
// Remove from the content support map.

View File

@ -274,10 +274,9 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
aBuilder->GetDocument());
PRUint32 pos = parent->IndexOf(node);
NS_ASSERTION((pos >= 0), "Element not found as child of its parent");
rv = parent->RemoveChildAt(pos, true);
NS_ENSURE_SUCCESS(rv, rv);
parent->RemoveChildAt(pos, true);
}
return rv;
return NS_OK;
}
case eTreeOpAppendChildrenToNewParent: {
nsCOMPtr<nsIContent> node = *(mOne.node);
@ -291,8 +290,7 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
bool didAppend = false;
while (node->HasChildren()) {
nsCOMPtr<nsIContent> child = node->GetFirstChild();
rv = node->RemoveChildAt(0, true);
NS_ENSURE_SUCCESS(rv, rv);
node->RemoveChildAt(0, true);
rv = parent->AppendChildTo(child, false);
NS_ENSURE_SUCCESS(rv, rv);
didAppend = true;