mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibWeb: Make CallbackType take a realm instead of settings object
In line with the ShadowRealm proposal changes in the WebIDL spec: webidl#1437 and supporting changes in HTML spec. This is required for ShadowRealms as they have no relevant settings object on the shadow realm, so fixes a crash in the QueueingStrategy test in this commit.
This commit is contained in:
parent
d527c5df5d
commit
d6bcd3fb0b
Notes:
github-actions[bot]
2024-11-21 01:10:31 +00:00
Author: https://github.com/shannonbooth
Commit: d6bcd3fb0b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2416
Reviewed-by: https://github.com/ADKaster ✅
15 changed files with 56 additions and 36 deletions
|
@ -44,6 +44,7 @@ void CustomElementRegistry::visit_edges(Visitor& visitor)
|
|||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#es-callback-function
|
||||
// https://github.com/whatwg/html/pull/9893
|
||||
static JS::ThrowCompletionOr<GC::Ref<WebIDL::CallbackType>> convert_value_to_callback_function(JS::VM& vm, JS::Value value)
|
||||
{
|
||||
// FIXME: De-duplicate this from the IDL generator.
|
||||
|
@ -51,8 +52,8 @@ static JS::ThrowCompletionOr<GC::Ref<WebIDL::CallbackType>> convert_value_to_cal
|
|||
if (!value.is_function())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, value.to_string_without_side_effects());
|
||||
|
||||
// 2. Return the IDL callback function type value that represents a reference to the same object that V represents, with the incumbent settings object as the callback context.
|
||||
return vm.heap().allocate<WebIDL::CallbackType>(value.as_object(), HTML::incumbent_settings_object());
|
||||
// 2. Return the IDL callback function type value that represents a reference to the same object that V represents, with the incumbent realm as the callback context.
|
||||
return vm.heap().allocate<WebIDL::CallbackType>(value.as_object(), HTML::incumbent_realm());
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#es-sequence
|
||||
|
|
|
@ -215,7 +215,7 @@ WebIDL::ExceptionOr<void> HTMLDialogElement::show_modal()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto cancel_callback = realm().heap().allocate<WebIDL::CallbackType>(*cancel_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto cancel_callback = realm().heap().allocate<WebIDL::CallbackType>(*cancel_callback_function, realm());
|
||||
m_close_watcher->add_event_listener_without_options(HTML::EventNames::cancel, DOM::IDLEventListener::create(realm(), cancel_callback));
|
||||
// - closeAction being to close the dialog given this and null.
|
||||
auto close_callback_function = JS::NativeFunction::create(
|
||||
|
@ -225,7 +225,7 @@ WebIDL::ExceptionOr<void> HTMLDialogElement::show_modal()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto close_callback = realm().heap().allocate<WebIDL::CallbackType>(*close_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto close_callback = realm().heap().allocate<WebIDL::CallbackType>(*close_callback_function, realm());
|
||||
m_close_watcher->add_event_listener_without_options(HTML::EventNames::close, DOM::IDLEventListener::create(realm(), close_callback));
|
||||
|
||||
// FIXME: 16. Set this's previously focused element to the focused element.
|
||||
|
|
|
@ -899,7 +899,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto mouseup_callback = realm().heap().allocate<WebIDL::CallbackType>(*mouseup_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto mouseup_callback = realm().heap().allocate<WebIDL::CallbackType>(*mouseup_callback_function, realm());
|
||||
DOM::AddEventListenerOptions mouseup_listener_options;
|
||||
mouseup_listener_options.once = true;
|
||||
|
||||
|
@ -912,7 +912,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto step_up_callback = realm().heap().allocate<WebIDL::CallbackType>(*up_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto step_up_callback = realm().heap().allocate<WebIDL::CallbackType>(*up_callback_function, realm());
|
||||
up_button->add_event_listener_without_options(UIEvents::EventNames::mousedown, DOM::IDLEventListener::create(realm(), step_up_callback));
|
||||
up_button->add_event_listener_without_options(UIEvents::EventNames::mouseup, DOM::IDLEventListener::create(realm(), mouseup_callback));
|
||||
|
||||
|
@ -934,7 +934,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto step_down_callback = realm().heap().allocate<WebIDL::CallbackType>(*down_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto step_down_callback = realm().heap().allocate<WebIDL::CallbackType>(*down_callback_function, realm());
|
||||
down_button->add_event_listener_without_options(UIEvents::EventNames::mousedown, DOM::IDLEventListener::create(realm(), step_down_callback));
|
||||
down_button->add_event_listener_without_options(UIEvents::EventNames::mouseup, DOM::IDLEventListener::create(realm(), mouseup_callback));
|
||||
}
|
||||
|
@ -993,7 +993,7 @@ void HTMLInputElement::create_file_input_shadow_tree()
|
|||
};
|
||||
|
||||
auto on_button_click_function = JS::NativeFunction::create(realm, move(on_button_click), 0, "", &realm);
|
||||
auto on_button_click_callback = realm.heap().allocate<WebIDL::CallbackType>(on_button_click_function, Bindings::principal_host_defined_environment_settings_object(realm));
|
||||
auto on_button_click_callback = realm.heap().allocate<WebIDL::CallbackType>(on_button_click_function, realm);
|
||||
m_file_button->add_event_listener_without_options(UIEvents::EventNames::click, DOM::IDLEventListener::create(realm, on_button_click_callback));
|
||||
|
||||
update_file_input_shadow_tree();
|
||||
|
@ -1065,7 +1065,7 @@ void HTMLInputElement::create_range_input_shadow_tree()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto keydown_callback = realm().heap().allocate<WebIDL::CallbackType>(*keydown_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto keydown_callback = realm().heap().allocate<WebIDL::CallbackType>(*keydown_callback_function, realm());
|
||||
add_event_listener_without_options(UIEvents::EventNames::keydown, DOM::IDLEventListener::create(realm(), keydown_callback));
|
||||
|
||||
auto wheel_callback_function = JS::NativeFunction::create(
|
||||
|
@ -1080,7 +1080,7 @@ void HTMLInputElement::create_range_input_shadow_tree()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto wheel_callback = realm().heap().allocate<WebIDL::CallbackType>(*wheel_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto wheel_callback = realm().heap().allocate<WebIDL::CallbackType>(*wheel_callback_function, realm());
|
||||
add_event_listener_without_options(UIEvents::EventNames::wheel, DOM::IDLEventListener::create(realm(), wheel_callback));
|
||||
|
||||
auto update_slider_by_mouse = [this](JS::VM& vm) {
|
||||
|
@ -1103,7 +1103,7 @@ void HTMLInputElement::create_range_input_shadow_tree()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto mousemove_callback = realm().heap().allocate<WebIDL::CallbackType>(*mousemove_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto mousemove_callback = realm().heap().allocate<WebIDL::CallbackType>(*mousemove_callback_function, realm());
|
||||
auto mousemove_listener = DOM::IDLEventListener::create(realm(), mousemove_callback);
|
||||
auto& window = static_cast<HTML::Window&>(relevant_global_object(*this));
|
||||
window.add_event_listener_without_options(UIEvents::EventNames::mousemove, mousemove_listener);
|
||||
|
@ -1115,7 +1115,7 @@ void HTMLInputElement::create_range_input_shadow_tree()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto mouseup_callback = realm().heap().allocate<WebIDL::CallbackType>(*mouseup_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto mouseup_callback = realm().heap().allocate<WebIDL::CallbackType>(*mouseup_callback_function, realm());
|
||||
DOM::AddEventListenerOptions mouseup_listener_options;
|
||||
mouseup_listener_options.once = true;
|
||||
window.add_event_listener(UIEvents::EventNames::mouseup, DOM::IDLEventListener::create(realm(), mouseup_callback), mouseup_listener_options);
|
||||
|
@ -1123,7 +1123,7 @@ void HTMLInputElement::create_range_input_shadow_tree()
|
|||
return JS::js_undefined();
|
||||
},
|
||||
0, "", &realm());
|
||||
auto mousedown_callback = realm().heap().allocate<WebIDL::CallbackType>(*mousedown_callback_function, Bindings::principal_host_defined_environment_settings_object(realm()));
|
||||
auto mousedown_callback = realm().heap().allocate<WebIDL::CallbackType>(*mousedown_callback_function, realm());
|
||||
add_event_listener_without_options(UIEvents::EventNames::mousedown, DOM::IDLEventListener::create(realm(), mousedown_callback));
|
||||
}
|
||||
|
||||
|
|
|
@ -124,7 +124,8 @@ GC::Ref<WebIDL::CallbackType> UniversalGlobalScopeMixin::count_queuing_strategy_
|
|||
auto function = JS::NativeFunction::create(realm, move(steps), 0, "size", &realm);
|
||||
|
||||
// 3. Set globalObject’s count queuing strategy size function to a Function that represents a reference to F, with callback context equal to globalObject’s relevant settings object.
|
||||
m_count_queuing_strategy_size_function = realm.create<WebIDL::CallbackType>(*function, relevant_settings_object(this_impl()));
|
||||
// FIXME: Update spec comment to pass globalObject's relevant realm once Streams spec is updated for ShadowRealm spec
|
||||
m_count_queuing_strategy_size_function = realm.create<WebIDL::CallbackType>(*function, realm);
|
||||
}
|
||||
|
||||
return GC::Ref { *m_count_queuing_strategy_size_function };
|
||||
|
@ -148,7 +149,8 @@ GC::Ref<WebIDL::CallbackType> UniversalGlobalScopeMixin::byte_length_queuing_str
|
|||
auto function = JS::NativeFunction::create(realm, move(steps), 1, "size", &realm);
|
||||
|
||||
// 3. Set globalObject’s byte length queuing strategy size function to a Function that represents a reference to F, with callback context equal to globalObject’s relevant settings object.
|
||||
m_byte_length_queuing_strategy_size_function = realm.create<WebIDL::CallbackType>(*function, relevant_settings_object(this_impl()));
|
||||
// FIXME: Update spec comment to pass globalObject's relevant realm once Streams spec is updated for ShadowRealm spec
|
||||
m_byte_length_queuing_strategy_size_function = realm.create<WebIDL::CallbackType>(*function, realm);
|
||||
}
|
||||
|
||||
return GC::Ref { *m_byte_length_queuing_strategy_size_function };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue