mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS: Convert Intl.Segmenter, Segments and SegmentIterator to Utf16
This is a precursor to implementing the FindBoundary AO, which operates on Utf16 code unit indexes.
This commit is contained in:
parent
4967bcd4ce
commit
b1d19b5917
Notes:
sideshowbarker
2024-07-17 19:54:57 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/b1d19b5917e Pull-request: https://github.com/SerenityOS/serenity/pull/12229 Reviewed-by: https://github.com/trflynn89 ✅
6 changed files with 17 additions and 16 deletions
|
@ -10,7 +10,7 @@
|
|||
namespace JS::Intl {
|
||||
|
||||
// 18.6.1 CreateSegmentIterator ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject
|
||||
SegmentIterator* SegmentIterator::create(GlobalObject& global_object, Segmenter& segmenter, String string)
|
||||
SegmentIterator* SegmentIterator::create(GlobalObject& global_object, Segmenter& segmenter, Utf16View const& string)
|
||||
{
|
||||
// 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ».
|
||||
// 2. Let iterator be ! OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
|
||||
|
@ -22,10 +22,10 @@ SegmentIterator* SegmentIterator::create(GlobalObject& global_object, Segmenter&
|
|||
}
|
||||
|
||||
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
|
||||
SegmentIterator::SegmentIterator(GlobalObject& global_object, Segmenter& segmenter, String string)
|
||||
SegmentIterator::SegmentIterator(GlobalObject& global_object, Segmenter& segmenter, Utf16View const& string)
|
||||
: Object(*global_object.intl_segment_iterator_prototype())
|
||||
, m_iterating_segmenter(segmenter)
|
||||
, m_iterated_string(move(string))
|
||||
, m_iterated_string(string)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Utf16View.h>
|
||||
#include <LibJS/Runtime/Intl/Segmenter.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
|
@ -15,20 +16,20 @@ class SegmentIterator final : public Object {
|
|||
JS_OBJECT(SegmentIterator, Object);
|
||||
|
||||
public:
|
||||
static SegmentIterator* create(GlobalObject&, Segmenter&, String);
|
||||
static SegmentIterator* create(GlobalObject&, Segmenter&, Utf16View const&);
|
||||
|
||||
SegmentIterator(GlobalObject&, Segmenter&, String);
|
||||
SegmentIterator(GlobalObject&, Segmenter&, Utf16View const&);
|
||||
virtual ~SegmentIterator() override = default;
|
||||
|
||||
Segmenter const& iterating_segmenter() const { return m_iterating_segmenter; }
|
||||
String const& iterated_string() const { return m_iterated_string; }
|
||||
Utf16View const& iterated_string() const { return m_iterated_string; }
|
||||
size_t iterated_string_next_segment_code_unit_index() const { return m_iterated_string_next_segment_code_unit_index; }
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Segmenter& m_iterating_segmenter; // [[IteratingSegmenter]]
|
||||
String m_iterated_string; // [[IteratedString]]
|
||||
Utf16View m_iterated_string; // [[IteratedString]]
|
||||
size_t m_iterated_string_next_segment_code_unit_index { 0 }; // [[IteratedStringNextSegmentCodeUnitIndex]]
|
||||
};
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
|
|||
auto* segmenter = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let string be ? ToString(string).
|
||||
auto string = TRY(vm.argument(0).to_string(global_object));
|
||||
auto string = TRY(vm.argument(0).to_utf16_string(global_object));
|
||||
|
||||
// 4. Return ! CreateSegmentsObject(segmenter, string).
|
||||
return Segments::create(global_object, *segmenter, move(string));
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
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)
|
||||
Segments* Segments::create(GlobalObject& global_object, Segmenter& segmenter, Utf16String string)
|
||||
{
|
||||
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
|
||||
// 2. Let segments be ! OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
|
||||
|
@ -22,7 +22,7 @@ Segments* Segments::create(GlobalObject& global_object, Segmenter& segmenter, St
|
|||
}
|
||||
|
||||
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
|
||||
Segments::Segments(GlobalObject& global_object, Segmenter& segmenter, String string)
|
||||
Segments::Segments(GlobalObject& global_object, Segmenter& segmenter, Utf16String string)
|
||||
: Object(*global_object.intl_segments_prototype())
|
||||
, m_segments_segmenter(segmenter)
|
||||
, m_segments_string(move(string))
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Utf16View.h>
|
||||
#include <LibJS/Runtime/Intl/Segmenter.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
|
@ -16,20 +16,20 @@ class Segments final : public Object {
|
|||
JS_OBJECT(Segments, Object);
|
||||
|
||||
public:
|
||||
static Segments* create(GlobalObject&, Segmenter&, String);
|
||||
static Segments* create(GlobalObject&, Segmenter&, Utf16String);
|
||||
|
||||
Segments(GlobalObject&, Segmenter&, String);
|
||||
Segments(GlobalObject&, Segmenter&, Utf16String);
|
||||
virtual ~Segments() override = default;
|
||||
|
||||
Segmenter& segments_segmenter() const { return m_segments_segmenter; }
|
||||
|
||||
String const& segments_string() const { return m_segments_string; }
|
||||
Utf16View segments_string() const { return m_segments_string.view(); }
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Segmenter& m_segments_segmenter; // [[SegmentsSegmenter]]
|
||||
String m_segments_string; // [[SegmentsString]]
|
||||
Utf16String m_segments_string; // [[SegmentsString]]
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
|
|||
auto& segmenter = segments->segments_segmenter();
|
||||
|
||||
// 4. Let string be segments.[[SegmentsString]].
|
||||
auto& string = segments->segments_string();
|
||||
auto string = segments->segments_string();
|
||||
|
||||
// 5. Return ! CreateSegmentIterator(segmenter, string).
|
||||
return SegmentIterator::create(global_object, segmenter, string);
|
||||
|
|
Loading…
Reference in a new issue