diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-02-09 09:00:14 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-09 17:13:33 +0000 |
commit | c3abb1396c4d3b87eee226c62e0726a2a65cbfd8 (patch) | |
tree | fbf3d644e1af9ddbc527b0a7e33af49af2f532b2 /Userland/Libraries/LibWeb/Fetch | |
parent | 69a56a8e39f495946bad8e11df4daa4ad0099dc1 (diff) | |
download | serenity-c3abb1396c4d3b87eee226c62e0726a2a65cbfd8.zip |
LibJS+LibWeb: Convert string view PrimitiveString instances to String
First, this adds an overload of PrimitiveString::create for StringView.
This overload will throw an OOM completion if creating a String fails.
This is not only a bit more convenient, but it also ensures at compile
time that all PrimitiveString::create(string_view) invocations will be
handled as String and OOM-aware.
Next, this wraps all invocations to PrimitiveString::create(string_view)
with MUST_OR_THROW_OOM.
A small PrimitiveString::create(DeprecatedFlyString) overload also had
to be added to disambiguate between the StringView and DeprecatedString
overloads.
Diffstat (limited to 'Userland/Libraries/LibWeb/Fetch')
-rw-r--r-- | Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp b/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp index 230d021f79..41fdd3e0cd 100644 --- a/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp +++ b/Userland/Libraries/LibWeb/Fetch/HeadersIterator.cpp @@ -68,14 +68,16 @@ JS::ThrowCompletionOr<JS::Object*> HeadersIterator::next() return create_iterator_result_object(vm(), JS::js_undefined(), true); auto const& pair = pairs[m_index++]; + StringView pair_name { pair.name }; + StringView pair_value { pair.value }; switch (m_iteration_kind) { case JS::Object::PropertyKind::Key: - return create_iterator_result_object(vm(), JS::PrimitiveString::create(vm(), StringView { pair.name }), false); + return create_iterator_result_object(vm(), MUST_OR_THROW_OOM(JS::PrimitiveString::create(vm(), pair_name)), false); case JS::Object::PropertyKind::Value: - return create_iterator_result_object(vm(), JS::PrimitiveString::create(vm(), StringView { pair.value }), false); + return create_iterator_result_object(vm(), MUST_OR_THROW_OOM(JS::PrimitiveString::create(vm(), pair_value)), false); case JS::Object::PropertyKind::KeyAndValue: { - auto array = JS::Array::create_from(realm(), { JS::PrimitiveString::create(vm(), StringView { pair.name }), JS::PrimitiveString::create(vm(), StringView { pair.value }) }); + auto array = JS::Array::create_from(realm(), { MUST_OR_THROW_OOM(JS::PrimitiveString::create(vm(), pair_name)), MUST_OR_THROW_OOM(JS::PrimitiveString::create(vm(), pair_value)) }); return create_iterator_result_object(vm(), array, false); } default: |