mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
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.
This commit is contained in:
parent
69a56a8e39
commit
c3abb1396c
Notes:
sideshowbarker
2024-07-17 23:02:37 +09:00
Author: https://github.com/trflynn89
Commit: c3abb1396c
Pull-request: https://github.com/SerenityOS/serenity/pull/17388
Reviewed-by: https://github.com/linusg
69 changed files with 223 additions and 186 deletions
|
@ -188,6 +188,11 @@ NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, String string)
|
|||
return *new_string;
|
||||
}
|
||||
|
||||
ThrowCompletionOr<NonnullGCPtr<PrimitiveString>> PrimitiveString::create(VM& vm, StringView string)
|
||||
{
|
||||
return create(vm, TRY_OR_THROW_OOM(vm, String::from_utf8(string)));
|
||||
}
|
||||
|
||||
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, DeprecatedString string)
|
||||
{
|
||||
if (string.is_empty())
|
||||
|
@ -209,6 +214,11 @@ NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, DeprecatedString s
|
|||
return *it->value;
|
||||
}
|
||||
|
||||
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, DeprecatedFlyString const& string)
|
||||
{
|
||||
return create(vm, string.impl());
|
||||
}
|
||||
|
||||
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, PrimitiveString& lhs, PrimitiveString& rhs)
|
||||
{
|
||||
// We're here to concatenate two strings into a new rope string.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue