mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 21:45:20 +00:00
If we are out of memory, we can't try to allocate a string that could fail as well. When Error is converted to String, this would result in an endless OOM-throwing loop. Instead, pre-allocate the string on the VM, and use it to construct the Error. Note that as of this commit, the OOM string is still a DeprecatedString. This is just preporatory for Error's conversion to String.
46 lines
991 B
C++
46 lines
991 B
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Utf16View.h>
|
|
#include <LibJS/Runtime/ThrowableStringBuilder.h>
|
|
|
|
namespace JS {
|
|
|
|
ThrowableStringBuilder::ThrowableStringBuilder(VM& vm)
|
|
: m_vm(vm)
|
|
{
|
|
}
|
|
|
|
ThrowCompletionOr<void> ThrowableStringBuilder::append(char ch)
|
|
{
|
|
TRY_OR_THROW_OOM(m_vm, try_append(ch));
|
|
return {};
|
|
}
|
|
|
|
ThrowCompletionOr<void> ThrowableStringBuilder::append(StringView string)
|
|
{
|
|
TRY_OR_THROW_OOM(m_vm, try_append(string));
|
|
return {};
|
|
}
|
|
|
|
ThrowCompletionOr<void> ThrowableStringBuilder::append(Utf16View const& string)
|
|
{
|
|
TRY_OR_THROW_OOM(m_vm, try_append(string));
|
|
return {};
|
|
}
|
|
|
|
ThrowCompletionOr<void> ThrowableStringBuilder::append_code_point(u32 value)
|
|
{
|
|
TRY_OR_THROW_OOM(m_vm, try_append_code_point(value));
|
|
return {};
|
|
}
|
|
|
|
ThrowCompletionOr<String> ThrowableStringBuilder::to_string() const
|
|
{
|
|
return TRY_OR_THROW_OOM(m_vm, StringBuilder::to_string());
|
|
}
|
|
|
|
}
|