Reporting better nsresults to DOM methods.

This commit is contained in:
vidur%netscape.com 1999-09-08 23:18:27 +00:00
Родитель b325137126
Коммит 50eaf4ef31
18 изменённых файлов: 346 добавлений и 120 удалений

Просмотреть файл

@ -94,22 +94,37 @@ nsDOMAttribute::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMPL_ADDREF(nsDOMAttribute)
NS_IMPL_RELEASE(nsDOMAttribute)
void
NS_IMETHODIMP
nsDOMAttribute::DropReference()
{
mContent = nsnull;
return NS_OK;
}
void
NS_IMETHODIMP
nsDOMAttribute::SetContent(nsIContent* aContent)
{
mContent = aContent;
return NS_OK;
}
void
NS_IMETHODIMP
nsDOMAttribute::GetContent(nsIContent** aContent)
{
*aContent = mContent;
NS_IF_ADDREF(mContent);
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::SetName(const nsString& aName)
{
mName=aName;
return NS_OK;
}
nsresult

Просмотреть файл

@ -35,9 +35,10 @@ class nsDOMAttribute;
class nsIDOMAttributePrivate : public nsISupports {
public:
virtual void DropReference() = 0;
virtual void SetContent(nsIContent* aContent) = 0;
virtual void SetName(const nsString& aName) = 0;
NS_IMETHOD DropReference() = 0;
NS_IMETHOD SetContent(nsIContent* aContent) = 0;
NS_IMETHOD GetContent(nsIContent** aContent) = 0;
NS_IMETHOD SetName(const nsString& aName) = 0;
};
// bogus child list for an attribute
@ -104,9 +105,10 @@ public:
NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument);
// nsIDOMAttributePrivate interface
virtual void DropReference();
virtual void SetContent(nsIContent* aContent);
virtual void SetName(const nsString& aName);
NS_IMETHOD DropReference();
NS_IMETHOD SetContent(nsIContent* aContent);
NS_IMETHOD GetContent(nsIContent** aContent);
NS_IMETHOD SetName(const nsString& aName);
private:
nsIContent* mContent;

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsIContent.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsINameSpaceManager.h"
#include "nsDOMError.h"
static NS_DEFINE_IID(kIDOMNamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kIDOMAttrIID, NS_IDOMATTR_IID);
@ -264,7 +265,11 @@ nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn)
nsresult result = NS_OK;
nsIDOMAttr* attribute;
if ((nsnull != mContent) && (nsnull != aNode)) {
if (nsnull == aNode) {
return NS_ERROR_NULL_POINTER;
}
if (nsnull != mContent) {
result = aNode->QueryInterface(kIDOMAttrIID, (void**)&attribute);
if (NS_OK == result) {
PLHashTable* attrHash;
@ -321,26 +326,39 @@ nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn)
attribute->GetValue(value);
// Associate the new attribute with the content
// XXX Need to fail if it's already associated with other
// content
key = name.ToNewCString();
result = attribute->QueryInterface(kIDOMAttributePrivateIID,
(void **)&attrPrivate);
if (NS_OK == result) {
attrPrivate->SetContent(mContent);
attrPrivate->SetName(name);
if (NS_SUCCEEDED(result)) {
nsIContent* owner;
attrPrivate->GetContent(&owner);
if (owner) {
// The old attribute is already associated with another
// piece of content.
result = NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR;
NS_RELEASE(owner);
}
else {
attrPrivate->SetContent(mContent);
attrPrivate->SetName(name);
NS_RELEASE(attrPrivate);
// Add the new attribute node to the hash table (maintaining
// a reference to it)
PL_HashTableAdd(attrHash, key, attribute);
// Set the attribute on the content
result = mContent->SetAttribute(nameSpaceID, nameAtom, value, PR_TRUE);
NS_IF_RELEASE(nameAtom);
}
NS_RELEASE(attrPrivate);
}
// Add the new attribute node to the hash table (maintaining
// a reference to it)
PL_HashTableAdd(attrHash, key, attribute);
// Set the attribute on the content
result = mContent->SetAttribute(nameSpaceID, nameAtom, value, PR_TRUE);
NS_IF_RELEASE(nameAtom);
}
}
else {
result = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
else {
*aReturn = nsnull;
@ -400,6 +418,7 @@ nsDOMAttributeMap::RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)
NS_RELEASE(attribute);
}
else {
result = NS_ERROR_DOM_NOT_FOUND_ERR;
*aReturn = nsnull;
}

Просмотреть файл

@ -76,6 +76,7 @@
#include "nsIDOMSelection.h"
#include "nsIDOMRange.h"
#include "nsIEnumerator.h"
#include "nsDOMError.h"
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
@ -1919,7 +1920,8 @@ nsDocument::CreateElementWithNameSpace(const nsString& aTagName,
const nsString& aNameSpace,
nsIDOMElement** aReturn)
{
return NS_OK;
*aReturn = nsnull;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
@ -1948,7 +1950,7 @@ nsDocument::GetNodeValue(nsString& aNodeValue)
NS_IMETHODIMP
nsDocument::SetNodeValue(const nsString& aNodeValue)
{
return NS_OK;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
NS_IMETHODIMP
@ -2066,17 +2068,17 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNod
nsIContent *content, *refContent = nsnull;
if (nsnull == aNewChild) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_NULL_POINTER;
}
aNewChild->GetNodeType(&nodeType);
if ((COMMENT_NODE != nodeType) && (PROCESSING_INSTRUCTION_NODE != nodeType)) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
result = aNewChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK != result) {
return result;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
if (nsnull == aRefChild) {
@ -2086,7 +2088,7 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNod
result = aRefChild->QueryInterface(kIContentIID, (void**)&refContent);
if (NS_OK != result) {
NS_RELEASE(content);
return result;
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
if ((nsnull != mProlog) && (0 != mProlog->Count())) {
@ -2134,23 +2136,23 @@ nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNod
nsIContent *content, *refContent;
if ((nsnull == aNewChild) || (nsnull == aOldChild)) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_NULL_POINTER;
}
aNewChild->GetNodeType(&nodeType);
if ((COMMENT_NODE != nodeType) && (PROCESSING_INSTRUCTION_NODE != nodeType)) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
result = aNewChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK != result) {
return result;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
result = aOldChild->QueryInterface(kIContentIID, (void**)&refContent);
if (NS_OK != result) {
NS_RELEASE(content);
return result;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
if ((nsnull != mProlog) && (0 != mProlog->Count())) {
@ -2165,7 +2167,7 @@ nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNod
}
if (refContent == mRootContent) {
result = NS_ERROR_INVALID_ARG;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
else if ((nsnull != mEpilog) && (0 != mEpilog->Count())) {
index = mEpilog->IndexOf(refContent);
@ -2203,12 +2205,12 @@ nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
nsIContent *content;
if (nsnull == aOldChild) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_NULL_POINTER;
}
result = aOldChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK != result) {
return result;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
if ((nsnull != mProlog) && (0 != mProlog->Count())) {
@ -2221,7 +2223,7 @@ nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
}
if (content == mRootContent) {
result = NS_ERROR_INVALID_ARG;
result = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
else if ((nsnull != mEpilog) && (0 != mEpilog->Count())) {
index = mEpilog->IndexOf(content);

Просмотреть файл

@ -25,6 +25,7 @@
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsDOMError.h"
static NS_DEFINE_IID(kIDOMDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID);
@ -295,7 +296,8 @@ nsDocumentFragment::GetNodeValue(nsString& aNodeValue)
NS_IMETHODIMP
nsDocumentFragment::SetNodeValue(const nsString& aNodeValue)
{
return NS_OK;
// The node value can't be modified
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
NS_IMETHODIMP

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsVoidArray.h"
#include "nsINameSpaceManager.h"
#include "nsITextContent.h"
#include "nsDOMError.h"
extern const nsIID kIDOMCharacterDataIID;
extern const nsIID kIDOMNodeIID;
@ -77,17 +78,17 @@ struct nsGenericDOMDataNode {
}
nsresult InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
nsIDOMNode** aReturn) {
return NS_ERROR_FAILURE;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
nsIDOMNode** aReturn) {
return NS_ERROR_FAILURE;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) {
return NS_ERROR_FAILURE;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) {
return NS_ERROR_FAILURE;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult GetOwnerDocument(nsIDOMDocument** aOwnerDocument);

Просмотреть файл

@ -58,6 +58,7 @@
#include "nsContentList.h"
#include "prprf.h"
#include "prmem.h"
#include "nsDOMError.h"
#include "nsLayoutAtoms.h"
#include "nsHTMLAtoms.h"
@ -244,7 +245,8 @@ nsGenericElement::GetNodeValue(nsString& aNodeValue)
nsresult
nsGenericElement::SetNodeValue(const nsString& aNodeValue)
{
return NS_OK;
// The node value can't be modified
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult
@ -1490,7 +1492,7 @@ nsGenericContainerElement::InsertBefore(nsIDOMNode* aNewChild,
*aReturn = nsnull;
if (nsnull == aNewChild) {
return NS_OK;/* XXX wrong error value */
return NS_ERROR_NULL_POINTER;
}
// Check if this is a document fragment. If it is, we need
@ -1560,6 +1562,9 @@ nsGenericContainerElement::InsertBefore(nsIDOMNode* aNewChild,
}
NS_IF_RELEASE(refContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
NS_RELEASE(docFrag);
}
else {
@ -1598,8 +1603,14 @@ nsGenericContainerElement::InsertBefore(nsIDOMNode* aNewChild,
SetDocumentInChildrenOf(newContent, mDocument);
res = InsertChildAt(newContent, pos, PR_TRUE);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(refContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
}
NS_RELEASE(newContent);
@ -1607,6 +1618,9 @@ nsGenericContainerElement::InsertBefore(nsIDOMNode* aNewChild,
*aReturn = aNewChild;
NS_ADDREF(aNewChild);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
return res;
@ -1619,7 +1633,10 @@ nsGenericContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
{
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_OK;
return NS_ERROR_NULL_POINTER;
}
if (nsnull == aNewChild) {
return NS_ERROR_NULL_POINTER;
}
nsIContent* content = nsnull;
nsresult res = aOldChild->QueryInterface(kIContentIID, (void**)&content);
@ -1679,6 +1696,9 @@ nsGenericContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
}
NS_RELEASE(docFragContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
NS_RELEASE(docFrag);
}
else {
@ -1701,12 +1721,21 @@ nsGenericContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
}
NS_RELEASE(newContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(content);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
return res;
}
@ -1716,6 +1745,10 @@ nsGenericContainerElement::RemoveChild(nsIDOMNode* aOldChild,
{
nsIContent* content = nsnull;
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_ERROR_NULL_POINTER;
}
nsresult res = aOldChild->QueryInterface(kIContentIID, (void**)&content);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_OK == res) {
@ -1726,8 +1759,14 @@ nsGenericContainerElement::RemoveChild(nsIDOMNode* aOldChild,
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(content);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
return res;
}

Просмотреть файл

@ -56,6 +56,7 @@
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsINameSpaceManager.h"
#include "nsDOMError.h"
#include "nsIHTMLContentContainer.h"
#include "nsHTMLParts.h"
@ -2380,7 +2381,7 @@ nsGenericHTMLContainerElement::InsertBefore(nsIDOMNode* aNewChild,
*aReturn = nsnull;
if (nsnull == aNewChild) {
return NS_OK;/* XXX wrong error value */
return NS_ERROR_NULL_POINTER;
}
// Check if this is a document fragment. If it is, we need
@ -2450,6 +2451,9 @@ nsGenericHTMLContainerElement::InsertBefore(nsIDOMNode* aNewChild,
}
NS_IF_RELEASE(refContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
NS_RELEASE(docFrag);
}
else {
@ -2488,8 +2492,14 @@ nsGenericHTMLContainerElement::InsertBefore(nsIDOMNode* aNewChild,
SetDocumentInChildrenOf(newContent, mDocument);
res = InsertChildAt(newContent, pos, PR_TRUE);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(refContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
}
NS_RELEASE(newContent);
@ -2497,6 +2507,9 @@ nsGenericHTMLContainerElement::InsertBefore(nsIDOMNode* aNewChild,
*aReturn = aNewChild;
NS_ADDREF(aNewChild);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
return res;
@ -2509,7 +2522,7 @@ nsGenericHTMLContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
{
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_OK;
return NS_ERROR_NULL_POINTER;
}
if (nsnull == aNewChild) {
return NS_ERROR_NULL_POINTER;
@ -2522,7 +2535,7 @@ nsGenericHTMLContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
IndexOf(content, pos);
if (pos >= 0) {
nsIContent* newContent = nsnull;
res = aNewChild->QueryInterface(kIContentIID, (void**)&newContent);
nsresult res = aNewChild->QueryInterface(kIContentIID, (void**)&newContent);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_OK == res) {
// Check if this is a document fragment. If it is, we need
@ -2572,6 +2585,9 @@ nsGenericHTMLContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
}
NS_RELEASE(docFragContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
NS_RELEASE(docFrag);
}
else {
@ -2587,19 +2603,28 @@ nsGenericHTMLContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
}
NS_RELEASE(oldParent);
}
SetDocumentInChildrenOf(newContent, mDocument);
res = ReplaceChildAt(newContent, pos, PR_TRUE);
}
}
NS_RELEASE(newContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(content);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
return res;
}
@ -2607,15 +2632,15 @@ nsresult
nsGenericHTMLContainerElement::RemoveChild(nsIDOMNode* aOldChild,
nsIDOMNode** aReturn)
{
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_OK;
}
nsIContent* content = nsnull;
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_ERROR_NULL_POINTER;
}
nsresult res = aOldChild->QueryInterface(kIContentIID, (void**)&content);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_SUCCEEDED(res)) {
if (NS_OK == res) {
PRInt32 pos;
IndexOf(content, pos);
if (pos >= 0) {
@ -2623,8 +2648,15 @@ nsGenericHTMLContainerElement::RemoveChild(nsIDOMNode* aOldChild,
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(content);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
return res;
}

Просмотреть файл

@ -57,6 +57,7 @@
#include "CNavDTD.h"
#include "nsIScriptGlobalObject.h"
#include "nsContentList.h"
#include "nsDOMError.h"
#ifndef NECKO
#include "nsINetService.h"
@ -1010,7 +1011,7 @@ nsHTMLDocument::CreateProcessingInstruction(const nsString& aTarget,
// There are no PIs for HTML
*aReturn = nsnull;
return NS_OK;
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
@ -1020,7 +1021,7 @@ nsHTMLDocument::CreateCDATASection(const nsString& aData,
// There are no CDATASections in HTML
*aReturn = nsnull;
return NS_OK;
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
@ -1030,7 +1031,7 @@ nsHTMLDocument::CreateEntityReference(const nsString& aName,
// There are no EntityReferences in HTML
*aReturn = nsnull;
return NS_OK;
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}

Просмотреть файл

@ -94,22 +94,37 @@ nsDOMAttribute::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMPL_ADDREF(nsDOMAttribute)
NS_IMPL_RELEASE(nsDOMAttribute)
void
NS_IMETHODIMP
nsDOMAttribute::DropReference()
{
mContent = nsnull;
return NS_OK;
}
void
NS_IMETHODIMP
nsDOMAttribute::SetContent(nsIContent* aContent)
{
mContent = aContent;
return NS_OK;
}
void
NS_IMETHODIMP
nsDOMAttribute::GetContent(nsIContent** aContent)
{
*aContent = mContent;
NS_IF_ADDREF(mContent);
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::SetName(const nsString& aName)
{
mName=aName;
return NS_OK;
}
nsresult

Просмотреть файл

@ -35,9 +35,10 @@ class nsDOMAttribute;
class nsIDOMAttributePrivate : public nsISupports {
public:
virtual void DropReference() = 0;
virtual void SetContent(nsIContent* aContent) = 0;
virtual void SetName(const nsString& aName) = 0;
NS_IMETHOD DropReference() = 0;
NS_IMETHOD SetContent(nsIContent* aContent) = 0;
NS_IMETHOD GetContent(nsIContent** aContent) = 0;
NS_IMETHOD SetName(const nsString& aName) = 0;
};
// bogus child list for an attribute
@ -104,9 +105,10 @@ public:
NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument);
// nsIDOMAttributePrivate interface
virtual void DropReference();
virtual void SetContent(nsIContent* aContent);
virtual void SetName(const nsString& aName);
NS_IMETHOD DropReference();
NS_IMETHOD SetContent(nsIContent* aContent);
NS_IMETHOD GetContent(nsIContent** aContent);
NS_IMETHOD SetName(const nsString& aName);
private:
nsIContent* mContent;

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsIContent.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsINameSpaceManager.h"
#include "nsDOMError.h"
static NS_DEFINE_IID(kIDOMNamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kIDOMAttrIID, NS_IDOMATTR_IID);
@ -264,7 +265,11 @@ nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn)
nsresult result = NS_OK;
nsIDOMAttr* attribute;
if ((nsnull != mContent) && (nsnull != aNode)) {
if (nsnull == aNode) {
return NS_ERROR_NULL_POINTER;
}
if (nsnull != mContent) {
result = aNode->QueryInterface(kIDOMAttrIID, (void**)&attribute);
if (NS_OK == result) {
PLHashTable* attrHash;
@ -321,26 +326,39 @@ nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn)
attribute->GetValue(value);
// Associate the new attribute with the content
// XXX Need to fail if it's already associated with other
// content
key = name.ToNewCString();
result = attribute->QueryInterface(kIDOMAttributePrivateIID,
(void **)&attrPrivate);
if (NS_OK == result) {
attrPrivate->SetContent(mContent);
attrPrivate->SetName(name);
if (NS_SUCCEEDED(result)) {
nsIContent* owner;
attrPrivate->GetContent(&owner);
if (owner) {
// The old attribute is already associated with another
// piece of content.
result = NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR;
NS_RELEASE(owner);
}
else {
attrPrivate->SetContent(mContent);
attrPrivate->SetName(name);
NS_RELEASE(attrPrivate);
// Add the new attribute node to the hash table (maintaining
// a reference to it)
PL_HashTableAdd(attrHash, key, attribute);
// Set the attribute on the content
result = mContent->SetAttribute(nameSpaceID, nameAtom, value, PR_TRUE);
NS_IF_RELEASE(nameAtom);
}
NS_RELEASE(attrPrivate);
}
// Add the new attribute node to the hash table (maintaining
// a reference to it)
PL_HashTableAdd(attrHash, key, attribute);
// Set the attribute on the content
result = mContent->SetAttribute(nameSpaceID, nameAtom, value, PR_TRUE);
NS_IF_RELEASE(nameAtom);
}
}
else {
result = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
else {
*aReturn = nsnull;
@ -400,6 +418,7 @@ nsDOMAttributeMap::RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)
NS_RELEASE(attribute);
}
else {
result = NS_ERROR_DOM_NOT_FOUND_ERR;
*aReturn = nsnull;
}

Просмотреть файл

@ -76,6 +76,7 @@
#include "nsIDOMSelection.h"
#include "nsIDOMRange.h"
#include "nsIEnumerator.h"
#include "nsDOMError.h"
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
@ -1919,7 +1920,8 @@ nsDocument::CreateElementWithNameSpace(const nsString& aTagName,
const nsString& aNameSpace,
nsIDOMElement** aReturn)
{
return NS_OK;
*aReturn = nsnull;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
@ -1948,7 +1950,7 @@ nsDocument::GetNodeValue(nsString& aNodeValue)
NS_IMETHODIMP
nsDocument::SetNodeValue(const nsString& aNodeValue)
{
return NS_OK;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
NS_IMETHODIMP
@ -2066,17 +2068,17 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNod
nsIContent *content, *refContent = nsnull;
if (nsnull == aNewChild) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_NULL_POINTER;
}
aNewChild->GetNodeType(&nodeType);
if ((COMMENT_NODE != nodeType) && (PROCESSING_INSTRUCTION_NODE != nodeType)) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
result = aNewChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK != result) {
return result;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
if (nsnull == aRefChild) {
@ -2086,7 +2088,7 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNod
result = aRefChild->QueryInterface(kIContentIID, (void**)&refContent);
if (NS_OK != result) {
NS_RELEASE(content);
return result;
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
if ((nsnull != mProlog) && (0 != mProlog->Count())) {
@ -2134,23 +2136,23 @@ nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNod
nsIContent *content, *refContent;
if ((nsnull == aNewChild) || (nsnull == aOldChild)) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_NULL_POINTER;
}
aNewChild->GetNodeType(&nodeType);
if ((COMMENT_NODE != nodeType) && (PROCESSING_INSTRUCTION_NODE != nodeType)) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
result = aNewChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK != result) {
return result;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
result = aOldChild->QueryInterface(kIContentIID, (void**)&refContent);
if (NS_OK != result) {
NS_RELEASE(content);
return result;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
if ((nsnull != mProlog) && (0 != mProlog->Count())) {
@ -2165,7 +2167,7 @@ nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNod
}
if (refContent == mRootContent) {
result = NS_ERROR_INVALID_ARG;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
else if ((nsnull != mEpilog) && (0 != mEpilog->Count())) {
index = mEpilog->IndexOf(refContent);
@ -2203,12 +2205,12 @@ nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
nsIContent *content;
if (nsnull == aOldChild) {
return NS_ERROR_INVALID_ARG;
return NS_ERROR_NULL_POINTER;
}
result = aOldChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK != result) {
return result;
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
if ((nsnull != mProlog) && (0 != mProlog->Count())) {
@ -2221,7 +2223,7 @@ nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
}
if (content == mRootContent) {
result = NS_ERROR_INVALID_ARG;
result = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
else if ((nsnull != mEpilog) && (0 != mEpilog->Count())) {
index = mEpilog->IndexOf(content);

Просмотреть файл

@ -25,6 +25,7 @@
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsDOMError.h"
static NS_DEFINE_IID(kIDOMDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID);
@ -295,7 +296,8 @@ nsDocumentFragment::GetNodeValue(nsString& aNodeValue)
NS_IMETHODIMP
nsDocumentFragment::SetNodeValue(const nsString& aNodeValue)
{
return NS_OK;
// The node value can't be modified
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
NS_IMETHODIMP

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsVoidArray.h"
#include "nsINameSpaceManager.h"
#include "nsITextContent.h"
#include "nsDOMError.h"
extern const nsIID kIDOMCharacterDataIID;
extern const nsIID kIDOMNodeIID;
@ -77,17 +78,17 @@ struct nsGenericDOMDataNode {
}
nsresult InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
nsIDOMNode** aReturn) {
return NS_ERROR_FAILURE;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
nsIDOMNode** aReturn) {
return NS_ERROR_FAILURE;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) {
return NS_ERROR_FAILURE;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) {
return NS_ERROR_FAILURE;
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult GetOwnerDocument(nsIDOMDocument** aOwnerDocument);

Просмотреть файл

@ -58,6 +58,7 @@
#include "nsContentList.h"
#include "prprf.h"
#include "prmem.h"
#include "nsDOMError.h"
#include "nsLayoutAtoms.h"
#include "nsHTMLAtoms.h"
@ -244,7 +245,8 @@ nsGenericElement::GetNodeValue(nsString& aNodeValue)
nsresult
nsGenericElement::SetNodeValue(const nsString& aNodeValue)
{
return NS_OK;
// The node value can't be modified
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
nsresult
@ -1490,7 +1492,7 @@ nsGenericContainerElement::InsertBefore(nsIDOMNode* aNewChild,
*aReturn = nsnull;
if (nsnull == aNewChild) {
return NS_OK;/* XXX wrong error value */
return NS_ERROR_NULL_POINTER;
}
// Check if this is a document fragment. If it is, we need
@ -1560,6 +1562,9 @@ nsGenericContainerElement::InsertBefore(nsIDOMNode* aNewChild,
}
NS_IF_RELEASE(refContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
NS_RELEASE(docFrag);
}
else {
@ -1598,8 +1603,14 @@ nsGenericContainerElement::InsertBefore(nsIDOMNode* aNewChild,
SetDocumentInChildrenOf(newContent, mDocument);
res = InsertChildAt(newContent, pos, PR_TRUE);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(refContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
}
NS_RELEASE(newContent);
@ -1607,6 +1618,9 @@ nsGenericContainerElement::InsertBefore(nsIDOMNode* aNewChild,
*aReturn = aNewChild;
NS_ADDREF(aNewChild);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
return res;
@ -1619,7 +1633,10 @@ nsGenericContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
{
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_OK;
return NS_ERROR_NULL_POINTER;
}
if (nsnull == aNewChild) {
return NS_ERROR_NULL_POINTER;
}
nsIContent* content = nsnull;
nsresult res = aOldChild->QueryInterface(kIContentIID, (void**)&content);
@ -1679,6 +1696,9 @@ nsGenericContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
}
NS_RELEASE(docFragContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
NS_RELEASE(docFrag);
}
else {
@ -1701,12 +1721,21 @@ nsGenericContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
}
NS_RELEASE(newContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(content);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
return res;
}
@ -1716,6 +1745,10 @@ nsGenericContainerElement::RemoveChild(nsIDOMNode* aOldChild,
{
nsIContent* content = nsnull;
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_ERROR_NULL_POINTER;
}
nsresult res = aOldChild->QueryInterface(kIContentIID, (void**)&content);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_OK == res) {
@ -1726,8 +1759,14 @@ nsGenericContainerElement::RemoveChild(nsIDOMNode* aOldChild,
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(content);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
return res;
}

Просмотреть файл

@ -56,6 +56,7 @@
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsINameSpaceManager.h"
#include "nsDOMError.h"
#include "nsIHTMLContentContainer.h"
#include "nsHTMLParts.h"
@ -2380,7 +2381,7 @@ nsGenericHTMLContainerElement::InsertBefore(nsIDOMNode* aNewChild,
*aReturn = nsnull;
if (nsnull == aNewChild) {
return NS_OK;/* XXX wrong error value */
return NS_ERROR_NULL_POINTER;
}
// Check if this is a document fragment. If it is, we need
@ -2450,6 +2451,9 @@ nsGenericHTMLContainerElement::InsertBefore(nsIDOMNode* aNewChild,
}
NS_IF_RELEASE(refContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
NS_RELEASE(docFrag);
}
else {
@ -2488,8 +2492,14 @@ nsGenericHTMLContainerElement::InsertBefore(nsIDOMNode* aNewChild,
SetDocumentInChildrenOf(newContent, mDocument);
res = InsertChildAt(newContent, pos, PR_TRUE);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(refContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
}
NS_RELEASE(newContent);
@ -2497,6 +2507,9 @@ nsGenericHTMLContainerElement::InsertBefore(nsIDOMNode* aNewChild,
*aReturn = aNewChild;
NS_ADDREF(aNewChild);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
}
return res;
@ -2509,7 +2522,7 @@ nsGenericHTMLContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
{
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_OK;
return NS_ERROR_NULL_POINTER;
}
if (nsnull == aNewChild) {
return NS_ERROR_NULL_POINTER;
@ -2522,7 +2535,7 @@ nsGenericHTMLContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
IndexOf(content, pos);
if (pos >= 0) {
nsIContent* newContent = nsnull;
res = aNewChild->QueryInterface(kIContentIID, (void**)&newContent);
nsresult res = aNewChild->QueryInterface(kIContentIID, (void**)&newContent);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_OK == res) {
// Check if this is a document fragment. If it is, we need
@ -2572,6 +2585,9 @@ nsGenericHTMLContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
}
NS_RELEASE(docFragContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
NS_RELEASE(docFrag);
}
else {
@ -2587,19 +2603,28 @@ nsGenericHTMLContainerElement::ReplaceChild(nsIDOMNode* aNewChild,
}
NS_RELEASE(oldParent);
}
SetDocumentInChildrenOf(newContent, mDocument);
res = ReplaceChildAt(newContent, pos, PR_TRUE);
}
}
NS_RELEASE(newContent);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(content);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
return res;
}
@ -2607,15 +2632,15 @@ nsresult
nsGenericHTMLContainerElement::RemoveChild(nsIDOMNode* aOldChild,
nsIDOMNode** aReturn)
{
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_OK;
}
nsIContent* content = nsnull;
*aReturn = nsnull;
if (nsnull == aOldChild) {
return NS_ERROR_NULL_POINTER;
}
nsresult res = aOldChild->QueryInterface(kIContentIID, (void**)&content);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_SUCCEEDED(res)) {
if (NS_OK == res) {
PRInt32 pos;
IndexOf(content, pos);
if (pos >= 0) {
@ -2623,8 +2648,15 @@ nsGenericHTMLContainerElement::RemoveChild(nsIDOMNode* aOldChild,
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
else {
res = NS_ERROR_DOM_NOT_FOUND_ERR;
}
NS_RELEASE(content);
}
else {
res = NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
return res;
}

Просмотреть файл

@ -57,6 +57,7 @@
#include "CNavDTD.h"
#include "nsIScriptGlobalObject.h"
#include "nsContentList.h"
#include "nsDOMError.h"
#ifndef NECKO
#include "nsINetService.h"
@ -1010,7 +1011,7 @@ nsHTMLDocument::CreateProcessingInstruction(const nsString& aTarget,
// There are no PIs for HTML
*aReturn = nsnull;
return NS_OK;
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
@ -1020,7 +1021,7 @@ nsHTMLDocument::CreateCDATASection(const nsString& aData,
// There are no CDATASections in HTML
*aReturn = nsnull;
return NS_OK;
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
@ -1030,7 +1031,7 @@ nsHTMLDocument::CreateEntityReference(const nsString& aName,
// There are no EntityReferences in HTML
*aReturn = nsnull;
return NS_OK;
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}