mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-12 13:21:57 +00:00
LibJS+LibWeb: Use realm.create<T> instead of heap.allocate<T>
The main motivation behind this is to remove JS specifics of the Realm from the implementation of the Heap. As a side effect of this change, this is a bit nicer to read than the previous approach, and in my opinion, also makes it a little more clear that this method is specific to a JavaScript Realm.
This commit is contained in:
parent
2a5dbedad4
commit
9b79a686eb
Notes:
github-actions[bot]
2024-11-13 21:52:48 +00:00
Author: https://github.com/shannonbooth
Commit: 9b79a686eb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2322
Reviewed-by: https://github.com/gmta
326 changed files with 697 additions and 714 deletions
|
@ -91,12 +91,11 @@ void HTMLInputElement::visit_edges(Cell::Visitor& visitor)
|
|||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-validity
|
||||
JS::NonnullGCPtr<ValidityState const> HTMLInputElement::validity() const
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& realm = this->realm();
|
||||
|
||||
dbgln("FIXME: Implement validity attribute getter");
|
||||
|
||||
return vm.heap().allocate<ValidityState>(realm, realm);
|
||||
return realm.create<ValidityState>(realm);
|
||||
}
|
||||
|
||||
JS::GCPtr<Layout::Node> HTMLInputElement::create_layout_node(CSS::StyleProperties style)
|
||||
|
@ -815,18 +814,18 @@ void HTMLInputElement::update_shadow_tree()
|
|||
|
||||
void HTMLInputElement::create_button_input_shadow_tree()
|
||||
{
|
||||
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
auto shadow_root = realm().create<DOM::ShadowRoot>(document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
set_shadow_root(shadow_root);
|
||||
auto text_container = MUST(DOM::create_element(document(), HTML::TagNames::span, Namespace::HTML));
|
||||
MUST(text_container->set_attribute(HTML::AttributeNames::style, "display: inline-block; pointer-events: none;"_string));
|
||||
m_text_node = heap().allocate<DOM::Text>(realm(), document(), value());
|
||||
m_text_node = realm().create<DOM::Text>(document(), value());
|
||||
MUST(text_container->append_child(*m_text_node));
|
||||
MUST(shadow_root->append_child(*text_container));
|
||||
}
|
||||
|
||||
void HTMLInputElement::create_text_input_shadow_tree()
|
||||
{
|
||||
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
auto shadow_root = realm().create<DOM::ShadowRoot>(document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
set_shadow_root(shadow_root);
|
||||
|
||||
auto initial_value = m_value;
|
||||
|
@ -853,7 +852,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
|||
)~~~"_string));
|
||||
MUST(element->append_child(*m_placeholder_element));
|
||||
|
||||
m_placeholder_text_node = heap().allocate<DOM::Text>(realm(), document(), String {});
|
||||
m_placeholder_text_node = realm().create<DOM::Text>(document(), String {});
|
||||
m_placeholder_text_node->set_data(placeholder());
|
||||
MUST(m_placeholder_element->append_child(*m_placeholder_text_node));
|
||||
|
||||
|
@ -868,7 +867,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
|||
)~~~"_string));
|
||||
MUST(element->append_child(*m_inner_text_element));
|
||||
|
||||
m_text_node = heap().allocate<DOM::Text>(realm(), document(), move(initial_value));
|
||||
m_text_node = realm().create<DOM::Text>(document(), move(initial_value));
|
||||
if (type_state() == TypeAttributeState::FileUpload) {
|
||||
// NOTE: file upload state is mutable, but we don't allow the text node to be modifed
|
||||
m_text_node->set_always_editable(false);
|
||||
|
@ -942,7 +941,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
|
|||
|
||||
void HTMLInputElement::create_color_input_shadow_tree()
|
||||
{
|
||||
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
auto shadow_root = realm().create<DOM::ShadowRoot>(document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
|
||||
auto color = value_sanitization_algorithm(m_value);
|
||||
|
||||
|
@ -981,7 +980,7 @@ void HTMLInputElement::create_file_input_shadow_tree()
|
|||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm, document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
auto shadow_root = realm.create<DOM::ShadowRoot>(document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
|
||||
m_file_button = DOM::create_element(document(), HTML::TagNames::button, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
m_file_label = DOM::create_element(document(), HTML::TagNames::label, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
|
@ -1026,7 +1025,7 @@ void HTMLInputElement::update_file_input_shadow_tree()
|
|||
|
||||
void HTMLInputElement::create_range_input_shadow_tree()
|
||||
{
|
||||
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
auto shadow_root = realm().create<DOM::ShadowRoot>(document(), *this, Bindings::ShadowRootMode::Closed);
|
||||
set_shadow_root(shadow_root);
|
||||
|
||||
m_slider_runnable_track = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue