ThrowableFormat.h 692 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/CheckedFormatString.h>
  8. #include <AK/DeprecatedString.h>
  9. #include <AK/Format.h>
  10. #include <LibJS/Runtime/Completion.h>
  11. #include <LibJS/Runtime/ErrorTypes.h>
  12. #include <LibJS/Runtime/VM.h>
  13. namespace JS {
  14. template<typename... Args>
  15. ThrowCompletionOr<DeprecatedString> deprecated_format(VM& vm, CheckedFormatString<Args...>&& fmtstr, Args const&... args)
  16. {
  17. StringBuilder builder;
  18. AK::VariadicFormatParams parameters { args... };
  19. TRY_OR_THROW_OOM(vm, vformat(builder, fmtstr.view(), parameters));
  20. return builder.to_deprecated_string();
  21. }
  22. }