summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-07-06 19:33:20 +0100
committerLinus Groh <mail@linusgroh.de>2021-07-07 00:42:01 +0100
commit7da1fcb2ef8b0a42d190aa73c770cc9edf4f6bb0 (patch)
tree6c6f62d0ae41c716f637c21ce7c4979bc5675018 /Userland/Libraries
parent8269921212875b75c918bde5d318f0c5de152dac (diff)
downloadserenity-7da1fcb2ef8b0a42d190aa73c770cc9edf4f6bb0.zip
LibJS: Add the Temporal.now namespace object
This will be home to various functions: - Temporal.now.timeZone() - Temporal.now.instant() - Temporal.now.plainDateTime() - Temporal.now.plainDateTimeISO() - Temporal.now.zonedDateTime() - Temporal.now.zonedDateTimeISO() - Temporal.now.plainDate() - Temporal.now.plainDateISO() - Temporal.now.plainTimeISO()
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp23
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Now.h22
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp6
4 files changed, 52 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt
index 23dbc4d8bb..f3541f3d52 100644
--- a/Userland/Libraries/LibJS/CMakeLists.txt
+++ b/Userland/Libraries/LibJS/CMakeLists.txt
@@ -121,6 +121,7 @@ set(SOURCES
Runtime/SymbolConstructor.cpp
Runtime/SymbolObject.cpp
Runtime/SymbolPrototype.cpp
+ Runtime/Temporal/Now.cpp
Runtime/Temporal/Temporal.cpp
Runtime/TypedArray.cpp
Runtime/TypedArrayConstructor.cpp
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
new file mode 100644
index 0000000000..b372cb236b
--- /dev/null
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibJS/Runtime/GlobalObject.h>
+#include <LibJS/Runtime/Temporal/Now.h>
+
+namespace JS::Temporal {
+
+// 2 The Temporal.now Object, https://tc39.es/proposal-temporal/#sec-temporal-now-object
+Now::Now(GlobalObject& global_object)
+ : Object(*global_object.object_prototype())
+{
+}
+
+void Now::initialize(GlobalObject& global_object)
+{
+ Object::initialize(global_object);
+}
+
+}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.h b/Userland/Libraries/LibJS/Runtime/Temporal/Now.h
new file mode 100644
index 0000000000..1f0ec308f3
--- /dev/null
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibJS/Runtime/Object.h>
+
+namespace JS::Temporal {
+
+class Now final : public Object {
+ JS_OBJECT(Now, Object);
+
+public:
+ explicit Now(GlobalObject&);
+ virtual void initialize(GlobalObject&) override;
+ virtual ~Now() override = default;
+};
+
+}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp
index 99a285c848..e99ca3b89c 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp
@@ -5,6 +5,7 @@
*/
#include <LibJS/Runtime/GlobalObject.h>
+#include <LibJS/Runtime/Temporal/Now.h>
#include <LibJS/Runtime/Temporal/Temporal.h>
namespace JS::Temporal {
@@ -18,6 +19,11 @@ Temporal::Temporal(GlobalObject& global_object)
void Temporal::initialize(GlobalObject& global_object)
{
Object::initialize(global_object);
+
+ auto& vm = this->vm();
+ u8 attr = Attribute::Writable | Attribute::Configurable;
+
+ define_direct_property(vm.names.now, heap().allocate<Now>(global_object, global_object), attr);
}
}