script: Properly handle removed iframes in GlobalScope::get_referrer (#32782)

Signed-off-by: newmoneybigbucks <newmoneybigbucks@protonmail.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
newmoneybigbucks 2024-08-07 07:12:19 -04:00 committed by GitHub
parent 9cb0e74cdc
commit 3fca6e015f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 8 deletions

View file

@ -2428,14 +2428,18 @@ impl GlobalScope {
// Substep 3.1.3
while url.as_str() == "about:srcdoc" {
document = document
.browsing_context()
.expect("iframe should have browsing context")
.parent()
.expect("iframes browsing_context should have parent")
.document()
.expect("iframes parent should have document");
// Return early if we cannot get a parent document. This might happen if
// this iframe was already removed from the parent page.
let Some(parent_document) =
document.browsing_context().and_then(|browsing_context| {
browsing_context
.parent()
.and_then(|parent| parent.document())
})
else {
return Referrer::NoReferrer;
};
document = parent_document;
url = document.url();
}