<!DOCTYPE html>
<html>
Test passes if it does not crash.
<body>
<div id="a"></div>
<div id="b">
<iframe id="f" src="about:blank"></iframe>
</div>

<script>
if (window.testRunner)
    testRunner.dumpAsText();

var listenerActive = false;
var fDoc = document.getElementById('f').contentDocument;
fDoc.open();

// Waits for frame f to finish loading, then moves div b into div a.
moveDivBIntoDivA = function() {
    if (fDoc.readyState == 'loading') {
        if (!listenerActive) {
            fDoc.addEventListener('readystatechange', moveDivBIntoDivA);
            listenerActive = true;
        }
        return;
    }
    document.getElementById('a').appendChild(document.getElementById('b'));
};

moveDivBIntoDivA();
fDoc.close();
</script>
</body>
</html>
