LibWeb: Port Range interface from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-08-26 16:46:33 +12:00 committed by Andrew Kaster
parent 9f047819a5
commit 7b79324548
3 changed files with 8 additions and 8 deletions

View file

@ -551,7 +551,7 @@ WebIDL::ExceptionOr<i16> Range::compare_point(Node const& node, u32 offset) cons
} }
// https://dom.spec.whatwg.org/#dom-range-stringifier // https://dom.spec.whatwg.org/#dom-range-stringifier
DeprecatedString Range::to_deprecated_string() const String Range::to_string() const
{ {
// 1. Let s be the empty string. // 1. Let s be the empty string.
StringBuilder builder; StringBuilder builder;
@ -559,7 +559,7 @@ DeprecatedString Range::to_deprecated_string() const
// 2. If thiss start node is thiss end node and it is a Text node, // 2. If thiss start node is thiss end node and it is a Text node,
// then return the substring of that Text nodes data beginning at thiss start offset and ending at thiss end offset. // then return the substring of that Text nodes data beginning at thiss start offset and ending at thiss end offset.
if (start_container() == end_container() && is<Text>(*start_container())) if (start_container() == end_container() && is<Text>(*start_container()))
return static_cast<Text const&>(*start_container()).data().substring(start_offset(), end_offset() - start_offset()); return String::from_deprecated_string(static_cast<Text const&>(*start_container()).data().substring(start_offset(), end_offset() - start_offset())).release_value();
// 3. If thiss start node is a Text node, then append the substring of that nodes data from thiss start offset until the end to s. // 3. If thiss start node is a Text node, then append the substring of that nodes data from thiss start offset until the end to s.
if (is<Text>(*start_container())) if (is<Text>(*start_container()))
@ -576,7 +576,7 @@ DeprecatedString Range::to_deprecated_string() const
builder.append(static_cast<Text const&>(*end_container()).data().substring_view(0, end_offset())); builder.append(static_cast<Text const&>(*end_container()).data().substring_view(0, end_offset()));
// 6. Return s. // 6. Return s.
return builder.to_deprecated_string(); return MUST(builder.to_string());
} }
// https://dom.spec.whatwg.org/#dom-range-extractcontents // https://dom.spec.whatwg.org/#dom-range-extractcontents
@ -1145,7 +1145,7 @@ JS::NonnullGCPtr<Geometry::DOMRect> Range::get_bounding_client_rect() const
} }
// https://w3c.github.io/DOM-Parsing/#dom-range-createcontextualfragment // https://w3c.github.io/DOM-Parsing/#dom-range-createcontextualfragment
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::create_contextual_fragment(DeprecatedString const& fragment) WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::create_contextual_fragment(String const& fragment)
{ {
// 1. Let node be the context object's start node. // 1. Let node be the context object's start node.
JS::NonnullGCPtr<Node> node = *start_container(); JS::NonnullGCPtr<Node> node = *start_container();
@ -1185,7 +1185,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> Range::create_contextual
} }
// 3. Let fragment node be the result of invoking the fragment parsing algorithm with fragment as markup, and element as the context element. // 3. Let fragment node be the result of invoking the fragment parsing algorithm with fragment as markup, and element as the context element.
auto fragment_node = TRY(DOMParsing::parse_fragment(fragment, *element)); auto fragment_node = TRY(DOMParsing::parse_fragment(fragment.to_deprecated_string(), *element));
// 4. Unmark all scripts in fragment node as "already started" and as "parser-inserted". // 4. Unmark all scripts in fragment node as "already started" and as "parser-inserted".
fragment_node->for_each_in_subtree_of_type<HTML::HTMLScriptElement>([&](HTML::HTMLScriptElement& script_element) { fragment_node->for_each_in_subtree_of_type<HTML::HTMLScriptElement>([&](HTML::HTMLScriptElement& script_element) {

View file

@ -79,7 +79,7 @@ public:
WebIDL::ExceptionOr<void> insert_node(JS::NonnullGCPtr<Node>); WebIDL::ExceptionOr<void> insert_node(JS::NonnullGCPtr<Node>);
WebIDL::ExceptionOr<void> surround_contents(JS::NonnullGCPtr<Node> new_parent); WebIDL::ExceptionOr<void> surround_contents(JS::NonnullGCPtr<Node> new_parent);
DeprecatedString to_deprecated_string() const; String to_string() const;
static HashTable<Range*>& live_ranges(); static HashTable<Range*>& live_ranges();
@ -89,7 +89,7 @@ public:
void set_associated_selection(Badge<Selection::Selection>, JS::GCPtr<Selection::Selection>); void set_associated_selection(Badge<Selection::Selection>, JS::GCPtr<Selection::Selection>);
WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> create_contextual_fragment(DeprecatedString const& fragment); WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> create_contextual_fragment(String const& fragment);
private: private:
explicit Range(Document&); explicit Range(Document&);

View file

@ -427,7 +427,7 @@ String Selection::to_string() const
// See https://www.w3.org/Bugs/Public/show_bug.cgi?id=10583 // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=10583
if (!m_range) if (!m_range)
return String {}; return String {};
return String::from_deprecated_string(m_range->to_deprecated_string()).release_value(); return m_range->to_string();
} }
JS::NonnullGCPtr<DOM::Document> Selection::document() const JS::NonnullGCPtr<DOM::Document> Selection::document() const