Bug 661327 - Warn in to-be-removed Attr functions; r=sicking

This commit is contained in:
Ms2ger 2011-06-23 10:30:48 +02:00
parent 8d778c04d5
commit 474ed763c5
5 changed files with 286 additions and 13 deletions

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ms2ger <ms2ger@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -1520,6 +1521,44 @@ public:
virtual Element* FindImageMap(const nsAString& aNormalizedMapName) = 0;
enum DeprecatedOperations {
eGetAttributeNode = 0,
eSetAttributeNode,
eGetAttributeNodeNS,
eSetAttributeNodeNS,
eRemoveAttributeNode,
eCreateAttribute,
eCreateAttributeNS,
eSpecified,
eOwnerElement,
eNodeName,
eNodeValue,
eNodeType,
eParentNode,
eChildNodes,
eHasChildNodes,
eHasAttributes,
eFirstChild,
eLastChild,
ePreviousSibling,
eNextSibling,
eAttributes,
eInsertBefore,
eReplaceChild,
eRemoveChild,
eAppendChild,
eCloneNode,
eOwnerDocument,
eNormalize,
eIsSupported,
eIsEqualNode,
eTextContent
};
void WarnOnceAbout(DeprecatedOperations aOperation);
private:
PRUint32 mWarnedAbout;
protected:
~nsIDocument()
{

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ms2ger <ms2ger@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -275,10 +276,15 @@ nsDOMAttribute::SetValue(const nsAString& aValue)
return rv;
}
NS_IMETHODIMP
nsDOMAttribute::GetSpecified(PRBool* aSpecified)
{
NS_ENSURE_ARG_POINTER(aSpecified);
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eSpecified);
}
*aSpecified = PR_TRUE;
return NS_OK;
}
@ -288,6 +294,11 @@ nsDOMAttribute::GetOwnerElement(nsIDOMElement** aOwnerElement)
{
NS_ENSURE_ARG_POINTER(aOwnerElement);
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eOwnerElement);
}
nsIContent* content = GetContentInternal();
if (content) {
return CallQueryInterface(content, aOwnerElement);
@ -301,18 +312,33 @@ nsDOMAttribute::GetOwnerElement(nsIDOMElement** aOwnerElement)
NS_IMETHODIMP
nsDOMAttribute::GetNodeName(nsAString& aNodeName)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eNodeName);
}
return GetName(aNodeName);
}
NS_IMETHODIMP
nsDOMAttribute::GetNodeValue(nsAString& aNodeValue)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eNodeValue);
}
return GetValue(aNodeValue);
}
NS_IMETHODIMP
nsDOMAttribute::SetNodeValue(const nsAString& aNodeValue)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eNodeValue);
}
return SetValue(aNodeValue);
}
@ -321,6 +347,11 @@ nsDOMAttribute::GetNodeType(PRUint16* aNodeType)
{
NS_ENSURE_ARG_POINTER(aNodeType);
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eNodeType);
}
*aNodeType = (PRUint16)nsIDOMNode::ATTRIBUTE_NODE;
return NS_OK;
}
@ -330,6 +361,11 @@ nsDOMAttribute::GetParentNode(nsIDOMNode** aParentNode)
{
NS_ENSURE_ARG_POINTER(aParentNode);
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eParentNode);
}
*aParentNode = nsnull;
return NS_OK;
}
@ -337,12 +373,22 @@ nsDOMAttribute::GetParentNode(nsIDOMNode** aParentNode)
NS_IMETHODIMP
nsDOMAttribute::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eChildNodes);
}
return nsINode::GetChildNodes(aChildNodes);
}
NS_IMETHODIMP
nsDOMAttribute::HasChildNodes(PRBool* aHasChildNodes)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eHasChildNodes);
}
*aHasChildNodes = mFirstChild != nsnull;
return NS_OK;
@ -353,6 +399,11 @@ nsDOMAttribute::HasAttributes(PRBool* aHasAttributes)
{
NS_ENSURE_ARG_POINTER(aHasAttributes);
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eHasAttributes);
}
*aHasAttributes = PR_FALSE;
return NS_OK;
@ -363,6 +414,11 @@ nsDOMAttribute::GetFirstChild(nsIDOMNode** aFirstChild)
{
*aFirstChild = nsnull;
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eFirstChild);
}
if (mFirstChild) {
CallQueryInterface(mFirstChild, aFirstChild);
}
@ -373,6 +429,10 @@ nsDOMAttribute::GetFirstChild(nsIDOMNode** aFirstChild)
NS_IMETHODIMP
nsDOMAttribute::GetLastChild(nsIDOMNode** aLastChild)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eLastChild);
}
return GetFirstChild(aLastChild);
}
@ -381,6 +441,11 @@ nsDOMAttribute::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
NS_ENSURE_ARG_POINTER(aPreviousSibling);
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::ePreviousSibling);
}
*aPreviousSibling = nsnull;
return NS_OK;
}
@ -390,6 +455,11 @@ nsDOMAttribute::GetNextSibling(nsIDOMNode** aNextSibling)
{
NS_ENSURE_ARG_POINTER(aNextSibling);
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eNextSibling);
}
*aNextSibling = nsnull;
return NS_OK;
}
@ -399,6 +469,11 @@ nsDOMAttribute::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
NS_ENSURE_ARG_POINTER(aAttributes);
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eAttributes);
}
*aAttributes = nsnull;
return NS_OK;
}
@ -406,24 +481,44 @@ nsDOMAttribute::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
NS_IMETHODIMP
nsDOMAttribute::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eInsertBefore);
}
return ReplaceOrInsertBefore(PR_FALSE, aNewChild, aRefChild, aReturn);
}
NS_IMETHODIMP
nsDOMAttribute::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eReplaceChild);
}
return ReplaceOrInsertBefore(PR_TRUE, aNewChild, aOldChild, aReturn);
}
NS_IMETHODIMP
nsDOMAttribute::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eRemoveChild);
}
return nsINode::RemoveChild(aOldChild, aReturn);
}
NS_IMETHODIMP
nsDOMAttribute::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eAppendChild);
}
return InsertBefore(aNewChild, nsnull, aReturn);
}
@ -447,12 +542,22 @@ nsDOMAttribute::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
NS_IMETHODIMP
nsDOMAttribute::CloneNode(PRBool aDeep, nsIDOMNode** aResult)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eCloneNode);
}
return nsNodeUtils::CloneNodeImpl(this, aDeep, PR_TRUE, aResult);
}
NS_IMETHODIMP
nsDOMAttribute::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eOwnerDocument);
}
return nsINode::GetOwnerDocument(aOwnerDocument);
}
@ -479,6 +584,11 @@ nsDOMAttribute::GetLocalName(nsAString& aLocalName)
NS_IMETHODIMP
nsDOMAttribute::Normalize()
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eNormalize);
}
// Nothing to do here
return NS_OK;
}
@ -488,6 +598,10 @@ nsDOMAttribute::IsSupported(const nsAString& aFeature,
const nsAString& aVersion,
PRBool* aReturn)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eIsSupported);
}
return nsGenericElement::InternalIsSupported(static_cast<nsIDOMAttr*>(this),
aFeature, aVersion, aReturn);
}
@ -516,18 +630,30 @@ nsDOMAttribute::CompareDocumentPosition(nsIDOMNode *other,
NS_IMETHODIMP
nsDOMAttribute::IsEqualNode(nsIDOMNode* aOther, PRBool* aResult)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eIsEqualNode);
}
return nsINode::IsEqualNode(aOther, aResult);
}
NS_IMETHODIMP
nsDOMAttribute::GetTextContent(nsAString &aTextContent)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eTextContent);
}
return GetNodeValue(aTextContent);
}
NS_IMETHODIMP
nsDOMAttribute::SetTextContent(const nsAString& aTextContent)
{
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eTextContent);
}
return SetNodeValue(aTextContent);
}

View File

@ -27,6 +27,7 @@
* Pete Collins <petejc@collab.net>
* James Ross <silver@warwickcompsoc.co.uk>
* Ryan Jones <sciguyryan@gmail.com>
* Ms2ger <ms2ger@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -4509,24 +4510,25 @@ nsDocument::CreateAttribute(const nsAString& aName,
nsIDOMAttr** aReturn)
{
*aReturn = nsnull;
WarnOnceAbout(eCreateAttribute);
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED);
nsresult rv = nsContentUtils::CheckQName(aName, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString value;
nsDOMAttribute* attribute;
nsCOMPtr<nsINodeInfo> nodeInfo;
rv = mNodeInfoManager->GetNodeInfo(aName, nsnull, kNameSpaceID_None,
nsIDOMNode::ATTRIBUTE_NODE,
getter_AddRefs(nodeInfo));
NS_ENSURE_SUCCESS(rv, rv);
attribute = new nsDOMAttribute(nsnull, nodeInfo.forget(), value, PR_FALSE);
NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY);
return CallQueryInterface(attribute, aReturn);
nsAutoString value;
nsCOMPtr<nsIDOMAttr> attribute =
new nsDOMAttribute(nsnull, nodeInfo.forget(), value, PR_FALSE);
attribute.forget(aReturn);
return NS_OK;
}
NS_IMETHODIMP
@ -4537,6 +4539,8 @@ nsDocument::CreateAttributeNS(const nsAString & aNamespaceURI,
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
WarnOnceAbout(eCreateAttributeNS);
nsCOMPtr<nsINodeInfo> nodeInfo;
nsresult rv = nsContentUtils::GetNodeInfoFromQName(aNamespaceURI,
aQualifiedName,
@ -4546,11 +4550,10 @@ nsDocument::CreateAttributeNS(const nsAString & aNamespaceURI,
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString value;
nsDOMAttribute* attribute =
nsCOMPtr<nsIDOMAttr> attribute =
new nsDOMAttribute(nsnull, nodeInfo.forget(), value, PR_TRUE);
NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY);
return CallQueryInterface(attribute, aResult);
attribute.forget(aResult);
return NS_OK;
}
NS_IMETHODIMP
@ -8249,6 +8252,56 @@ nsDocument::FindImageMap(const nsAString& aUseMapValue)
return nsnull;
}
static const char* kWarnings[] = {
"GetAttributeNodeWarning",
"SetAttributeNodeWarning",
"GetAttributeNodeNSWarning",
"SetAttributeNodeNSWarning",
"RemoveAttributeNodeWarning",
"CreateAttributeWarning",
"CreateAttributeNSWarning",
"SpecifiedWarning",
"OwnerElementWarning",
"NodeNameWarning",
"NodeValueWarning",
"NodeTypeWarning",
"ParentNodeWarning",
"ChildNodesWarning",
"HasChildNodesWarning",
"HasAttributesWarning",
"FirstChildWarning",
"LastChildWarning",
"PreviousSiblingWarning",
"NextSiblingWarning",
"AttributesWarning",
"InsertBeforeWarning",
"ReplaceChildWarning",
"RemoveChildWarning",
"AppendChildWarning",
"CloneNodeWarning",
"GetOwnerDocumentWarning",
"IsSupportedWarning",
"IsEqualNodeWarning",
"TextContentWarning"
};
void
nsIDocument::WarnOnceAbout(DeprecatedOperations aOperation)
{
PR_STATIC_ASSERT(NS_ARRAY_LENGTH(kWarnings) < 32);
if (mWarnedAbout & (1 << aOperation)) {
return;
}
mWarnedAbout |= (1 << aOperation);
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
kWarnings[aOperation],
nsnull, 0,
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM Core", this);
}
nsresult
nsDocument::AddImage(imgIRequest* aImage)
{

View File

@ -21,6 +21,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ms2ger <ms2ger@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -2468,6 +2469,11 @@ nsGenericElement::GetAttributeNode(const nsAString& aName,
NS_ENSURE_ARG_POINTER(aReturn);
*aReturn = nsnull;
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eGetAttributeNode);
}
nsCOMPtr<nsIDOMNamedNodeMap> map;
nsresult rv = GetAttributes(getter_AddRefs(map));
NS_ENSURE_SUCCESS(rv, rv);
@ -2491,6 +2497,11 @@ nsGenericElement::SetAttributeNode(nsIDOMAttr* aAttribute,
*aReturn = nsnull;
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eSetAttributeNode);
}
nsCOMPtr<nsIDOMNamedNodeMap> map;
nsresult rv = GetAttributes(getter_AddRefs(map));
NS_ENSURE_SUCCESS(rv, rv);
@ -2515,6 +2526,11 @@ nsGenericElement::RemoveAttributeNode(nsIDOMAttr* aAttribute,
*aReturn = nsnull;
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eRemoveAttributeNode);
}
nsCOMPtr<nsIDOMNamedNodeMap> map;
nsresult rv = GetAttributes(getter_AddRefs(map));
NS_ENSURE_SUCCESS(rv, rv);
@ -2610,9 +2626,13 @@ nsGenericElement::GetAttributeNodeNS(const nsAString& aNamespaceURI,
nsIDOMAttr** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
*aReturn = nsnull;
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eGetAttributeNodeNS);
}
nsCOMPtr<nsIDOMNamedNodeMap> map;
nsresult rv = GetAttributes(getter_AddRefs(map));
NS_ENSURE_SUCCESS(rv, rv);
@ -2633,9 +2653,13 @@ nsGenericElement::SetAttributeNodeNS(nsIDOMAttr* aNewAttr,
{
NS_ENSURE_ARG_POINTER(aReturn);
NS_ENSURE_ARG_POINTER(aNewAttr);
*aReturn = nsnull;
nsIDocument* document = GetOwnerDoc();
if (document) {
document->WarnOnceAbout(nsIDocument::eSetAttributeNodeNS);
}
nsCOMPtr<nsIDOMNamedNodeMap> map;
nsresult rv = GetAttributes(getter_AddRefs(map));
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -21,6 +21,7 @@
# Contributor(s):
# Mitch <mstoltz@netscape.com> (original author)
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
# Ms2ger <ms2ger@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
@ -75,3 +76,33 @@ FormValidationInvalidURL=Please enter a URL.
FormValidationPatternMismatch=Please match the requested format.
# LOCALIZATION NOTE (FormValidationPatternMismatchWithTitle): %S is the (possibly truncated) title attribute value.
FormValidationPatternMismatchWithTitle=Please match the requested format: %S.
GetAttributeNodeWarning=Use of getAttributeNode() is deprecated. Use getAttribute() instead.
SetAttributeNodeWarning=Use of setAttributeNode() is deprecated. Use setAttribute() instead.
GetAttributeNodeWarning=Use of getAttributeNodeNS() is deprecated. Use getAttributeNS() instead.
SetAttributeNodeWarning=Use of setAttributeNodeNS() is deprecated. Use setAttributeNS() instead.
RemoveAttributeNodeWarning=Use of removeAttributeNode() is deprecated. Use removeAttribute() instead.
CreateAttribute=Use of document.createAttribute() is deprecated. Use element.setAttribute() instead.
CreateAttributeNS=Use of document.createAttributeNS() is deprecated. Use element.setAttributeNS() instead.
SpecifiedWarning=Use of attributes' specified attribute is deprecated. It always returns true.
OwnerElementWarning=Use of attributes' ownerElement attribute is deprecated.
NodeNameWarning=Use of attributes' nodeName attribute is deprecated. Use name instead.
NodeValueWarning=Use of attributes' nodeValue attribute is deprecated. Use value instead.
NodeTypeWarning=Use of attributes' nodeType attribute is deprecated. It always returns
ParentNodeWarning=Use of attributes' parentNode attribute is deprecated. It always returns null.
ChildNodesWarning=Use of attributes' childNodes attribute is deprecated. It always returns null.
HasChildNodesWarning=Use of attributes' hasChildNodes() is deprecated. It always returns false.
HasAttributesWarning=Use of attributes' hasAttributes() is deprecated. It always returns false.
FirstChildWarning=Use of attributes' firstChild attribute is deprecated. Use value instead.
LastChildWarning=Use of attributes' lastChild attribute is deprecated. Use value instead.
PreviousSiblingWarning=Use of attributes' previousSibling attribute is deprecated. It always returns null.
NextSiblingWarning=Use of attributes' nextSibling attribute is deprecated. It always returns null.
AttributesWarning=Use of attributes' attributes attribute is deprecated. It always returns null.
InsertBeforeWarning=Use of attributes' insertBefore() is deprecated. Use value instead.
ReplaceChildWarning=Use of attributes' replaceChild() is deprecated. Use value instead.
RemoveChildWarning=Use of attributes' removeChild() is deprecated. Use value instead.
AppendChildWarning=Use of attributes' appendChild() is deprecated. Use value instead.
CloneNodeWarning=Use of attributes' cloneNode() is deprecated.
GetOwnerDocumentWarning=Use of attributes' ownerDocument attribute is deprecated.
IsSupportedWarning=Use of attributes' isSupported() is deprecated.
IsEqualNodeWarning=Use of attributes' isEqualNode() is deprecated.
TextContentWarning=Use of attributes' textContent attribute is deprecated. Use value instead.