mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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/
This commit is contained in:
parent
7d8c182359
commit
a37dcf8ca7
Notes:
sideshowbarker
2024-07-18 07:12:42 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/a37dcf8ca75 Pull-request: https://github.com/SerenityOS/serenity/pull/9289
5 changed files with 49 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace JS {
|
|||
P(EPSILON) \
|
||||
P(Function) \
|
||||
P(Infinity) \
|
||||
P(Intl) \
|
||||
P(JSON) \
|
||||
P(LN10) \
|
||||
P(LN2) \
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <LibJS/Runtime/GeneratorObjectPrototype.h>
|
||||
#include <LibJS/Runtime/GlobalEnvironment.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/Intl.h>
|
||||
#include <LibJS/Runtime/IteratorPrototype.h>
|
||||
#include <LibJS/Runtime/JSONObject.h>
|
||||
#include <LibJS/Runtime/MapConstructor.h>
|
||||
|
@ -203,6 +204,7 @@ void GlobalObject::initialize_global_object()
|
|||
define_direct_property(vm.names.Math, heap().allocate<MathObject>(*this, *this), attr);
|
||||
define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(*this, *this), attr);
|
||||
define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, *this), attr);
|
||||
define_direct_property(vm.names.Intl, heap().allocate<Intl::Intl>(*this, *this), attr);
|
||||
define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(*this, *this), attr);
|
||||
|
||||
// This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype.
|
||||
|
|
23
Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp
Normal file
23
Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp
Normal file
|
@ -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/Intl/Intl.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
22
Userland/Libraries/LibJS/Runtime/Intl/Intl.h
Normal file
22
Userland/Libraries/LibJS/Runtime/Intl/Intl.h
Normal file
|
@ -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::Intl {
|
||||
|
||||
class Intl final : public Object {
|
||||
JS_OBJECT(Intl, Object);
|
||||
|
||||
public:
|
||||
explicit Intl(GlobalObject&);
|
||||
virtual void initialize(GlobalObject&) override;
|
||||
virtual ~Intl() override = default;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue