summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-07-06 20:39:55 +0100
committerLinus Groh <mail@linusgroh.de>2021-07-07 00:42:01 +0100
commit6735353b969e9709343209099a6c52effe71688f (patch)
tree76eb20c68ea7be4f44a84761b136164d06ad4e22 /Userland
parent7da1fcb2ef8b0a42d190aa73c770cc9edf4f6bb0 (diff)
downloadserenity-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')
-rw-r--r--Userland/Libraries/LibJS/Forward.h11
-rw-r--r--Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.cpp18
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.h12
4 files changed, 44 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Forward.h b/Userland/Libraries/LibJS/Forward.h
index e5676a9bc5..2d350e300a 100644
--- a/Userland/Libraries/LibJS/Forward.h
+++ b/Userland/Libraries/LibJS/Forward.h
@@ -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;
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