/* * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace JS { class ThrowableStringBuilder : private AK::StringBuilder { public: explicit ThrowableStringBuilder(VM&); ThrowCompletionOr append(char); ThrowCompletionOr append(StringView); ThrowCompletionOr append(Utf16View const&); ThrowCompletionOr append_code_point(u32 value); ThrowCompletionOr to_string() const; template ThrowCompletionOr appendff(CheckedFormatString&& fmtstr, Parameters const&... parameters) { AK::VariadicFormatParams variadic_format_params { parameters... }; if (vformat(*this, fmtstr.view(), variadic_format_params).is_error()) { // The size returned here is a bit of an estimate, as we don't know what the final formatted string length would be. return m_vm.throw_completion(ErrorType::NotEnoughMemoryToAllocate, length() + fmtstr.view().length()); } return {}; } using AK::StringBuilder::is_empty; using AK::StringBuilder::string_view; using AK::StringBuilder::trim; private: VM& m_vm; }; }