serenity
serenity copied to clipboard
LibWeb: Don't crash in offset_parent() if no ancestor element found
The specification says the final step of this algorithm is to return null. Previously, the browser would crash if the content of an iframe was appended to the document before its offsetParent property was queried.
Fixes this WPT test (and probably others): the-xhtml-syntax/parsing-xhtml-documents/adopt-while-parsing-001
This fix also prevents these WPT tests from crashing WebContent, although it doesn't fix them:
- css/css-anchor-position/anchor-name-cross-shadow
- css/css-anchor-position/anchor-name-in-shadow
- css/css-anchor-position/position-fallback-tree-scoped
- css/cssom-view/elementsFromPoint-shadowroot
- css/cssom-view/scrollIntoView-shadow
I believe a more complete solution would be to implement offsetParent from this specification. This would allow us to handle calling offsetParent for elements within a shadow root, which may fix the above 5 tests.
In the meantime, I think this change is still worth making, as it stops WebContent from crashing even if it doesn't always work as expected.