mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:17:35 +00:00
LibJS: Rename JS_ENUMERATE_{ERROR_SUBCLASSES => NATIVE_ERRORS}
The fact that they *are* subclasses is an implementation detail and should not be highlighted. The spec calls these NativeErrors, so let's use that. Also added a comment explaining *why* they inherit from Error - I was about to change that :^)
This commit is contained in:
parent
0e10dec324
commit
ad3242bab7
8 changed files with 48 additions and 45 deletions
|
@ -46,7 +46,7 @@
|
||||||
JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \
|
JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \
|
||||||
__JS_ENUMERATE(TypedArray, typed_array, TypedArrayPrototype, TypedArrayConstructor, void)
|
__JS_ENUMERATE(TypedArray, typed_array, TypedArrayPrototype, TypedArrayConstructor, void)
|
||||||
|
|
||||||
#define JS_ENUMERATE_ERROR_SUBCLASSES \
|
#define JS_ENUMERATE_NATIVE_ERRORS \
|
||||||
__JS_ENUMERATE(EvalError, eval_error, EvalErrorPrototype, EvalErrorConstructor, void) \
|
__JS_ENUMERATE(EvalError, eval_error, EvalErrorPrototype, EvalErrorConstructor, void) \
|
||||||
__JS_ENUMERATE(InternalError, internal_error, InternalErrorPrototype, InternalErrorConstructor, void) \
|
__JS_ENUMERATE(InternalError, internal_error, InternalErrorPrototype, InternalErrorConstructor, void) \
|
||||||
__JS_ENUMERATE(InvalidCharacterError, invalid_character_error, InvalidCharacterErrorPrototype, InvalidCharacterErrorConstructor, void) \
|
__JS_ENUMERATE(InvalidCharacterError, invalid_character_error, InvalidCharacterErrorPrototype, InvalidCharacterErrorConstructor, void) \
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
|
|
||||||
#define JS_ENUMERATE_BUILTIN_TYPES \
|
#define JS_ENUMERATE_BUILTIN_TYPES \
|
||||||
JS_ENUMERATE_NATIVE_OBJECTS \
|
JS_ENUMERATE_NATIVE_OBJECTS \
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES \
|
JS_ENUMERATE_NATIVE_ERRORS \
|
||||||
JS_ENUMERATE_TYPED_ARRAYS
|
JS_ENUMERATE_TYPED_ARRAYS
|
||||||
|
|
||||||
#define JS_ENUMERATE_WELL_KNOWN_SYMBOLS \
|
#define JS_ENUMERATE_WELL_KNOWN_SYMBOLS \
|
||||||
|
@ -160,7 +160,7 @@ struct ClampedU8;
|
||||||
class ConstructorName; \
|
class ConstructorName; \
|
||||||
class PrototypeName;
|
class PrototypeName;
|
||||||
JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES
|
JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
JS_ENUMERATE_TYPED_ARRAYS
|
JS_ENUMERATE_TYPED_ARRAYS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ Error::Error(Object& prototype)
|
||||||
{ \
|
{ \
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,19 +22,22 @@ public:
|
||||||
virtual ~Error() override = default;
|
virtual ~Error() override = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_ERROR_SUBCLASS(ClassName, snake_name, PrototypeName, ConstructorName) \
|
// NOTE: Making these inherit from Error is not required by the spec but
|
||||||
class ClassName final : public Error { \
|
// our way of implementing the [[ErrorData]] internal slot, which is
|
||||||
JS_OBJECT(ClassName, Error); \
|
// used in Object.prototype.toString().
|
||||||
\
|
#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||||
public: \
|
class ClassName final : public Error { \
|
||||||
static ClassName* create(GlobalObject&, const String& message = {}); \
|
JS_OBJECT(ClassName, Error); \
|
||||||
\
|
\
|
||||||
explicit ClassName(Object& prototype); \
|
public: \
|
||||||
virtual ~ClassName() override = default; \
|
static ClassName* create(GlobalObject&, const String& message = {}); \
|
||||||
|
\
|
||||||
|
explicit ClassName(Object& prototype); \
|
||||||
|
virtual ~ClassName() override = default; \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
DECLARE_ERROR_SUBCLASS(ClassName, snake_name, PrototypeName, ConstructorName)
|
DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName)
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ Value ErrorConstructor::construct(Function&)
|
||||||
return ClassName::create(global_object(), message); \
|
return ClassName::create(global_object(), message); \
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,24 +26,24 @@ private:
|
||||||
virtual bool has_constructor() const override { return true; }
|
virtual bool has_constructor() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_ERROR_SUBCLASS_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName) \
|
#define DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||||
class ConstructorName final : public NativeFunction { \
|
class ConstructorName final : public NativeFunction { \
|
||||||
JS_OBJECT(ConstructorName, NativeFunction); \
|
JS_OBJECT(ConstructorName, NativeFunction); \
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
explicit ConstructorName(GlobalObject&); \
|
explicit ConstructorName(GlobalObject&); \
|
||||||
virtual void initialize(GlobalObject&) override; \
|
virtual void initialize(GlobalObject&) override; \
|
||||||
virtual ~ConstructorName() override; \
|
virtual ~ConstructorName() override; \
|
||||||
virtual Value call() override; \
|
virtual Value call() override; \
|
||||||
virtual Value construct(Function& new_target) override; \
|
virtual Value construct(Function& new_target) override; \
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
virtual bool has_constructor() const override { return true; } \
|
virtual bool has_constructor() const override { return true; } \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
DECLARE_ERROR_SUBCLASS_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName)
|
DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName)
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
|
||||||
define_property(vm.names.message, js_string(vm, ""), attr); \
|
define_property(vm.names.message, js_string(vm, ""), attr); \
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,19 +22,19 @@ private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_ERROR_SUBCLASS_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
#define DECLARE_NATIVE_ERROR_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||||
class PrototypeName final : public Object { \
|
class PrototypeName final : public Object { \
|
||||||
JS_OBJECT(PrototypeName, Object); \
|
JS_OBJECT(PrototypeName, Object); \
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
explicit PrototypeName(GlobalObject&); \
|
explicit PrototypeName(GlobalObject&); \
|
||||||
virtual void initialize(GlobalObject&) override; \
|
virtual void initialize(GlobalObject&) override; \
|
||||||
virtual ~PrototypeName() override = default; \
|
virtual ~PrototypeName() override = default; \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
DECLARE_ERROR_SUBCLASS_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName)
|
DECLARE_NATIVE_ERROR_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName)
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -151,7 +151,7 @@ void GlobalObject::initialize_global_object()
|
||||||
|
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
add_constructor(vm.names.ClassName, m_##snake_name##_constructor, m_##snake_name##_prototype);
|
add_constructor(vm.names.ClassName, m_##snake_name##_constructor, m_##snake_name##_prototype);
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
JS_ENUMERATE_TYPED_ARRAYS
|
JS_ENUMERATE_TYPED_ARRAYS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ void GlobalObject::visit_edges(Visitor& visitor)
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
visitor.visit(m_##snake_name##_constructor); \
|
visitor.visit(m_##snake_name##_constructor); \
|
||||||
visitor.visit(m_##snake_name##_prototype);
|
visitor.visit(m_##snake_name##_prototype);
|
||||||
JS_ENUMERATE_ERROR_SUBCLASSES
|
JS_ENUMERATE_NATIVE_ERRORS
|
||||||
JS_ENUMERATE_BUILTIN_TYPES
|
JS_ENUMERATE_BUILTIN_TYPES
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue