summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2023-01-09 23:59:08 +0000
committerTim Flynn <trflynn89@pm.me>2023-01-09 22:14:35 -0500
commit63136615d22c76138804fa88786a46c954eec36e (patch)
tree00058977f74bc44575fb96b77622cb0a060ac4e6 /Userland/Libraries/LibJS
parent76f89bf50de2a70bb4410831edd1bbfcfea15a8f (diff)
downloadserenity-63136615d22c76138804fa88786a46c954eec36e.zip
LibJS: Make namespace object initialization lazy as well
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intrinsics.cpp18
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intrinsics.h7
2 files changed, 13 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp b/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
index 1ab3d19728..e80de460ba 100644
--- a/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -231,12 +231,6 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
m_throw_type_error_function->define_direct_property(vm.names.name, PrimitiveString::create(vm, ""), 0);
MUST(m_throw_type_error_function->internal_prevent_extensions());
-#define __JS_ENUMERATE(ClassName, snake_name) \
- VERIFY(!m_##snake_name##_object); \
- m_##snake_name##_object = heap().allocate<ClassName>(realm, realm);
- JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
-#undef __JS_ENUMERATE
-
initialize_constructor(vm, vm.names.Error, *m_error_constructor, m_error_prototype);
initialize_constructor(vm, vm.names.Function, *m_function_constructor, m_function_prototype);
initialize_constructor(vm, vm.names.Object, *m_object_constructor, m_object_prototype);
@@ -331,6 +325,16 @@ JS_ENUMERATE_TEMPORAL_OBJECTS
#undef __JS_ENUMERATE_INNER
+#define __JS_ENUMERATE(ClassName, snake_name) \
+ ClassName* Intrinsics::snake_name##_object() \
+ { \
+ if (!m_##snake_name##_object) \
+ m_##snake_name##_object = heap().allocate<ClassName>(m_realm, m_realm); \
+ return m_##snake_name##_object; \
+ }
+JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
+#undef __JS_ENUMERATE
+
void Intrinsics::visit_edges(Visitor& visitor)
{
visitor.visit(m_realm);
diff --git a/Userland/Libraries/LibJS/Runtime/Intrinsics.h b/Userland/Libraries/LibJS/Runtime/Intrinsics.h
index 0e335f9965..a0820fe614 100644
--- a/Userland/Libraries/LibJS/Runtime/Intrinsics.h
+++ b/Userland/Libraries/LibJS/Runtime/Intrinsics.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -78,10 +78,7 @@ public:
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(ClassName, snake_name) \
- ClassName* snake_name##_object() \
- { \
- return m_##snake_name##_object; \
- }
+ ClassName* snake_name##_object();
JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
#undef __JS_ENUMERATE