<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="xpath-test-pre.js"></script>
</head>
<body>
<p>Test that iterators are invalidated even if the original context is detached.</p>
<div id="console"></div>
<script>
var doc = document.implementation.createDocument(null, "doc", null);
var root = doc.createElement("div");
root.appendChild(doc.createElement("span"));
root.appendChild(doc.createElement("p"));

var result = doc.evaluate(".//*", root, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
shouldBe("result.invalidIteratorState", "false");
shouldBe("result.iterateNext().tagName", "'span'");

debug("Modifying the document...");
doc.documentElement.setAttribute("foo", "bar");

shouldBe("result.invalidIteratorState", "true");
shouldThrow("result.iterateNext()");

</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
