mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +00: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
69 changed files with 223 additions and 186 deletions
|
@ -64,8 +64,26 @@
|
|||
#include <LibJS/Runtime/WeakSet.h>
|
||||
|
||||
namespace {
|
||||
|
||||
ErrorOr<void> print_value(JS::PrintContext&, JS::Value value, HashTable<JS::Object*>& seen_objects);
|
||||
|
||||
template<typename T>
|
||||
ErrorOr<void> print_value(JS::PrintContext& print_context, JS::ThrowCompletionOr<T> value_or_error, HashTable<JS::Object*>& seen_objects)
|
||||
{
|
||||
if (value_or_error.is_error()) {
|
||||
auto error = value_or_error.release_error();
|
||||
|
||||
// We can't explicitly check for OOM because InternalError does not store the ErrorType
|
||||
VERIFY(error.value().has_value());
|
||||
VERIFY(error.value()->is_object());
|
||||
VERIFY(is<JS::InternalError>(error.value()->as_object()));
|
||||
|
||||
return Error::from_errno(ENOMEM);
|
||||
}
|
||||
|
||||
return print_value(print_context, value_or_error.release_value(), seen_objects);
|
||||
}
|
||||
|
||||
DeprecatedString strip_ansi(StringView format_string)
|
||||
{
|
||||
if (format_string.is_empty())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue