diff options
author | Linus Groh <mail@linusgroh.de> | 2021-07-06 20:39:55 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-07-07 00:42:01 +0100 |
commit | 6735353b969e9709343209099a6c52effe71688f (patch) | |
tree | 76eb20c68ea7be4f44a84761b136164d06ad4e22 /Userland/Libraries/LibJS/Runtime | |
parent | 7da1fcb2ef8b0a42d190aa73c770cc9edf4f6bb0 (diff) | |
download | serenity-6735353b969e9709343209099a6c52effe71688f.zip |
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
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/GlobalObject.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/GlobalObject.h | 12 |
3 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h index b792d0a5e4..35bdc71e9b 100644 --- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h +++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h @@ -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 diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 75db91487a..5f3acbcab2 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -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 diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h index b2b761f533..e470f0a0ae 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h @@ -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 |