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:
Shannon Booth 2024-11-14 05:50:17 +13:00 committed by Tim Flynn
commit 9b79a686eb
Notes: github-actions[bot] 2024-11-13 21:52:48 +00:00
326 changed files with 697 additions and 714 deletions

View file

@ -699,7 +699,7 @@ WebIDL::ExceptionOr<void> Element::attach_a_shadow_root(Bindings::ShadowRootMode
}
// 5. Let shadow be a new shadow root whose node document is elements node document, host is this, and mode is mode.
auto shadow = heap().allocate<ShadowRoot>(realm(), document(), *this, mode);
auto shadow = realm().create<ShadowRoot>(document(), *this, mode);
// 6. Set shadows delegates focus to delegatesFocus".
shadow->set_delegates_focus(delegates_focus);
@ -1547,7 +1547,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DOM::DocumentFragment>> Element::parse_frag
auto new_children = algorithm(*this, markup, HTML::HTMLParser::AllowDeclarativeShadowRoots::No);
// 4. Let fragment be a new DocumentFragment whose node document is context's node document.
auto fragment = realm().heap().allocate<DOM::DocumentFragment>(realm(), document());
auto fragment = realm().create<DOM::DocumentFragment>(document());
// 5. Append each Node in new children to fragment (in tree order).
for (auto& child : new_children) {
@ -1721,7 +1721,7 @@ WebIDL::ExceptionOr<JS::GCPtr<Element>> Element::insert_adjacent_element(String
WebIDL::ExceptionOr<void> Element::insert_adjacent_text(String const& where, String const& data)
{
// 1. Let text be a new Text node whose data is data and node document is thiss node document.
auto text = heap().allocate<DOM::Text>(realm(), document(), data);
auto text = realm().create<DOM::Text>(document(), data);
// 2. Run insert adjacent, given this, where, and text.
// Spec Note: This method returns nothing because it existed before we had a chance to design it.