diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-10 14:06:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-10 14:06:52 +0200 |
commit | cb0dfd8f724d466c5145d52433f8953898e22eaf (patch) | |
tree | 7fecc56f46b51f9e587f37e36656682b982be75c /Libraries/LibJS/Runtime/ErrorConstructor.cpp | |
parent | 0bdfb952c5d6ebe4499fe70259263db453101ef8 (diff) | |
download | serenity-cb0dfd8f724d466c5145d52433f8953898e22eaf.zip |
LibJS: Use enumerator macros for boilerplate code around native types
Diffstat (limited to 'Libraries/LibJS/Runtime/ErrorConstructor.cpp')
-rw-r--r-- | Libraries/LibJS/Runtime/ErrorConstructor.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Libraries/LibJS/Runtime/ErrorConstructor.cpp index a5a2a625a8..b62018fe02 100644 --- a/Libraries/LibJS/Runtime/ErrorConstructor.cpp +++ b/Libraries/LibJS/Runtime/ErrorConstructor.cpp @@ -53,28 +53,26 @@ Value ErrorConstructor::construct(Interpreter& interpreter) return interpreter.heap().allocate<Error>("Error", message); } -#define DEFINE_ERROR_SUBCLASS_CONSTRUCTOR(TitleCase, snake_case) \ - TitleCase##Constructor::TitleCase##Constructor() \ +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + ConstructorName::ConstructorName() \ { \ - put("prototype", interpreter().snake_case##_prototype()); \ + put("prototype", interpreter().snake_name##_prototype()); \ put("length", Value(1)); \ } \ - TitleCase##Constructor::~TitleCase##Constructor() {} \ - Value TitleCase##Constructor::call(Interpreter& interpreter) \ + ConstructorName::~ConstructorName() {} \ + Value ConstructorName::call(Interpreter& interpreter) \ { \ return construct(interpreter); \ } \ - Value TitleCase##Constructor::construct(Interpreter& interpreter) \ + Value ConstructorName::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); \ + return interpreter.heap().allocate<ClassName>(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 +#undef __JS_ENUMERATE } |