<!DOCTYPE html>
<html>
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id="parent"><br id="child"><br id="next"></div>
<script>
test(() => {
let parent = document.querySelector('#parent');
parent.addEventListener('DOMSubtreeModified', () => {
document.body.appendChild(document.querySelector('#next'));
}, {once: true});
let new_node = document.createElement('span');
assert_throws_dom('NotFoundError', () => {
parent.replaceChild(new_node, document.querySelector('#child'));
});
assert_equals(parent.firstChild, null);
assert_equals(new_node.parentNode, null);
assert_equals(new_node.nextSibling, null);
}, 'Re-parenting a reference node should not crash replaceChild().');
</script>
</body>