LibWeb: Don't crash when accessing property in detached Window object

After removing an iframe from the DOM, its contentWindow will be
detached from its browsing context, per spec.

Because the contentWindow is still accessible, we cannot assume that
Window objects always have an associated browsing context.

This needs to be fixed in the spec, but let's add a sensible null check
in the meantime.
This commit is contained in:
Andreas Kling 2024-03-11 09:35:35 +01:00
commit ad843b6e4a
Notes: sideshowbarker 2024-07-17 06:38:11 +09:00
5 changed files with 28 additions and 6 deletions

View file

@ -0,0 +1,11 @@
<script src="../include.js"></script>
<script>
test(() => {
let iframe = document.querySelector("iframe")
let w = iframe.contentWindow;
println(w.getSelection());
iframe.remove();
println(w.getSelection());
println("PASS (didn't crash)");
})
</script><iframe></iframe>