Skip to content

Commit

Permalink
Merge pull request #822 from plehegar/plh/insertBefore-fix
Browse files Browse the repository at this point in the history
Better exception handling when creating nodes
  • Loading branch information
plehegar committed Mar 31, 2014
2 parents 9361e94 + 51fcefa commit d64f7d7
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions dom/nodes/Node-insertBefore.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
function testLeafNode(node) {
function testLeafNode(nodeName, createNodeFunction) {
test(function() {
var node = createNodeFunction();
assert_throws(new TypeError(), function() { node.insertBefore(null, null) })
}, "Calling insertBefore with a non-Node first argument on a leaf node " + format_value(node) + " must throw TypeError.")
}, "Calling insertBefore with a non-Node first argument on a leaf node " + nodeName + " must throw TypeError.")
test(function() {
var node = createNodeFunction();
assert_throws("HIERARCHY_REQUEST_ERR", function() { node.insertBefore(document.createTextNode("fail"), null) })
// Would be step 2.
assert_throws("HIERARCHY_REQUEST_ERR", function() { node.insertBefore(node, null) })
// Would be step 3.
assert_throws("HIERARCHY_REQUEST_ERR", function() { node.insertBefore(node, document.createTextNode("child")) })
}, "Calling insertBefore an a leaf node " + format_value(node) + " must throw HIERARCHY_REQUEST_ERR.")
}, "Calling insertBefore an a leaf node " + nodeName + " must throw HIERARCHY_REQUEST_ERR.")
}

test(function() {
Expand All @@ -24,13 +26,10 @@
assert_throws(new TypeError(), function() { document.body.insertBefore({'a':'b'}, document.body.firstChild) })
}, "Calling insertBefore with a non-Node first argument must throw TypeError.")

test(function() {
// Step 1.
testLeafNode(document.doctype)
testLeafNode(document.createTextNode("Foo"))
testLeafNode(document.createComment("Foo"))
testLeafNode(document.createProcessingInstruction("foo", "bar"))
}, "Must be able to create all leaf nodes in HTML documents.")
testLeafNode("DocumentType", function () { return document.doctype; } )
testLeafNode("Text", function () { return document.createTextNode("Foo") })
testLeafNode("Comment", function () { return document.createComment("Foo") })
testLeafNode("ProcessingInstruction", function () { return document.createProcessingInstruction("foo", "bar") })

test(function() {
// Step 2.
Expand Down

0 comments on commit d64f7d7

Please sign in to comment.