LibJS: Create exception messages as Strings

The JS::Error types all store their exception messages as a String. So
by using ByteString, we hit the StringView constructor, and end up
allocating the same string twice.
This commit is contained in:
Timothy Flynn 2024-07-17 09:55:20 -04:00 committed by Tim Flynn
parent 144e822de2
commit c3f8202d0c
Notes: sideshowbarker 2024-07-18 02:44:22 +09:00

View file

@ -198,10 +198,16 @@ public:
return JS::throw_completion(completion);
}
template<typename T>
Completion throw_completion(ErrorType type)
{
return throw_completion<T>(String::from_utf8_without_validation(type.message().bytes()));
}
template<typename T, typename... Args>
Completion throw_completion(ErrorType type, Args&&... args)
{
return throw_completion<T>(ByteString::formatted(type.message(), forward<Args>(args)...));
return throw_completion<T>(MUST(String::formatted(type.message(), forward<Args>(args)...)));
}
Value get_new_target();