mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibJS: Add preparation for Temporal constructors and prototypes
Add a JS_ENUMERATE_TEMPORAL_OBJECTS macro and use it to generate: - Forward declarations - CommonPropertyNames class name members - Constructor and prototype GlobalObject members, getters, visitors, and initialize_constructor() calls
This commit is contained in:
parent
7da1fcb2ef
commit
6735353b96
4 changed files with 44 additions and 0 deletions
|
@ -76,6 +76,8 @@
|
|||
__JS_ENUMERATE(Float32Array, float32_array, Float32ArrayPrototype, Float32ArrayConstructor, float) \
|
||||
__JS_ENUMERATE(Float64Array, float64_array, Float64ArrayPrototype, Float64ArrayConstructor, double)
|
||||
|
||||
#define JS_ENUMERATE_TEMPORAL_OBJECTS
|
||||
|
||||
#define JS_ENUMERATE_ITERATOR_PROTOTYPES \
|
||||
__JS_ENUMERATE(Iterator, iterator) \
|
||||
__JS_ENUMERATE(ArrayIterator, array_iterator) \
|
||||
|
@ -185,6 +187,15 @@ JS_ENUMERATE_NATIVE_ERRORS
|
|||
JS_ENUMERATE_TYPED_ARRAYS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
namespace Temporal {
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName) \
|
||||
class ClassName; \
|
||||
class ConstructorName; \
|
||||
class PrototypeName;
|
||||
JS_ENUMERATE_TEMPORAL_OBJECTS
|
||||
#undef __JS_ENUMERATE
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class Handle;
|
||||
|
||||
|
|
|
@ -344,6 +344,9 @@ struct CommonPropertyNames {
|
|||
#define __JS_ENUMERATE(x, a, b, c, t) PropertyName x { #x, PropertyName::StringMayBeNumber::No };
|
||||
JS_ENUMERATE_BUILTIN_TYPES
|
||||
#undef __JS_ENUMERATE
|
||||
#define __JS_ENUMERATE(x, a, b, c) PropertyName x { #x, PropertyName::StringMayBeNumber::No };
|
||||
JS_ENUMERATE_TEMPORAL_OBJECTS
|
||||
#undef __JS_ENUMERATE
|
||||
#define __JS_ENUMERATE(x, a) PropertyName x { #x, PropertyName::StringMayBeNumber::No };
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
#undef __JS_ENUMERATE
|
||||
|
|
|
@ -133,6 +133,18 @@ void GlobalObject::initialize_global_object()
|
|||
JS_ENUMERATE_BUILTIN_TYPES
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
if (!m_temporal_##snake_name##_prototype) \
|
||||
m_temporal_##snake_name##_prototype = heap().allocate<Temporal::PrototypeName>(*this, *this);
|
||||
JS_ENUMERATE_TEMPORAL_OBJECTS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
// Must be allocated before `Temporal::Temporal` below.
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
initialize_constructor(vm.names.ClassName, m_temporal_##snake_name##_constructor, m_temporal_##snake_name##_prototype);
|
||||
JS_ENUMERATE_TEMPORAL_OBJECTS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.gc, gc, 0, attr);
|
||||
define_native_function(vm.names.isNaN, is_nan, 1, attr);
|
||||
|
@ -235,6 +247,12 @@ void GlobalObject::visit_edges(Visitor& visitor)
|
|||
JS_ENUMERATE_BUILTIN_TYPES
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
visitor.visit(m_temporal_##snake_name##_constructor); \
|
||||
visitor.visit(m_temporal_##snake_name##_prototype);
|
||||
JS_ENUMERATE_TEMPORAL_OBJECTS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name) \
|
||||
visitor.visit(m_##snake_name##_prototype);
|
||||
JS_ENUMERATE_ITERATOR_PROTOTYPES
|
||||
|
|
|
@ -46,6 +46,12 @@ public:
|
|||
JS_ENUMERATE_BUILTIN_TYPES
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
Temporal::ConstructorName* temporal_##snake_name##_constructor() { return m_temporal_##snake_name##_constructor; } \
|
||||
Object* temporal_##snake_name##_prototype() { return m_temporal_##snake_name##_prototype; }
|
||||
JS_ENUMERATE_TEMPORAL_OBJECTS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name) \
|
||||
Object* snake_name##_prototype() { return m_##snake_name##_prototype; }
|
||||
JS_ENUMERATE_ITERATOR_PROTOTYPES
|
||||
|
@ -95,6 +101,12 @@ private:
|
|||
JS_ENUMERATE_BUILTIN_TYPES
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||
Temporal::ConstructorName* m_temporal_##snake_name##_constructor { nullptr }; \
|
||||
Object* m_temporal_##snake_name##_prototype { nullptr };
|
||||
JS_ENUMERATE_TEMPORAL_OBJECTS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name) \
|
||||
Object* m_##snake_name##_prototype { nullptr };
|
||||
JS_ENUMERATE_ITERATOR_PROTOTYPES
|
||||
|
|
Loading…
Add table
Reference in a new issue