LibWeb: Implement Element.insertAdjacentText

This commit is contained in:
Luke Wilde 2022-10-01 00:30:38 +01:00 committed by Andreas Kling
parent d540e2ec98
commit 540c307009
Notes: sideshowbarker 2024-07-17 06:30:50 +09:00
3 changed files with 14 additions and 0 deletions

View file

@ -891,4 +891,16 @@ WebIDL::ExceptionOr<JS::GCPtr<Element>> Element::insert_adjacent_element(String
return JS::GCPtr<Element> { verify_cast<Element>(*returned_node) };
}
// https://dom.spec.whatwg.org/#dom-element-insertadjacenttext
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.
JS::NonnullGCPtr<Text> text = *heap().allocate<DOM::Text>(realm(), 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.
(void)TRY(insert_adjacent(where, move(text)));
return {};
}
}

View file

@ -145,6 +145,7 @@ public:
bool is_actually_disabled() const;
WebIDL::ExceptionOr<JS::GCPtr<Element>> insert_adjacent_element(String const& where, JS::NonnullGCPtr<Element> element);
WebIDL::ExceptionOr<void> insert_adjacent_text(String const& where, String const& data);
protected:
Element(Document&, DOM::QualifiedName);

View file

@ -54,6 +54,7 @@ interface Element : Node {
readonly attribute long clientHeight;
[CEReactions] Element? insertAdjacentElement(DOMString where, Element element);
undefined insertAdjacentText(DOMString where, DOMString data);
[CEReactions] undefined insertAdjacentHTML(DOMString position, DOMString text);
};