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

@ -16,7 +16,7 @@ JS_DEFINE_ALLOCATOR(AbortController);
WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortController>> AbortController::construct_impl(JS::Realm& realm)
{
auto signal = TRY(AbortSignal::construct_impl(realm));
return realm.heap().allocate<AbortController>(realm, realm, move(signal));
return realm.create<AbortController>(realm, move(signal));
}
// https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller

View file

@ -20,7 +20,7 @@ JS_DEFINE_ALLOCATOR(AbortSignal);
WebIDL::ExceptionOr<JS::NonnullGCPtr<AbortSignal>> AbortSignal::construct_impl(JS::Realm& realm)
{
return realm.heap().allocate<AbortSignal>(realm, realm);
return realm.create<AbortSignal>(realm);
}
AbortSignal::AbortSignal(JS::Realm& realm)

View file

@ -16,7 +16,7 @@ JS_DEFINE_ALLOCATOR(AccessibilityTreeNode);
JS::NonnullGCPtr<AccessibilityTreeNode> AccessibilityTreeNode::create(Document* document, DOM::Node const* value)
{
return document->heap().allocate<AccessibilityTreeNode>(document->realm(), value);
return document->realm().create<AccessibilityTreeNode>(value);
}
AccessibilityTreeNode::AccessibilityTreeNode(JS::GCPtr<DOM::Node const> value)

View file

@ -20,17 +20,17 @@ JS_DEFINE_ALLOCATOR(Attr);
JS::NonnullGCPtr<Attr> Attr::create(Document& document, FlyString local_name, String value, Element* owner_element)
{
return document.heap().allocate<Attr>(document.realm(), document, QualifiedName(move(local_name), Optional<FlyString> {}, Optional<FlyString> {}), move(value), owner_element);
return document.realm().create<Attr>(document, QualifiedName(move(local_name), Optional<FlyString> {}, Optional<FlyString> {}), move(value), owner_element);
}
JS::NonnullGCPtr<Attr> Attr::create(Document& document, QualifiedName qualified_name, String value, Element* owner_element)
{
return document.heap().allocate<Attr>(document.realm(), document, move(qualified_name), move(value), owner_element);
return document.realm().create<Attr>(document, move(qualified_name), move(value), owner_element);
}
JS::NonnullGCPtr<Attr> Attr::clone(Document& document)
{
return *heap().allocate<Attr>(realm(), document, m_qualified_name, m_value, nullptr);
return realm().create<Attr>(document, m_qualified_name, m_value, nullptr);
}
Attr::Attr(Document& document, QualifiedName qualified_name, String value, Element* owner_element)

View file

@ -22,7 +22,7 @@ Comment::Comment(Document& document, String const& data)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Comment>> Comment::construct_impl(JS::Realm& realm, String const& data)
{
auto& window = verify_cast<HTML::Window>(realm.global_object());
return realm.heap().allocate<Comment>(realm, window.associated_document(), data);
return realm.create<Comment>(window.associated_document(), data);
}
void Comment::initialize(JS::Realm& realm)

View file

@ -16,7 +16,7 @@ JS_DEFINE_ALLOCATOR(CustomEvent);
JS::NonnullGCPtr<CustomEvent> CustomEvent::create(JS::Realm& realm, FlyString const& event_name, CustomEventInit const& event_init)
{
return realm.heap().allocate<CustomEvent>(realm, realm, event_name, event_init);
return realm.create<CustomEvent>(realm, event_name, event_init);
}
WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> CustomEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, CustomEventInit const& event_init)

View file

@ -24,7 +24,7 @@ JS_DEFINE_ALLOCATOR(DOMImplementation);
JS::NonnullGCPtr<DOMImplementation> DOMImplementation::create(Document& document)
{
auto& realm = document.realm();
return realm.heap().allocate<DOMImplementation>(realm, document);
return realm.create<DOMImplementation>(document);
}
DOMImplementation::DOMImplementation(Document& document)
@ -102,7 +102,7 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(Optional<Stri
html_document->set_ready_for_post_load_tasks(true);
// 3. Append a new doctype, with "html" as its name and with its node document set to doc, to doc.
auto doctype = heap().allocate<DocumentType>(realm(), html_document);
auto doctype = realm().create<DocumentType>(html_document);
doctype->set_name("html"_string);
MUST(html_document->append_child(*doctype));
@ -121,7 +121,7 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(Optional<Stri
MUST(head_element->append_child(title_element));
// 2. Append a new Text node, with its data set to title (which could be the empty string) and its node document set to doc, to the title element created earlier.
auto text_node = heap().allocate<Text>(realm(), html_document, title.value());
auto text_node = realm().create<Text>(html_document, title.value());
MUST(title_element->append_child(*text_node));
}

View file

@ -59,7 +59,7 @@ JS_DEFINE_ALLOCATOR(DOMTokenList);
JS::NonnullGCPtr<DOMTokenList> DOMTokenList::create(Element& associated_element, FlyString associated_attribute)
{
auto& realm = associated_element.realm();
return realm.heap().allocate<DOMTokenList>(realm, associated_element, move(associated_attribute));
return realm.create<DOMTokenList>(associated_element, move(associated_attribute));
}
// https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A2

View file

@ -374,12 +374,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> Document::construct_impl(JS::Rea
JS::NonnullGCPtr<Document> Document::create(JS::Realm& realm, URL::URL const& url)
{
return realm.heap().allocate<Document>(realm, realm, url);
return realm.create<Document>(realm, url);
}
JS::NonnullGCPtr<Document> Document::create_for_fragment_parsing(JS::Realm& realm)
{
return realm.heap().allocate<Document>(realm, realm, "about:blank"sv, TemporaryDocumentForFragmentParsing::Yes);
return realm.create<Document>(realm, "about:blank"sv, TemporaryDocumentForFragmentParsing::Yes);
}
Document::Document(JS::Realm& realm, const URL::URL& url, TemporaryDocumentForFragmentParsing temporary_document_for_fragment_parsing)
@ -429,9 +429,9 @@ void Document::initialize(JS::Realm& realm)
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(Document);
m_selection = heap().allocate<Selection::Selection>(realm, realm, *this);
m_selection = realm.create<Selection::Selection>(realm, *this);
m_list_of_available_images = heap().allocate<HTML::ListOfAvailableImages>(realm);
m_list_of_available_images = realm.create<HTML::ListOfAvailableImages>();
page().client().page_did_create_new_document(*this);
}
@ -1709,12 +1709,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Optio
JS::NonnullGCPtr<DocumentFragment> Document::create_document_fragment()
{
return heap().allocate<DocumentFragment>(realm(), *this);
return realm().create<DocumentFragment>(*this);
}
JS::NonnullGCPtr<Text> Document::create_text_node(String const& data)
{
return heap().allocate<Text>(realm(), *this, data);
return realm().create<Text>(*this, data);
}
// https://dom.spec.whatwg.org/#dom-document-createcdatasection
@ -1729,12 +1729,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CDATASection>> Document::create_cdata_secti
return WebIDL::InvalidCharacterError::create(realm(), "String may not contain ']]>'"_string);
// 3. Return a new CDATASection node with its data set to data and node document set to this.
return heap().allocate<CDATASection>(realm(), *this, data);
return realm().create<CDATASection>(*this, data);
}
JS::NonnullGCPtr<Comment> Document::create_comment(String const& data)
{
return heap().allocate<Comment>(realm(), *this, data);
return realm().create<Comment>(*this, data);
}
// https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
@ -1749,7 +1749,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> Document::create_pr
return WebIDL::InvalidCharacterError::create(realm(), "String may not contain '?>'"_string);
// 3. Return a new ProcessingInstruction node, with target set to target, data set to data, and node document set to this.
return heap().allocate<ProcessingInstruction>(realm(), *this, data, target);
return realm().create<ProcessingInstruction>(*this, data, target);
}
JS::NonnullGCPtr<Range> Document::create_range()
@ -3986,7 +3986,7 @@ void Document::queue_an_intersection_observer_entry(IntersectionObserver::Inters
auto& realm = this->realm();
// 1. Construct an IntersectionObserverEntry, passing in time, rootBounds, boundingClientRect, intersectionRect, isIntersecting, and target.
auto entry = realm.heap().allocate<IntersectionObserver::IntersectionObserverEntry>(realm, realm, time, root_bounds, bounding_client_rect, intersection_rect, is_intersecting, intersection_ratio, target);
auto entry = realm.create<IntersectionObserver::IntersectionObserverEntry>(realm, time, root_bounds, bounding_client_rect, intersection_rect, is_intersecting, intersection_ratio, target);
// 2. Append it to observers internal [[QueuedEntries]] slot.
observer.queue_entry({}, entry);

View file

@ -38,7 +38,7 @@ void DocumentFragment::set_host(Web::DOM::Element* element)
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> DocumentFragment::construct_impl(JS::Realm& realm)
{
auto& window = verify_cast<HTML::Window>(realm.global_object());
return realm.heap().allocate<DocumentFragment>(realm, window.associated_document());
return realm.create<DocumentFragment>(window.associated_document());
}
}

View file

@ -31,7 +31,7 @@ static void convert_to_xml_error_document(DOM::Document& document, String error_
auto html_element = MUST(DOM::create_element(document, HTML::TagNames::html, Namespace::HTML));
auto body_element = MUST(DOM::create_element(document, HTML::TagNames::body, Namespace::HTML));
MUST(html_element->append_child(body_element));
MUST(body_element->append_child(document.heap().allocate<DOM::Text>(document.realm(), document, error_string)));
MUST(body_element->append_child(document.realm().create<DOM::Text>(document, error_string)));
document.remove_all_children();
MUST(document.append_child(html_element));
}
@ -249,7 +249,7 @@ static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOM::Document>> load_text_document(H
auto title = MUST(String::from_byte_string(LexicalPath::basename(url.to_byte_string())));
auto title_element = MUST(DOM::create_element(document, HTML::TagNames::title, Namespace::HTML));
MUST(document->head()->append_child(title_element));
auto title_text = document->heap().allocate<DOM::Text>(document->realm(), document, title);
auto title_text = document->realm().create<DOM::Text>(document, title);
MUST(title_element->append_child(*title_text));
});
@ -287,7 +287,7 @@ static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOM::Document>> load_media_document(
auto title_element = TRY(DOM::create_element(document, HTML::TagNames::title, Namespace::HTML));
TRY(document->head()->append_child(title_element));
auto title_text = document->heap().template allocate<DOM::Text>(document->realm(), document, title);
auto title_text = document->realm().template create<DOM::Text>(document, title);
TRY(title_element->append_child(*title_text));
return {};
};

View file

@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(DocumentType);
JS::NonnullGCPtr<DocumentType> DocumentType::create(Document& document)
{
return document.heap().allocate<DocumentType>(document.realm(), document);
return document.realm().create<DocumentType>(document);
}
DocumentType::DocumentType(Document& document)

View file

@ -16,7 +16,7 @@ JS_DEFINE_ALLOCATOR(EditingHostManager);
JS::NonnullGCPtr<EditingHostManager> EditingHostManager::create(JS::Realm& realm, JS::NonnullGCPtr<Document> document)
{
return realm.heap().allocate<EditingHostManager>(realm, document);
return realm.create<EditingHostManager>(document);
}
EditingHostManager::EditingHostManager(JS::NonnullGCPtr<Document> document)
@ -47,7 +47,7 @@ void EditingHostManager::handle_insert(String const& data)
if (!is<DOM::Text>(*node)) {
auto& realm = node->realm();
auto text = realm.heap().allocate<DOM::Text>(realm, node->document(), data);
auto text = realm.create<DOM::Text>(node->document(), data);
MUST(node->append_child(*text));
MUST(selection->collapse(*text, 1));
return;

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.

View file

@ -281,153 +281,153 @@ static JS::NonnullGCPtr<Element> create_html_element(JS::Realm& realm, Document&
FlyString tag_name = qualified_name.local_name();
if (tag_name == HTML::TagNames::a)
return realm.heap().allocate<HTML::HTMLAnchorElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLAnchorElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::area)
return realm.heap().allocate<HTML::HTMLAreaElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLAreaElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::audio)
return realm.heap().allocate<HTML::HTMLAudioElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLAudioElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::base)
return realm.heap().allocate<HTML::HTMLBaseElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLBaseElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::body)
return realm.heap().allocate<HTML::HTMLBodyElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLBodyElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::br)
return realm.heap().allocate<HTML::HTMLBRElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLBRElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::button)
return realm.heap().allocate<HTML::HTMLButtonElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLButtonElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::canvas)
return realm.heap().allocate<HTML::HTMLCanvasElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLCanvasElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::data)
return realm.heap().allocate<HTML::HTMLDataElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLDataElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::datalist)
return realm.heap().allocate<HTML::HTMLDataListElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLDataListElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::details)
return realm.heap().allocate<HTML::HTMLDetailsElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLDetailsElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::dialog)
return realm.heap().allocate<HTML::HTMLDialogElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLDialogElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::dir)
return realm.heap().allocate<HTML::HTMLDirectoryElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLDirectoryElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::div)
return realm.heap().allocate<HTML::HTMLDivElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLDivElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::dl)
return realm.heap().allocate<HTML::HTMLDListElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLDListElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::embed)
return realm.heap().allocate<HTML::HTMLEmbedElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLEmbedElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::fieldset)
return realm.heap().allocate<HTML::HTMLFieldSetElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLFieldSetElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::font)
return realm.heap().allocate<HTML::HTMLFontElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLFontElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::form)
return realm.heap().allocate<HTML::HTMLFormElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLFormElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::frame)
return realm.heap().allocate<HTML::HTMLFrameElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLFrameElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::frameset)
return realm.heap().allocate<HTML::HTMLFrameSetElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLFrameSetElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::head)
return realm.heap().allocate<HTML::HTMLHeadElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLHeadElement>(document, move(qualified_name));
if (tag_name.is_one_of(HTML::TagNames::h1, HTML::TagNames::h2, HTML::TagNames::h3, HTML::TagNames::h4, HTML::TagNames::h5, HTML::TagNames::h6))
return realm.heap().allocate<HTML::HTMLHeadingElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLHeadingElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::hr)
return realm.heap().allocate<HTML::HTMLHRElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLHRElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::html)
return realm.heap().allocate<HTML::HTMLHtmlElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLHtmlElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::iframe)
return realm.heap().allocate<HTML::HTMLIFrameElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLIFrameElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::img)
return realm.heap().allocate<HTML::HTMLImageElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLImageElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::input)
return realm.heap().allocate<HTML::HTMLInputElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLInputElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::label)
return realm.heap().allocate<HTML::HTMLLabelElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLLabelElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::legend)
return realm.heap().allocate<HTML::HTMLLegendElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLLegendElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::li)
return realm.heap().allocate<HTML::HTMLLIElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLLIElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::link)
return realm.heap().allocate<HTML::HTMLLinkElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLLinkElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::map)
return realm.heap().allocate<HTML::HTMLMapElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLMapElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::marquee)
return realm.heap().allocate<HTML::HTMLMarqueeElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLMarqueeElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::menu)
return realm.heap().allocate<HTML::HTMLMenuElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLMenuElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::meta)
return realm.heap().allocate<HTML::HTMLMetaElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLMetaElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::meter)
return realm.heap().allocate<HTML::HTMLMeterElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLMeterElement>(document, move(qualified_name));
if (tag_name.is_one_of(HTML::TagNames::ins, HTML::TagNames::del))
return realm.heap().allocate<HTML::HTMLModElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLModElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::object)
return realm.heap().allocate<HTML::HTMLObjectElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLObjectElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::ol)
return realm.heap().allocate<HTML::HTMLOListElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLOListElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::optgroup)
return realm.heap().allocate<HTML::HTMLOptGroupElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLOptGroupElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::option)
return realm.heap().allocate<HTML::HTMLOptionElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLOptionElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::output)
return realm.heap().allocate<HTML::HTMLOutputElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLOutputElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::p)
return realm.heap().allocate<HTML::HTMLParagraphElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLParagraphElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::param)
return realm.heap().allocate<HTML::HTMLParamElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLParamElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::picture)
return realm.heap().allocate<HTML::HTMLPictureElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLPictureElement>(document, move(qualified_name));
// NOTE: The obsolete elements "listing" and "xmp" are explicitly mapped to HTMLPreElement in the specification.
if (tag_name.is_one_of(HTML::TagNames::pre, HTML::TagNames::listing, HTML::TagNames::xmp))
return realm.heap().allocate<HTML::HTMLPreElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLPreElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::progress)
return realm.heap().allocate<HTML::HTMLProgressElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLProgressElement>(document, move(qualified_name));
if (tag_name.is_one_of(HTML::TagNames::blockquote, HTML::TagNames::q))
return realm.heap().allocate<HTML::HTMLQuoteElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLQuoteElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::script)
return realm.heap().allocate<HTML::HTMLScriptElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLScriptElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::select)
return realm.heap().allocate<HTML::HTMLSelectElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLSelectElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::slot)
return realm.heap().allocate<HTML::HTMLSlotElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLSlotElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::source)
return realm.heap().allocate<HTML::HTMLSourceElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLSourceElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::span)
return realm.heap().allocate<HTML::HTMLSpanElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLSpanElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::style)
return realm.heap().allocate<HTML::HTMLStyleElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLStyleElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::summary)
return realm.heap().allocate<HTML::HTMLSummaryElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLSummaryElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::caption)
return realm.heap().allocate<HTML::HTMLTableCaptionElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTableCaptionElement>(document, move(qualified_name));
if (tag_name.is_one_of(Web::HTML::TagNames::td, Web::HTML::TagNames::th))
return realm.heap().allocate<HTML::HTMLTableCellElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTableCellElement>(document, move(qualified_name));
if (tag_name.is_one_of(HTML::TagNames::colgroup, HTML::TagNames::col))
return realm.heap().allocate<HTML::HTMLTableColElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTableColElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::table)
return realm.heap().allocate<HTML::HTMLTableElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTableElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::tr)
return realm.heap().allocate<HTML::HTMLTableRowElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTableRowElement>(document, move(qualified_name));
if (tag_name.is_one_of(HTML::TagNames::tbody, HTML::TagNames::thead, HTML::TagNames::tfoot))
return realm.heap().allocate<HTML::HTMLTableSectionElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTableSectionElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::template_)
return realm.heap().allocate<HTML::HTMLTemplateElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTemplateElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::textarea)
return realm.heap().allocate<HTML::HTMLTextAreaElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTextAreaElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::time)
return realm.heap().allocate<HTML::HTMLTimeElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTimeElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::title)
return realm.heap().allocate<HTML::HTMLTitleElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTitleElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::track)
return realm.heap().allocate<HTML::HTMLTrackElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLTrackElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::ul)
return realm.heap().allocate<HTML::HTMLUListElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLUListElement>(document, move(qualified_name));
if (tag_name == HTML::TagNames::video)
return realm.heap().allocate<HTML::HTMLVideoElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLVideoElement>(document, move(qualified_name));
if (tag_name.is_one_of(
HTML::TagNames::article, HTML::TagNames::section, HTML::TagNames::nav, HTML::TagNames::aside, HTML::TagNames::hgroup, HTML::TagNames::header, HTML::TagNames::footer, HTML::TagNames::address, HTML::TagNames::dt, HTML::TagNames::dd, HTML::TagNames::figure, HTML::TagNames::figcaption, HTML::TagNames::main, HTML::TagNames::em, HTML::TagNames::strong, HTML::TagNames::small, HTML::TagNames::s, HTML::TagNames::cite, HTML::TagNames::dfn, HTML::TagNames::abbr, HTML::TagNames::ruby, HTML::TagNames::rt, HTML::TagNames::rp, HTML::TagNames::code, HTML::TagNames::var, HTML::TagNames::samp, HTML::TagNames::kbd, HTML::TagNames::sub, HTML::TagNames::sup, HTML::TagNames::i, HTML::TagNames::b, HTML::TagNames::u, HTML::TagNames::mark, HTML::TagNames::bdi, HTML::TagNames::bdo, HTML::TagNames::wbr, HTML::TagNames::noscript,
// Obsolete
HTML::TagNames::acronym, HTML::TagNames::basefont, HTML::TagNames::big, HTML::TagNames::center, HTML::TagNames::nobr, HTML::TagNames::noembed, HTML::TagNames::noframes, HTML::TagNames::plaintext, HTML::TagNames::rb, HTML::TagNames::rtc, HTML::TagNames::strike, HTML::TagNames::tt))
return realm.heap().allocate<HTML::HTMLElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLElement>(document, move(qualified_name));
if (HTML::is_valid_custom_element_name(qualified_name.local_name()))
return realm.heap().allocate<HTML::HTMLElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLElement>(document, move(qualified_name));
return realm.heap().allocate<HTML::HTMLUnknownElement>(realm, document, move(qualified_name));
return realm.create<HTML::HTMLUnknownElement>(document, move(qualified_name));
}
static JS::NonnullGCPtr<SVG::SVGElement> create_svg_element(JS::Realm& realm, Document& document, QualifiedName qualified_name)
@ -435,67 +435,67 @@ static JS::NonnullGCPtr<SVG::SVGElement> create_svg_element(JS::Realm& realm, Do
auto const& local_name = qualified_name.local_name();
if (local_name == SVG::TagNames::svg)
return realm.heap().allocate<SVG::SVGSVGElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGSVGElement>(document, move(qualified_name));
// FIXME: Support SVG's mixedCase tag names properly.
if (local_name.equals_ignoring_ascii_case(SVG::TagNames::clipPath))
return realm.heap().allocate<SVG::SVGClipPathElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGClipPathElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::circle)
return realm.heap().allocate<SVG::SVGCircleElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGCircleElement>(document, move(qualified_name));
if (local_name.equals_ignoring_ascii_case(SVG::TagNames::defs))
return realm.heap().allocate<SVG::SVGDefsElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGDefsElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::desc)
return realm.heap().allocate<SVG::SVGDescElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGDescElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::ellipse)
return realm.heap().allocate<SVG::SVGEllipseElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGEllipseElement>(document, move(qualified_name));
if (local_name.equals_ignoring_ascii_case(SVG::TagNames::foreignObject))
return realm.heap().allocate<SVG::SVGForeignObjectElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGForeignObjectElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::line)
return realm.heap().allocate<SVG::SVGLineElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGLineElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::linearGradient)
return realm.heap().allocate<SVG::SVGLinearGradientElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGLinearGradientElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::mask)
return realm.heap().allocate<SVG::SVGMaskElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGMaskElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::metadata)
return realm.heap().allocate<SVG::SVGMetadataElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGMetadataElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::path)
return realm.heap().allocate<SVG::SVGPathElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGPathElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::polygon)
return realm.heap().allocate<SVG::SVGPolygonElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGPolygonElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::polyline)
return realm.heap().allocate<SVG::SVGPolylineElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGPolylineElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::radialGradient)
return realm.heap().allocate<SVG::SVGRadialGradientElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGRadialGradientElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::rect)
return realm.heap().allocate<SVG::SVGRectElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGRectElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::g)
return realm.heap().allocate<SVG::SVGGElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGGElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::stop)
return realm.heap().allocate<SVG::SVGStopElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGStopElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::style)
return realm.heap().allocate<SVG::SVGStyleElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGStyleElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::symbol)
return realm.heap().allocate<SVG::SVGSymbolElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGSymbolElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::text)
return realm.heap().allocate<SVG::SVGTextElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGTextElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::textPath)
return realm.heap().allocate<SVG::SVGTextPathElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGTextPathElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::title)
return realm.heap().allocate<SVG::SVGTitleElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGTitleElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::tspan)
return realm.heap().allocate<SVG::SVGTSpanElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGTSpanElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::use)
return realm.heap().allocate<SVG::SVGUseElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGUseElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::script)
return realm.heap().allocate<SVG::SVGScriptElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGScriptElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::a)
return realm.heap().allocate<SVG::SVGAElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGAElement>(document, move(qualified_name));
if (local_name == SVG::TagNames::image)
return realm.heap().allocate<SVG::SVGImageElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGImageElement>(document, move(qualified_name));
// https://svgwg.org/svg2-draft/types.html#ElementsInTheSVGDOM
// Elements in the SVG namespace whose local name does not match an element defined in any
// specification supported by the software must nonetheless implement the SVGElement interface.
return realm.heap().allocate<SVG::SVGElement>(realm, document, move(qualified_name));
return realm.create<SVG::SVGElement>(document, move(qualified_name));
}
static JS::NonnullGCPtr<MathML::MathMLElement> create_mathml_element(JS::Realm& realm, Document& document, QualifiedName qualified_name)
@ -507,7 +507,7 @@ static JS::NonnullGCPtr<MathML::MathMLElement> create_mathml_element(JS::Realm&
// https://w3c.github.io/mathml-core/#mathml-elements-and-attributes
// The term MathML element refers to any element in the MathML namespace.
return realm.heap().allocate<MathML::MathMLElement>(realm, document, move(qualified_name));
return realm.create<MathML::MathMLElement>(document, move(qualified_name));
}
// https://dom.spec.whatwg.org/#concept-create-element
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document, FlyString local_name, Optional<FlyString> namespace_, Optional<FlyString> prefix, Optional<String> is_value, bool synchronous_custom_elements_flag)
@ -617,7 +617,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
// 2. Set result to a new element that implements the HTMLUnknownElement interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix,
// local name set to localName, custom element state set to "failed", custom element definition set to null, is value set to null, and node document set to document.
JS::NonnullGCPtr<Element> element = realm.heap().allocate<HTML::HTMLUnknownElement>(realm, document, QualifiedName { local_name, prefix, Namespace::HTML });
JS::NonnullGCPtr<Element> element = realm.create<HTML::HTMLUnknownElement>(document, QualifiedName { local_name, prefix, Namespace::HTML });
element->set_custom_element_state(CustomElementState::Failed);
return element;
}
@ -628,7 +628,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
// 2. Otherwise:
// 1. Set result to a new element that implements the HTMLElement interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix,
// local name set to localName, custom element state set to "undefined", custom element definition set to null, is value set to null, and node document set to document.
auto element = realm.heap().allocate<HTML::HTMLElement>(realm, document, QualifiedName { local_name, prefix, Namespace::HTML });
auto element = realm.create<HTML::HTMLElement>(document, QualifiedName { local_name, prefix, Namespace::HTML });
element->set_custom_element_state(CustomElementState::Undefined);
// 2. Enqueue a custom element upgrade reaction given result and definition.
@ -677,7 +677,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document
// https://dom.spec.whatwg.org/#concept-element-interface
// The element interface for any name and namespace is Element, unless stated otherwise.
dbgln("Potential FIXME: Creating unknown generic element '{}' in namespace '{}'", local_name, namespace_);
auto element = realm.heap().allocate<DOM::Element>(realm, document, move(qualified_name));
auto element = realm.create<DOM::Element>(document, move(qualified_name));
element->set_is_value(move(is_value));
element->set_custom_element_state(CustomElementState::Uncustomized);
return element;

View file

@ -21,7 +21,7 @@ JS_DEFINE_ALLOCATOR(Event);
// https://dom.spec.whatwg.org/#concept-event-create
JS::NonnullGCPtr<Event> Event::create(JS::Realm& realm, FlyString const& event_name, EventInit const& event_init)
{
auto event = realm.heap().allocate<Event>(realm, realm, event_name, event_init);
auto event = realm.create<Event>(realm, event_name, event_init);
// 4. Initialize events isTrusted attribute to true.
event->m_is_trusted = true;
return event;
@ -29,7 +29,7 @@ JS::NonnullGCPtr<Event> Event::create(JS::Realm& realm, FlyString const& event_n
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Event::construct_impl(JS::Realm& realm, FlyString const& event_name, EventInit const& event_init)
{
return realm.heap().allocate<Event>(realm, realm, event_name, event_init);
return realm.create<Event>(realm, event_name, event_init);
}
// https://dom.spec.whatwg.org/#inner-event-creation-steps

View file

@ -54,7 +54,7 @@ EventTarget::~EventTarget() = default;
WebIDL::ExceptionOr<JS::NonnullGCPtr<EventTarget>> EventTarget::construct_impl(JS::Realm& realm)
{
// The new EventTarget() constructor steps are to do nothing.
return realm.heap().allocate<EventTarget>(realm, realm);
return realm.create<EventTarget>(realm);
}
void EventTarget::initialize(JS::Realm& realm)

View file

@ -19,7 +19,7 @@ JS_DEFINE_ALLOCATOR(HTMLCollection);
JS::NonnullGCPtr<HTMLCollection> HTMLCollection::create(ParentNode& root, Scope scope, Function<bool(Element const&)> filter)
{
return root.heap().allocate<HTMLCollection>(root.realm(), root, scope, move(filter));
return root.realm().create<HTMLCollection>(root, scope, move(filter));
}
HTMLCollection::HTMLCollection(ParentNode& root, Scope scope, Function<bool(Element const&)> filter)

View file

@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(IDLEventListener);
JS::NonnullGCPtr<IDLEventListener> IDLEventListener::create(JS::Realm& realm, JS::NonnullGCPtr<WebIDL::CallbackType> callback)
{
return realm.heap().allocate<IDLEventListener>(realm, realm, move(callback));
return realm.create<IDLEventListener>(realm, move(callback));
}
IDLEventListener::IDLEventListener(JS::Realm& realm, JS::NonnullGCPtr<WebIDL::CallbackType> callback)

View file

@ -16,7 +16,7 @@ JS_DEFINE_ALLOCATOR(LiveNodeList);
JS::NonnullGCPtr<NodeList> LiveNodeList::create(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter)
{
return realm.heap().allocate<LiveNodeList>(realm, realm, root, scope, move(filter));
return realm.create<LiveNodeList>(realm, root, scope, move(filter));
}
LiveNodeList::LiveNodeList(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter)

View file

@ -17,7 +17,7 @@ JS_DEFINE_ALLOCATOR(TransientRegisteredObserver);
WebIDL::ExceptionOr<JS::NonnullGCPtr<MutationObserver>> MutationObserver::construct_impl(JS::Realm& realm, JS::GCPtr<WebIDL::CallbackType> callback)
{
return realm.heap().allocate<MutationObserver>(realm, realm, callback);
return realm.create<MutationObserver>(realm, callback);
}
// https://dom.spec.whatwg.org/#dom-mutationobserver-mutationobserver

View file

@ -17,7 +17,7 @@ JS_DEFINE_ALLOCATOR(MutationRecord);
JS::NonnullGCPtr<MutationRecord> MutationRecord::create(JS::Realm& realm, FlyString const& type, Node const& target, NodeList& added_nodes, NodeList& removed_nodes, Node* previous_sibling, Node* next_sibling, Optional<String> const& attribute_name, Optional<String> const& attribute_namespace, Optional<String> const& old_value)
{
return realm.heap().allocate<MutationRecord>(realm, realm, type, target, added_nodes, removed_nodes, previous_sibling, next_sibling, attribute_name, attribute_namespace, old_value);
return realm.create<MutationRecord>(realm, type, target, added_nodes, removed_nodes, previous_sibling, next_sibling, attribute_name, attribute_namespace, old_value);
}
MutationRecord::MutationRecord(JS::Realm& realm, FlyString const& type, Node const& target, NodeList& added_nodes, NodeList& removed_nodes, Node* previous_sibling, Node* next_sibling, Optional<String> const& attribute_name, Optional<String> const& attribute_namespace, Optional<String> const& old_value)

View file

@ -20,7 +20,7 @@ JS_DEFINE_ALLOCATOR(NamedNodeMap);
JS::NonnullGCPtr<NamedNodeMap> NamedNodeMap::create(Element& element)
{
auto& realm = element.realm();
return realm.heap().allocate<NamedNodeMap>(realm, element);
return realm.create<NamedNodeMap>(element);
}
NamedNodeMap::NamedNodeMap(Element& element)

View file

@ -1034,7 +1034,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::clone_node(Document* document,
} else if (is<DocumentType>(this)) {
// DocumentType
auto document_type = verify_cast<DocumentType>(this);
auto document_type_copy = heap().allocate<DocumentType>(realm(), *document);
auto document_type_copy = realm().create<DocumentType>(*document);
// Set copys name, public ID, and system ID to those of node.
document_type_copy->set_name(document_type->name());
@ -1053,26 +1053,26 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::clone_node(Document* document,
auto& text = static_cast<Text&>(*this);
// Set copys data to that of node.
auto text_copy = heap().allocate<Text>(realm(), *document, text.data());
auto text_copy = realm().create<Text>(*document, text.data());
copy = move(text_copy);
} else if (is<Comment>(this)) {
// Comment
auto comment = verify_cast<Comment>(this);
// Set copys data to that of node.
auto comment_copy = heap().allocate<Comment>(realm(), *document, comment->data());
auto comment_copy = realm().create<Comment>(*document, comment->data());
copy = move(comment_copy);
} else if (is<ProcessingInstruction>(this)) {
// ProcessingInstruction
auto processing_instruction = verify_cast<ProcessingInstruction>(this);
// Set copys target and data to those of node.
auto processing_instruction_copy = heap().allocate<ProcessingInstruction>(realm(), *document, processing_instruction->data(), processing_instruction->target());
auto processing_instruction_copy = realm().create<ProcessingInstruction>(*document, processing_instruction->data(), processing_instruction->target());
copy = processing_instruction_copy;
}
// Otherwise, Do nothing.
else if (is<DocumentFragment>(this)) {
copy = heap().allocate<DocumentFragment>(realm(), *document);
copy = realm().create<DocumentFragment>(*document);
}
// FIXME: 4. Set copys node document and document to copy, if copy is a document, and set copys node document to document otherwise.
@ -1551,7 +1551,7 @@ void Node::string_replace_all(String const& string)
// 2. If string is not the empty string, then set node to a new Text node whose data is string and node document is parents node document.
if (!string.is_empty())
node = heap().allocate<Text>(realm(), document(), string);
node = realm().create<Text>(document(), string);
// 3. Replace all with node within parent.
replace_all(node);
@ -1588,7 +1588,7 @@ WebIDL::ExceptionOr<void> Node::unsafely_set_html(Element& context_element, Stri
auto new_children = HTML::HTMLParser::parse_html_fragment(context_element, html, HTML::HTMLParser::AllowDeclarativeShadowRoots::Yes);
// 2. Let fragment be a new DocumentFragment whose node document is contextElements node document.
auto fragment = heap().allocate<DocumentFragment>(realm(), context_element.document());
auto fragment = realm().create<DocumentFragment>(context_element.document());
// 3. For each node in newChildren, append node to fragment.
for (auto& child : new_children)

View file

@ -15,7 +15,7 @@ JS_DEFINE_ALLOCATOR(NodeFilter);
JS::NonnullGCPtr<NodeFilter> NodeFilter::create(JS::Realm& realm, WebIDL::CallbackType& callback)
{
return realm.heap().allocate<NodeFilter>(realm, realm, callback);
return realm.create<NodeFilter>(realm, callback);
}
NodeFilter::NodeFilter(JS::Realm& realm, WebIDL::CallbackType& callback)

View file

@ -54,7 +54,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<NodeIterator>> NodeIterator::create(Node& r
// 2. Set iterators root and iterators reference to root.
// 3. Set iterators pointer before reference to true.
auto& realm = root.realm();
auto iterator = realm.heap().allocate<NodeIterator>(realm, root);
auto iterator = realm.create<NodeIterator>(root);
// 4. Set iterators whatToShow to whatToShow.
iterator->m_what_to_show = what_to_show;

View file

@ -27,13 +27,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> convert_nodes_to_single_node(Vector<
if (node.has<JS::Handle<Node>>())
return *node.get<JS::Handle<Node>>();
return document.heap().allocate<DOM::Text>(document.realm(), document, node.get<String>());
return document.realm().create<DOM::Text>(document, node.get<String>());
};
if (nodes.size() == 1)
return potentially_convert_string_to_text_node(nodes.first());
auto document_fragment = document.heap().allocate<DOM::DocumentFragment>(document.realm(), document);
auto document_fragment = document.realm().create<DOM::DocumentFragment>(document);
for (auto const& unconverted_node : nodes) {
auto node = potentially_convert_string_to_text_node(unconverted_node);
(void)TRY(document_fragment->append_child(node));

View file

@ -23,7 +23,7 @@ class Position final : public JS::Cell {
public:
[[nodiscard]] static JS::NonnullGCPtr<Position> create(JS::Realm& realm, JS::NonnullGCPtr<Node> node, unsigned offset)
{
return realm.heap().allocate<Position>(realm, node, offset);
return realm.create<Position>(node, offset);
}
JS::GCPtr<Node> node() { return m_node; }

View file

@ -45,13 +45,13 @@ JS::NonnullGCPtr<Range> Range::create(HTML::Window& window)
JS::NonnullGCPtr<Range> Range::create(Document& document)
{
auto& realm = document.realm();
return realm.heap().allocate<Range>(realm, document);
return realm.create<Range>(document);
}
JS::NonnullGCPtr<Range> Range::create(Node& start_container, WebIDL::UnsignedLong start_offset, Node& end_container, WebIDL::UnsignedLong end_offset)
{
auto& realm = start_container.realm();
return realm.heap().allocate<Range>(realm, start_container, start_offset, end_container, end_offset);
return realm.create<Range>(start_container, start_offset, end_container, end_offset);
}
WebIDL::ExceptionOr<JS::NonnullGCPtr<Range>> Range::construct_impl(JS::Realm& realm)
@ -442,12 +442,12 @@ WebIDL::ExceptionOr<void> Range::select_node_contents(Node& node)
JS::NonnullGCPtr<Range> Range::clone_range() const
{
return heap().allocate<Range>(shape().realm(), const_cast<Node&>(*m_start_container), m_start_offset, const_cast<Node&>(*m_end_container), m_end_offset);
return shape().realm().create<Range>(const_cast<Node&>(*m_start_container), m_start_offset, const_cast<Node&>(*m_end_container), m_end_offset);
}
JS::NonnullGCPtr<Range> Range::inverted() const
{
return heap().allocate<Range>(shape().realm(), const_cast<Node&>(*m_end_container), m_end_offset, const_cast<Node&>(*m_start_container), m_start_offset);
return shape().realm().create<Range>(const_cast<Node&>(*m_end_container), m_end_offset, const_cast<Node&>(*m_start_container), m_start_offset);
}
JS::NonnullGCPtr<Range> Range::normalized() const
@ -607,7 +607,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract_contents(
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::extract()
{
// 1. Let fragment be a new DocumentFragment node whose node document is ranges start nodes node document.
auto fragment = heap().allocate<DOM::DocumentFragment>(realm(), const_cast<Document&>(start_container()->document()));
auto fragment = realm().create<DOM::DocumentFragment>(const_cast<Document&>(start_container()->document()));
// 2. If range is collapsed, then return fragment.
if (collapsed())
@ -936,7 +936,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_contents()
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::clone_the_contents()
{
// 1. Let fragment be a new DocumentFragment node whose node document is ranges start nodes node document.
auto fragment = heap().allocate<DOM::DocumentFragment>(realm(), const_cast<Document&>(start_container()->document()));
auto fragment = realm().create<DOM::DocumentFragment>(const_cast<Document&>(start_container()->document()));
// 2. If range is collapsed, then return fragment.
if (collapsed())

View file

@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(StaticNodeList);
JS::NonnullGCPtr<NodeList> StaticNodeList::create(JS::Realm& realm, Vector<JS::Handle<Node>> static_nodes)
{
return realm.heap().allocate<StaticNodeList>(realm, realm, move(static_nodes));
return realm.create<StaticNodeList>(realm, move(static_nodes));
}
StaticNodeList::StaticNodeList(JS::Realm& realm, Vector<JS::Handle<Node>> static_nodes)

View file

@ -35,7 +35,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<StaticRange>> StaticRange::construct_impl(J
return WebIDL::InvalidNodeTypeError::create(realm, "endContainer cannot be a DocumentType or Attribute node."_string);
// 2. Set thiss start to (init["startContainer"], init["startOffset"]) and end to (init["endContainer"], init["endOffset"]).
return realm.heap().allocate<StaticRange>(realm, *init.start_container, init.start_offset, *init.end_container, init.end_offset);
return realm.create<StaticRange>(*init.start_container, init.start_offset, *init.end_container, init.end_offset);
}
void StaticRange::initialize(JS::Realm& realm)

View file

@ -45,7 +45,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::construct_impl(JS::Realm& real
{
// The new Text(data) constructor steps are to set thiss data to data and thiss node document to current global objects associated Document.
auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
return realm.heap().allocate<Text>(realm, window.associated_document(), data);
return realm.create<Text>(window.associated_document(), data);
}
// https://dom.spec.whatwg.org/#dom-text-splittext
@ -66,7 +66,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::split_text(size_t offset)
auto new_data = TRY(substring_data(offset, count));
// 5. Let new node be a new Text node, with the same node document as node. Set new nodes data to new data.
auto new_node = heap().allocate<Text>(realm(), document(), new_data);
auto new_node = realm().create<Text>(document(), new_data);
// 6. Let parent be nodes parent.
JS::GCPtr<Node> parent = this->parent();

View file

@ -45,7 +45,7 @@ JS::NonnullGCPtr<TreeWalker> TreeWalker::create(Node& root, unsigned what_to_sho
// 1. Let walker be a new TreeWalker object.
// 2. Set walkers root and walkers current to root.
auto& realm = root.realm();
auto walker = realm.heap().allocate<TreeWalker>(realm, root);
auto walker = realm.create<TreeWalker>(root);
// 3. Set walkers whatToShow to whatToShow.
walker->m_what_to_show = what_to_show;

View file

@ -13,7 +13,7 @@ JS_DEFINE_ALLOCATOR(XMLDocument);
JS::NonnullGCPtr<XMLDocument> XMLDocument::create(JS::Realm& realm, URL::URL const& url)
{
return realm.heap().allocate<XMLDocument>(realm, realm, url);
return realm.create<XMLDocument>(realm, url);
}
XMLDocument::XMLDocument(JS::Realm& realm, URL::URL const& url)