@@ -175,14 +175,14 @@ static JS::ExecutionContext* top_most_script_having_execution_context(JS::VM& vm
175175}
176176
177177// https://html.spec.whatwg.org/multipage/webappapis.html#prepare-to-run-a-callback
178- void EnvironmentSettingsObject:: prepare_to_run_callback ()
178+ void prepare_to_run_callback (JS::Realm& realm )
179179{
180- auto & vm = global_object ().vm ();
180+ auto & vm = realm. global_object ().vm ();
181181
182- // 1. Push settings onto the backup incumbent settings object stack.
182+ // 1. Push realm onto the backup incumbent settings object stack.
183183 // NOTE: The spec doesn't say which event loop's stack to put this on. However, all the examples of the incumbent settings object use iframes and cross browsing context communication to demonstrate the concept.
184184 // This means that it must rely on some global state that can be accessed by all browsing contexts, which is the main thread event loop.
185- HTML::main_thread_event_loop ().push_onto_backup_incumbent_settings_object_stack ({}, * this );
185+ HTML::main_thread_event_loop ().push_onto_backup_incumbent_realm_stack (realm );
186186
187187 // 2. Let context be the topmost script-having execution context.
188188 auto * context = top_most_script_having_execution_context (vm);
@@ -209,9 +209,10 @@ URL::URL EnvironmentSettingsObject::parse_url(StringView url)
209209}
210210
211211// https://html.spec.whatwg.org/multipage/webappapis.html#clean-up-after-running-a-callback
212- void EnvironmentSettingsObject::clean_up_after_running_callback ()
212+ // https://whatpr.org/html/9893/b8ea975...df5706b/webappapis.html#clean-up-after-running-a-callback
213+ void clean_up_after_running_callback (JS::Realm const & realm)
213214{
214- auto & vm = global_object ().vm ();
215+ auto & vm = realm. global_object ().vm ();
215216
216217 // 1. Let context be the topmost script-having execution context.
217218 auto * context = top_most_script_having_execution_context (vm);
@@ -220,12 +221,12 @@ void EnvironmentSettingsObject::clean_up_after_running_callback()
220221 if (context)
221222 context->skip_when_determining_incumbent_counter --;
222223
223- // 3. Assert: the topmost entry of the backup incumbent settings object stack is settings .
224+ // 3. Assert: the topmost entry of the backup incumbent realm stack is realm .
224225 auto & event_loop = HTML::main_thread_event_loop ();
225- VERIFY (&event_loop.top_of_backup_incumbent_settings_object_stack () == this );
226+ VERIFY (&event_loop.top_of_backup_incumbent_realm_stack () == &realm );
226227
227- // 4. Remove settings from the backup incumbent settings object stack.
228- event_loop.pop_backup_incumbent_settings_object_stack ({} );
228+ // 4. Remove realm from the backup incumbent realm stack.
229+ event_loop.pop_backup_incumbent_realm_stack ( );
229230}
230231
231232// https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-script
@@ -285,8 +286,9 @@ void EnvironmentSettingsObject::disallow_further_import_maps()
285286 verify_cast<Window>(global).set_import_maps_allowed (false );
286287}
287288
288- // https://html.spec.whatwg.org/multipage/webappapis.html#incumbent-settings-object
289- EnvironmentSettingsObject& incumbent_settings_object ()
289+ // https://html.spec.whatwg.org/multipage/webappapis.html#concept-incumbent-realm
290+ // https://whatpr.org/html/9893/b8ea975...df5706b/webappapis.html#concept-incumbent-realm
291+ JS::Realm& incumbent_realm ()
290292{
291293 auto & event_loop = HTML::main_thread_event_loop ();
292294 auto & vm = event_loop.vm ();
@@ -297,22 +299,24 @@ EnvironmentSettingsObject& incumbent_settings_object()
297299 // 2. If context is null, or if context's skip-when-determining-incumbent counter is greater than zero, then:
298300 if (!context || context->skip_when_determining_incumbent_counter > 0 ) {
299301 // 1. Assert: the backup incumbent settings object stack is not empty.
300- // NOTE: If this assertion fails, it's because the incumbent settings object was used with no involvement of JavaScript.
301- VERIFY (!event_loop.is_backup_incumbent_settings_object_stack_empty ());
302+ // 1. Assert: the backup incumbent realm stack is not empty.
303+ // NOTE: If this assertion fails, it's because the incumbent realm was used with no involvement of JavaScript.
304+ VERIFY (!event_loop.is_backup_incumbent_realm_stack_empty ());
302305
303- // 2. Return the topmost entry of the backup incumbent settings object stack.
304- return event_loop.top_of_backup_incumbent_settings_object_stack ();
306+ // 2. Return the topmost entry of the backup incumbent realm stack.
307+ return event_loop.top_of_backup_incumbent_realm_stack ();
305308 }
306309
307- // 3. Return context's Realm component's settings object .
308- return Bindings::host_defined_environment_settings_object ( *context->realm ) ;
310+ // 3. Return context's Realm component.
311+ return *context->realm ;
309312}
310313
311- // https://html.spec.whatwg.org/multipage/webappapis.html#concept-incumbent-realm
312- JS::Realm& incumbent_realm ()
314+ // https://html.spec.whatwg.org/multipage/webappapis.html#incumbent-settings-object
315+ // https://whatpr.org/html/9893/b8ea975...df5706b/webappapis.html#incumbent-settings-object
316+ EnvironmentSettingsObject& incumbent_settings_object ()
313317{
314- // Then, the incumbent Realm is the Realm of the incumbent settings object.
315- return incumbent_settings_object (). realm ( );
318+ // FIXME: Then, the incumbent settings object is the incumbent realm's principal realm settings object.
319+ return Bindings::host_defined_environment_settings_object ( incumbent_realm () );
316320}
317321
318322// https://html.spec.whatwg.org/multipage/webappapis.html#concept-incumbent-global
0 commit comments