From bb10b0e301efaa6105ee2fc353e4b552dd5b3da0 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 28 Nov 2024 02:49:34 +1300 Subject: [PATCH] LibWeb: Always assert that principal realm returns a principal realm There was a bug in the HTML proposal where a synthetic realm settings object's principal realm was a shadow realm if there were nested shadow realms, which this assertion catches more directly (rather than later down the track, where it is used). We were meant to also assert for this case, but we were previously returning early. --- Libraries/LibWeb/HTML/Scripting/Environments.cpp | 10 +++++----- Libraries/LibWeb/HTML/Scripting/Environments.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cpp index cbb0f689b9..4b2c0d321b 100644 --- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -360,19 +360,19 @@ JS::Realm& current_principal_realm() } // https://whatpr.org/html/9893/webappapis.html#concept-principal-realm-of-realm -JS::Realm& principal_realm(JS::Realm& realm) +JS::Realm& principal_realm(GC::Ref realm) { - VERIFY(realm.host_defined()); + VERIFY(realm->host_defined()); // 1. If realm.[[HostDefined]] is a synthetic realm settings object, then: - if (is(*realm.host_defined())) { + if (is(*realm->host_defined())) { // 1. Assert: realm is a synthetic realm. // 2. Set realm to the principal realm of realm.[[HostDefined]]. - return static_cast(*realm.host_defined()).synthetic_realm_settings.principal_realm; + realm = static_cast(*realm->host_defined()).synthetic_realm_settings.principal_realm; } // 2. Assert: realm.[[HostDefined]] is an environment settings object and realm is a principal realm. - VERIFY(is(*realm.host_defined())); + VERIFY(is(*realm->host_defined())); // 3. Return realm. return realm; diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.h b/Libraries/LibWeb/HTML/Scripting/Environments.h index a2e75de821..8ff26d6606 100644 --- a/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -149,7 +149,7 @@ JS::Realm& current_principal_realm(); EnvironmentSettingsObject& principal_realm_settings_object(JS::Realm&); EnvironmentSettingsObject& current_principal_settings_object(); -JS::Realm& principal_realm(JS::Realm&); +JS::Realm& principal_realm(GC::Ref); JS::Object& current_principal_global_object(); JS::Realm& relevant_realm(JS::Object const&); EnvironmentSettingsObject& relevant_settings_object(JS::Object const&);