From a37dcf8ca75a4601280d649c4f17c3faeef9c886 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 8 Aug 2021 18:27:28 +0100 Subject: [PATCH] LibJS: Add the Intl namespace object :^) This is the start of implementing ECMA-402 in LibJS, better known as the ECMAScript Internationalization API. Much like Temporal this gets its own subdirectory (Runtime/Intl/) as well as a new C++ namespace (JS::Intl) so we don't have to prefix all the files and classes with "Intl". https://tc39.es/ecma402/ --- Userland/Libraries/LibJS/CMakeLists.txt | 1 + .../LibJS/Runtime/CommonPropertyNames.h | 1 + .../Libraries/LibJS/Runtime/GlobalObject.cpp | 2 ++ .../Libraries/LibJS/Runtime/Intl/Intl.cpp | 23 +++++++++++++++++++ Userland/Libraries/LibJS/Runtime/Intl/Intl.h | 22 ++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp create mode 100644 Userland/Libraries/LibJS/Runtime/Intl/Intl.h diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index 04755eb20b..15319f9828 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -72,6 +72,7 @@ set(SOURCES Runtime/GlobalEnvironment.cpp Runtime/GlobalObject.cpp Runtime/IndexedProperties.cpp + Runtime/Intl/Intl.cpp Runtime/IteratorOperations.cpp Runtime/IteratorPrototype.cpp Runtime/JSONObject.cpp diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h index ebeef2e506..47d3d1f80e 100644 --- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h +++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h @@ -25,6 +25,7 @@ namespace JS { P(EPSILON) \ P(Function) \ P(Infinity) \ + P(Intl) \ P(JSON) \ P(LN10) \ P(LN2) \ diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index d2fee8c659..c6f0439f98 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -203,6 +204,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.Intl, 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. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp new file mode 100644 index 0000000000..d32638ea29 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace JS::Intl { + +// 8 The Intl Object, https://tc39.es/ecma402/#intl-object +Intl::Intl(GlobalObject& global_object) + : Object(*global_object.object_prototype()) +{ +} + +void Intl::initialize(GlobalObject& global_object) +{ + Object::initialize(global_object); +} + +} diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Intl.h b/Userland/Libraries/LibJS/Runtime/Intl/Intl.h new file mode 100644 index 0000000000..b4c09740f5 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Intl/Intl.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace JS::Intl { + +class Intl final : public Object { + JS_OBJECT(Intl, Object); + +public: + explicit Intl(GlobalObject&); + virtual void initialize(GlobalObject&) override; + virtual ~Intl() override = default; +}; + +}