From 8269921212875b75c918bde5d318f0c5de152dac Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 6 Jul 2021 19:14:47 +0100 Subject: [PATCH] LibJS: Add the Temporal namespace object :^) Currently empty, but we gotta start somewhere! This is the start of implementing the Temporal proposal (currently stage 3). I have decided to start a new subdirectory (Runtime/Temporal/) as well as a new C++ namespace (JS::Temporal) for this so we don't have to prefix all the files and classes with "Temporal" - there will be a lot. https://tc39.es/proposal-temporal/ --- Userland/Libraries/LibJS/CMakeLists.txt | 1 + .../LibJS/Runtime/CommonPropertyNames.h | 1 + .../Libraries/LibJS/Runtime/GlobalObject.cpp | 2 ++ .../LibJS/Runtime/Temporal/Temporal.cpp | 23 +++++++++++++++++++ .../LibJS/Runtime/Temporal/Temporal.h | 22 ++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp create mode 100644 Userland/Libraries/LibJS/Runtime/Temporal/Temporal.h diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index 78f363405a..23dbc4d8bb 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/Temporal.cpp Runtime/TypedArray.cpp Runtime/TypedArrayConstructor.cpp Runtime/TypedArrayPrototype.cpp diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h index da8e9fcfa4..b792d0a5e4 100644 --- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h +++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h @@ -46,6 +46,7 @@ namespace JS { P(SQRT2) \ P(String) \ P(Symbol) \ + P(Temporal) \ P(UTC) \ P(abs) \ P(acos) \ diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 557be0be08..75db91487a 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -170,6 +171,7 @@ void GlobalObject::initialize_global_object() define_direct_property(vm.names.Math, heap().allocate(*this, *this), attr); define_direct_property(vm.names.JSON, heap().allocate(*this, *this), attr); define_direct_property(vm.names.Reflect, heap().allocate(*this, *this), attr); + define_direct_property(vm.names.Temporal, heap().allocate(*this, *this), attr); // This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype. initialize_constructor(vm.names.Error, m_error_constructor, m_error_prototype); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp new file mode 100644 index 0000000000..99a285c848 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace JS::Temporal { + +// 1 The Temporal Object, https://tc39.es/proposal-temporal/#sec-temporal-objects +Temporal::Temporal(GlobalObject& global_object) + : Object(*global_object.object_prototype()) +{ +} + +void Temporal::initialize(GlobalObject& global_object) +{ + Object::initialize(global_object); +} + +} diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.h b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.h new file mode 100644 index 0000000000..f2f34f2d32 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace JS::Temporal { + +class Temporal final : public Object { + JS_OBJECT(Temporal, Object); + +public: + explicit Temporal(GlobalObject&); + virtual void initialize(GlobalObject&) override; + virtual ~Temporal() override = default; +}; + +}