Bug 553896 - Node.isEqualNode(null) shouldn't throw. r=smaug

This commit is contained in:
Ms2ger@gmail.com 2010-03-22 17:06:57 +01:00
parent 0152250bfd
commit f42ea8604f
5 changed files with 80 additions and 6 deletions

View File

@ -539,10 +539,11 @@ NS_IMETHODIMP
nsDOMAttribute::IsEqualNode(nsIDOMNode* aOther,
PRBool* aReturn)
{
NS_ENSURE_ARG_POINTER(aOther);
*aReturn = PR_FALSE;
if (!aOther)
return NS_OK;
// Node type check by QI. We also reuse this later.
nsCOMPtr<nsIAttribute> aOtherAttr = do_QueryInterface(aOther);
if (!aOtherAttr) {

View File

@ -5668,10 +5668,11 @@ nsDocument::IsSameNode(nsIDOMNode* aOther, PRBool* aReturn)
NS_IMETHODIMP
nsDocument::IsEqualNode(nsIDOMNode* aOther, PRBool* aReturn)
{
NS_ENSURE_ARG_POINTER(aOther);
*aReturn = PR_FALSE;
if (!aOther)
return NS_OK;
// Node type check by QI. We also reuse this later.
nsCOMPtr<nsIDocument> aOtherDoc = do_QueryInterface(aOther);
if (!aOtherDoc) {

View File

@ -894,10 +894,11 @@ nsNode3Tearoff::AreNodesEqual(nsIContent* aContent1,
NS_IMETHODIMP
nsNode3Tearoff::IsEqualNode(nsIDOMNode* aOther, PRBool* aReturn)
{
NS_ENSURE_ARG_POINTER(aOther);
*aReturn = PR_FALSE;
if (!aOther)
return NS_OK;
// Since we implement nsIContent, aOther must as well.
nsCOMPtr<nsIContent> aOtherContent = do_QueryInterface(aOther);
// Documents and attributes don't implement nsIContent.

View File

@ -361,6 +361,7 @@ _TEST_FILES = test_bug5141.html \
test_bug548463.html \
test_bug545644.html \
test_bug545644.xhtml \
test_bug553896.xhtml \
$(NULL)
# This test fails on the Mac for some reason

View File

@ -0,0 +1,70 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=553896
-->
<head>
<title>Test for Bug 553896</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=553896">Mozilla Bug 553896</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
<![CDATA[
/** Test for Bug 553896 **/
try {
ok(!document.createElement("foo").isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
try {
ok(!document.createAttribute("foo").isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
try {
ok(!document.createTextNode("foo").isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
try {
ok(!document.createCDATASection("foo").isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
try {
ok(!document.createProcessingInstruction("foo", "bar").isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
try {
ok(!document.createComment("foo").isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
try {
ok(!document.isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
try {
ok(!document.implementation.createDocumentType("html", "", "").isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
try {
ok(!document.createDocumentFragment().isEqualNode(null), "Node is equal to null?");
} catch (e) {
ok(false, "Exception was raised.");
}
]]>
</script>
</pre>
</body>
</html>