Browse Source

LibWeb: Port Element::insert_adjacent from ByteString

Shannon Booth 1 year ago
parent
commit
e6861cb5ef

+ 3 - 3
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -1468,7 +1468,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(String const& position,
 }
 
 // https://dom.spec.whatwg.org/#insert-adjacent
-WebIDL::ExceptionOr<JS::GCPtr<Node>> Element::insert_adjacent(ByteString const& where, JS::NonnullGCPtr<Node> node)
+WebIDL::ExceptionOr<JS::GCPtr<Node>> Element::insert_adjacent(StringView where, JS::NonnullGCPtr<Node> node)
 {
     // To insert adjacent, given an element element, string where, and a node node, run the steps associated with the first ASCII case-insensitive match for where:
     if (Infra::is_ascii_case_insensitive_match(where, "beforebegin"sv)) {
@@ -1512,7 +1512,7 @@ WebIDL::ExceptionOr<JS::GCPtr<Node>> Element::insert_adjacent(ByteString const&
 WebIDL::ExceptionOr<JS::GCPtr<Element>> Element::insert_adjacent_element(String const& where, JS::NonnullGCPtr<Element> element)
 {
     // The insertAdjacentElement(where, element) method steps are to return the result of running insert adjacent, give this, where, and element.
-    auto returned_node = TRY(insert_adjacent(where.to_byte_string(), move(element)));
+    auto returned_node = TRY(insert_adjacent(where, element));
     if (!returned_node)
         return JS::GCPtr<Element> { nullptr };
     return JS::GCPtr<Element> { verify_cast<Element>(*returned_node) };
@@ -1526,7 +1526,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_text(String const& where, Str
 
     // 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.to_byte_string(), text));
+    (void)TRY(insert_adjacent(where, text));
     return {};
 }
 

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Element.h

@@ -391,7 +391,7 @@ private:
 
     void invalidate_style_after_attribute_change(FlyString const& attribute_name);
 
-    WebIDL::ExceptionOr<JS::GCPtr<Node>> insert_adjacent(ByteString const& where, JS::NonnullGCPtr<Node> node);
+    WebIDL::ExceptionOr<JS::GCPtr<Node>> insert_adjacent(StringView where, JS::NonnullGCPtr<Node> node);
 
     void enqueue_an_element_on_the_appropriate_element_queue();