V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-segment-iterator.h
1 // Copyright 2018 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 
5 #ifndef V8_INTL_SUPPORT
6 #error Internationalization is expected to be enabled.
7 #endif // V8_INTL_SUPPORT
8 
9 #ifndef V8_OBJECTS_JS_SEGMENT_ITERATOR_H_
10 #define V8_OBJECTS_JS_SEGMENT_ITERATOR_H_
11 
12 #include "src/heap/factory.h"
13 #include "src/isolate.h"
14 #include "src/objects.h"
15 #include "src/objects/js-segmenter.h"
16 #include "src/objects/managed.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 class JSSegmentIterator : public JSObject {
31  public:
32  // ecma402 #sec-CreateSegmentIterator
33  V8_WARN_UNUSED_RESULT static MaybeHandle<JSSegmentIterator> Create(
34  Isolate* isolate, icu::BreakIterator* icu_break_iterator,
35  JSSegmenter::Granularity granularity, Handle<String> string);
36 
37  // ecma402 #sec-segment-iterator-prototype-next
38  V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> Next(
39  Isolate* isolate, Handle<JSSegmentIterator> segment_iterator_holder);
40 
41  // ecma402 #sec-segment-iterator-prototype-following
42  static Maybe<bool> Following(
43  Isolate* isolate, Handle<JSSegmentIterator> segment_iterator_holder,
44  Handle<Object> from);
45 
46  // ecma402 #sec-segment-iterator-prototype-preceding
47  static Maybe<bool> Preceding(
48  Isolate* isolate, Handle<JSSegmentIterator> segment_iterator_holder,
49  Handle<Object> from);
50 
51  // ecma402 #sec-segment-iterator-prototype-position
52  static Handle<Object> Position(
53  Isolate* isolate, Handle<JSSegmentIterator> segment_iterator_holder);
54 
55  Handle<String> GranularityAsString() const;
56 
57  // ecma402 #sec-segment-iterator-prototype-breakType
58  Handle<Object> BreakType() const;
59 
60  V8_WARN_UNUSED_RESULT MaybeHandle<String> GetSegment(Isolate* isolate,
61  int32_t start,
62  int32_t end) const;
63 
64  DECL_CAST(JSSegmentIterator)
65 
66  // SegmentIterator accessors.
67  DECL_ACCESSORS(icu_break_iterator, Managed<icu::BreakIterator>)
68  DECL_ACCESSORS(unicode_string, Managed<icu::UnicodeString>)
69 
70  DECL_PRINTER(JSSegmentIterator)
71  DECL_VERIFIER(JSSegmentIterator)
72 
73  inline void set_granularity(JSSegmenter::Granularity granularity);
74  inline JSSegmenter::Granularity granularity() const;
75 
76 // Bit positions in |flags|.
77 #define FLAGS_BIT_FIELDS(V, _) \
78  V(GranularityBits, JSSegmenter::Granularity, 3, _)
79  DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
80 #undef FLAGS_BIT_FIELDS
81 
82  STATIC_ASSERT(JSSegmenter::Granularity::GRAPHEME <= GranularityBits::kMax);
83  STATIC_ASSERT(JSSegmenter::Granularity::WORD <= GranularityBits::kMax);
84  STATIC_ASSERT(JSSegmenter::Granularity::SENTENCE <= GranularityBits::kMax);
85  STATIC_ASSERT(JSSegmenter::Granularity::LINE <= GranularityBits::kMax);
86 
87  // [flags] Bit field containing various flags about the function.
88  DECL_INT_ACCESSORS(flags)
89 
90 // Layout description.
91 #define SEGMENTER_FIELDS(V) \
92  /* Pointer fields. */ \
93  V(kICUBreakIteratorOffset, kTaggedSize) \
94  V(kUnicodeStringOffset, kTaggedSize) \
95  V(kFlagsOffset, kTaggedSize) \
96  /* Total Size */ \
97  V(kSize, 0)
98 
99  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, SEGMENTER_FIELDS)
100 #undef SEGMENTER_FIELDS
101 
102  private:
103  DISALLOW_IMPLICIT_CONSTRUCTORS(JSSegmentIterator);
104 };
105 
106 } // namespace internal
107 } // namespace v8
108 
109 #include "src/objects/object-macros-undef.h"
110 
111 #endif // V8_OBJECTS_JS_SEGMENT_ITERATOR_H_
Definition: v8.h:56
Definition: libplatform.h:13