1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:17:35 +00:00

LibJS: Make PrimitiveString::utf8_string() infallible

Work towards #20449.
This commit is contained in:
Andreas Kling 2023-08-08 19:17:55 +02:00
parent 7849950383
commit c084269e5f
29 changed files with 79 additions and 93 deletions

View file

@ -370,18 +370,7 @@ ErrorOr<String> Value::to_string_without_side_effects() const
case INT32_TAG:
return String::number(as_i32());
case STRING_TAG:
if (auto string = as_string().utf8_string(); string.is_throw_completion()) {
auto completion = string.release_error();
// We can't explicitly check for OOM because InternalError does not store the ErrorType
VERIFY(completion.value().has_value());
VERIFY(completion.value()->is_object());
VERIFY(is<InternalError>(completion.value()->as_object()));
return AK::Error::from_errno(ENOMEM);
} else {
return string.release_value();
}
return as_string().utf8_string();
case SYMBOL_TAG:
return as_symbol().descriptive_string();
case BIGINT_TAG:
@ -414,7 +403,7 @@ ThrowCompletionOr<String> Value::to_string(VM& vm) const
switch (m_value.tag) {
// 1. If argument is a String, return argument.
case STRING_TAG:
return TRY(as_string().utf8_string());
return as_string().utf8_string();
// 2. If argument is a Symbol, throw a TypeError exception.
case SYMBOL_TAG:
return vm.throw_completion<TypeError>(ErrorType::Convert, "symbol", "string");