Bug 613793 - Raise an exception when trying to append a child to a DocumentType; r=bzbarsky a=jst

This commit is contained in:
Ms2ger 2010-12-04 09:00:19 +01:00
parent c81be225e7
commit 7f800d51a7
4 changed files with 36 additions and 6 deletions

View File

@ -4006,14 +4006,12 @@ nsINode::ReplaceOrInsertBefore(PRBool aReplace, nsINode* aNewChild,
return NS_ERROR_NULL_POINTER;
}
if (IsNodeOfType(eDATA_NODE)) {
if (!IsNodeOfType(eDOCUMENT) &&
!IsNodeOfType(eDOCUMENT_FRAGMENT) &&
!IsElement()) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
if (IsNodeOfType(eATTRIBUTE)) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsIContent* refContent;
nsresult res = NS_OK;
PRInt32 insPos;

View File

@ -421,6 +421,7 @@ _TEST_FILES2 = \
file_x-frame-options_main.html \
file_x-frame-options_page.sjs \
test_createHTMLDocument.html \
test_bug564047.html \
test_bug567350.html \
test_bug574596.html \
test_bug578096.html \

View File

@ -0,0 +1,31 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=564047
-->
<head>
<title>Test for Bug 564047</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=564047">Mozilla Bug 564047</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 564047 **/
try {
document.doctype.appendChild(document.createTextNode("test"));
ok(false, "Should have thrown an exception");
} catch (e) {
ok(e instanceof DOMException, "Should be a DOMException");
is(e.code, DOMException.HIERARCHY_REQUEST_ERR);
}
</script>
</pre>
</body>
</html>

View File

@ -74,7 +74,7 @@ var indexErrTests = ["characterdataindexsizeerrdeletedatacountnegative", "charac
"characterdataindexsizeerrsubstringcountnegative", "hc_characterdataindexsizeerrdeletedatacountnegative",
"hc_characterdataindexsizeerrreplacedatacountnegative", "hc_characterdataindexsizeerrsubstringcountnegative"];
var attributeModTests = ["hc_attrappendchild1", "hc_attrappendchild2", "hc_attrappendchild3", "hc_attrappendchild5",
var attributeModTests = ["hc_attrappendchild1", "hc_attrappendchild3", "hc_attrappendchild5",
"hc_attrappendchild6", "hc_attrchildnodes2", "hc_attrclonenode1", "hc_attrinsertbefore1",
"hc_attrinsertbefore2", "hc_attrinsertbefore3", "hc_attrinsertbefore4", "hc_attrinsertbefore6",
"hc_attrnormalize", "hc_attrremovechild2", "hc_attrreplacechild1", "hc_attrreplacechild2",