1 // Copyright 2020 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #ifndef V8_OBJECTS_JS_SEGMENTS_H_
5 #define V8_OBJECTS_JS_SEGMENTS_H_
6 
7 #ifndef V8_INTL_SUPPORT
8 #error Internationalization is expected to be enabled.
9 #endif  // V8_INTL_SUPPORT
10 
11 #include "src/base/bit-field.h"
12 #include "src/execution/isolate.h"
13 #include "src/heap/factory.h"
14 #include "src/objects/js-segmenter.h"
15 #include "src/objects/managed.h"
16 #include "src/objects/objects.h"
17 #include "unicode/uversion.h"
18 
19 // Has to be the last include (doesn't have include guards):
20 #include "src/objects/object-macros.h"
21 
22 namespace U_ICU_NAMESPACE {
23 class BreakIterator;
24 class UnicodeString;
25 }  // namespace U_ICU_NAMESPACE
26 
27 namespace v8 {
28 namespace internal {
29 
30 #include "torque-generated/src/objects/js-segments-tq.inc"
31 
32 class JSSegments : public TorqueGeneratedJSSegments<JSSegments, JSObject> {
33  public:
34   // ecma402 #sec-createsegmentsobject
35   V8_WARN_UNUSED_RESULT static MaybeHandle<JSSegments> Create(
36       Isolate* isolate, Handle<JSSegmenter> segmenter, Handle<String> string);
37 
38   // ecma402 #sec-%segmentsprototype%.containing
39   V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Containing(
40       Isolate* isolate, Handle<JSSegments> segments_holder, double n);
41 
42   // ecma402 #sec-createsegmentdataobject
43   V8_WARN_UNUSED_RESULT static MaybeHandle<Object> CreateSegmentDataObject(
44       Isolate* isolate, JSSegmenter::Granularity granularity,
45       icu::BreakIterator* break_iterator, const icu::UnicodeString& string,
46       int32_t start_index, int32_t end_index);
47 
48   Handle<String> GranularityAsString(Isolate* isolate) const;
49 
50   // SegmentIterator accessors.
51   DECL_ACCESSORS(icu_break_iterator, Managed<icu::BreakIterator>)
52   DECL_ACCESSORS(unicode_string, Managed<icu::UnicodeString>)
53 
54   DECL_PRINTER(JSSegments)
55 
56   inline void set_granularity(JSSegmenter::Granularity granularity);
57   inline JSSegmenter::Granularity granularity() const;
58 
59   // Bit positions in |flags|.
60   DEFINE_TORQUE_GENERATED_JS_SEGMENT_ITERATOR_FLAGS()
61 
62   STATIC_ASSERT(JSSegmenter::Granularity::GRAPHEME <= GranularityBits::kMax);
63   STATIC_ASSERT(JSSegmenter::Granularity::WORD <= GranularityBits::kMax);
64   STATIC_ASSERT(JSSegmenter::Granularity::SENTENCE <= GranularityBits::kMax);
65 
66   TQ_OBJECT_CONSTRUCTORS(JSSegments)
67 };
68 
69 }  // namespace internal
70 }  // namespace v8
71 
72 #include "src/objects/object-macros-undef.h"
73 
74 #endif  // V8_OBJECTS_JS_SEGMENTS_H_
75