mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:27:35 +00:00
LibJS: Start implementing Intl Segments objects
This commit is contained in:
parent
891dfd9cbb
commit
bbacea255f
8 changed files with 136 additions and 0 deletions
38
Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
Normal file
38
Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/Segments.h>
|
||||
#include <LibJS/Runtime/Intl/SegmentsPrototype.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
// 18.5.1 CreateSegmentsObject ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject
|
||||
Segments* Segments::create(GlobalObject& global_object, Segmenter& segmenter, String string)
|
||||
{
|
||||
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
|
||||
// 2. Let segments be ! OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
|
||||
// 3. Set segments.[[SegmentsSegmenter]] to segmenter.
|
||||
// 4. Set segments.[[SegmentsString]] to string.
|
||||
// 5. Return segments.
|
||||
return global_object.heap().allocate<Segments>(global_object, global_object, segmenter, move(string));
|
||||
}
|
||||
|
||||
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
|
||||
Segments::Segments(GlobalObject& global_object, Segmenter& segmenter, String string)
|
||||
: Object(*global_object.intl_segments_prototype())
|
||||
, m_segments_segmenter(segmenter)
|
||||
, m_segments_string(move(string))
|
||||
{
|
||||
}
|
||||
|
||||
void Segments::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(&m_segments_segmenter);
|
||||
}
|
||||
|
||||
}
|
35
Userland/Libraries/LibJS/Runtime/Intl/Segments.h
Normal file
35
Userland/Libraries/LibJS/Runtime/Intl/Segments.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/Runtime/Intl/Segmenter.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
class Segments final : public Object {
|
||||
JS_OBJECT(Segments, Object);
|
||||
|
||||
public:
|
||||
static Segments* create(GlobalObject&, Segmenter&, String);
|
||||
|
||||
Segments(GlobalObject&, Segmenter&, String);
|
||||
virtual ~Segments() override = default;
|
||||
|
||||
Segmenter& segments_segmenter() const { return m_segments_segmenter; }
|
||||
|
||||
String const& segments_string() const { return m_segments_string; }
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Segmenter& m_segments_segmenter; // [[SegmentsSegmenter]]
|
||||
String m_segments_string; // [[SegmentsString]]
|
||||
};
|
||||
|
||||
}
|
24
Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp
Normal file
24
Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/Segments.h>
|
||||
#include <LibJS/Runtime/Intl/SegmentsPrototype.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
// 18.5.2 The %SegmentsPrototype% Object, https://tc39.es/ecma402/#sec-%segmentsprototype%-object
|
||||
SegmentsPrototype::SegmentsPrototype(GlobalObject& global_object)
|
||||
: PrototypeObject(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
void SegmentsPrototype::initialize(GlobalObject& global_object)
|
||||
{
|
||||
Object::initialize(global_object);
|
||||
}
|
||||
|
||||
}
|
23
Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.h
Normal file
23
Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Intl/Segments.h>
|
||||
#include <LibJS/Runtime/PrototypeObject.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
class SegmentsPrototype final : public PrototypeObject<SegmentsPrototype, Segments> {
|
||||
JS_PROTOTYPE_OBJECT(SegmentsPrototype, Segments, Segments);
|
||||
|
||||
public:
|
||||
explicit SegmentsPrototype(GlobalObject&);
|
||||
virtual void initialize(GlobalObject&) override;
|
||||
virtual ~SegmentsPrototype() override = default;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue