1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:27:35 +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:
Andreas Kling 2020-04-10 12:42:33 +02:00
parent df7b617ba1
commit 58ab76269c
11 changed files with 157 additions and 7 deletions

View file

@ -26,6 +26,7 @@
#pragma once
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/NativeFunction.h>
namespace JS {
@ -43,4 +44,22 @@ private:
virtual const char* class_name() const override { return "ErrorConstructor"; }
};
#define DECLARE_ERROR_SUBCLASS_CONSTRUCTOR(TitleCase, snake_case) \
class TitleCase##Constructor final : public NativeFunction { \
public: \
TitleCase##Constructor(); \
virtual ~TitleCase##Constructor() override; \
virtual Value call(Interpreter&) override; \
virtual Value construct(Interpreter&) override; \
\
private: \
virtual bool has_constructor() const override { return true; } \
virtual const char* class_name() const override { return #TitleCase "Constructor"; } \
};
#define __JS_ENUMERATE_ERROR_SUBCLASS(TitleCase, snake_case) \
DECLARE_ERROR_SUBCLASS_CONSTRUCTOR(TitleCase, snake_case)
JS_ENUMERATE_ERROR_SUBCLASSES
#undef __JS_ENUMERATE_ERROR_SUBCLASS
}