mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibJS: Add all the Error subclasses
This patch adds instance, constructor and prototype classes for: - EvalError - InternalError - RangeError - ReferenceError - SyntaxError - TypeError - URIError Enumerator macros are used to reduce the amount of typing. :^)
This commit is contained in:
parent
df7b617ba1
commit
58ab76269c
11 changed files with 157 additions and 7 deletions
|
@ -53,4 +53,28 @@ Value ErrorConstructor::construct(Interpreter& interpreter)
|
|||
return interpreter.heap().allocate<Error>("Error", message);
|
||||
}
|
||||
|
||||
#define DEFINE_ERROR_SUBCLASS_CONSTRUCTOR(TitleCase, snake_case) \
|
||||
TitleCase##Constructor::TitleCase##Constructor() \
|
||||
{ \
|
||||
put("prototype", interpreter().snake_case##_prototype()); \
|
||||
put("length", Value(1)); \
|
||||
} \
|
||||
TitleCase##Constructor::~TitleCase##Constructor() {} \
|
||||
Value TitleCase##Constructor::call(Interpreter& interpreter) \
|
||||
{ \
|
||||
return construct(interpreter); \
|
||||
} \
|
||||
Value TitleCase##Constructor::construct(Interpreter& interpreter) \
|
||||
{ \
|
||||
String message = ""; \
|
||||
if (!interpreter.call_frame().arguments.is_empty() && !interpreter.call_frame().arguments[0].is_undefined()) \
|
||||
message = interpreter.call_frame().arguments[0].to_string(); \
|
||||
return interpreter.heap().allocate<TitleCase>(message); \
|
||||
}
|
||||
|
||||
#define __JS_ENUMERATE_ERROR_SUBCLASS(TitleCase, snake_case) \
|
||||
DEFINE_ERROR_SUBCLASS_CONSTRUCTOR(TitleCase, snake_case)
|
||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
||||
#undef __JS_ENUMERATE_ERROR_SUBCLASS
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue