LibJS: Consolidate error messages into ErrorTypes.h

Now, exceptions can be thrown with
interpreter.throw_exception<T>(ErrorType:TYPE, "format", "args",
"here").
This commit is contained in:
Matthew Olsson 2020-06-09 22:48:01 -07:00 committed by Andreas Kling
parent 9940a7f6de
commit 78155a6668
Notes: sideshowbarker 2024-07-19 05:43:14 +09:00
63 changed files with 439 additions and 223 deletions

View file

@ -35,6 +35,7 @@
#include <LibJS/Console.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/ErrorTypes.h>
#include <LibJS/Runtime/Exception.h>
#include <LibJS/Runtime/LexicalEnvironment.h>
#include <LibJS/Runtime/MarkedValueList.h>
@ -175,6 +176,12 @@ public:
return throw_exception(heap().allocate<Exception>(value));
}
template<typename T, typename... Args>
Value throw_exception(ErrorType type, Args&&... args)
{
return throw_exception(T::create(global_object(), String::format(type.message(), forward<Args>(args)...)));
}
Value last_value() const { return m_last_value; }
bool underscore_is_last_value() const { return m_underscore_is_last_value; }