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_SEGMENT_ITERATOR_H_
5#define V8_OBJECTS_JS_SEGMENT_ITERATOR_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
22namespace U_ICU_NAMESPACE {
23class BreakIterator;
24class UnicodeString;
25}  // namespace U_ICU_NAMESPACE
26
27namespace v8 {
28namespace internal {
29
30#include "torque-generated/src/objects/js-segment-iterator-tq.inc"
31
32class JSSegmentIterator
33    : public TorqueGeneratedJSSegmentIterator<JSSegmentIterator, JSObject> {
34 public:
35  // ecma402 #sec-CreateSegmentIterator
36  V8_WARN_UNUSED_RESULT static MaybeHandle<JSSegmentIterator> Create(
37      Isolate* isolate, icu::BreakIterator* icu_break_iterator,
38      JSSegmenter::Granularity granularity);
39
40  // ecma402 #sec-segment-iterator-prototype-next
41  V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> Next(
42      Isolate* isolate, Handle<JSSegmentIterator> segment_iterator_holder);
43
44  Handle<String> GranularityAsString(Isolate* isolate) const;
45
46  // SegmentIterator accessors.
47  DECL_ACCESSORS(icu_break_iterator, Managed<icu::BreakIterator>)
48  DECL_ACCESSORS(unicode_string, Managed<icu::UnicodeString>)
49
50  DECL_PRINTER(JSSegmentIterator)
51
52  inline void set_granularity(JSSegmenter::Granularity granularity);
53  inline JSSegmenter::Granularity granularity() const;
54
55  // Bit positions in |flags|.
56  DEFINE_TORQUE_GENERATED_JS_SEGMENT_ITERATOR_FLAGS()
57
58  STATIC_ASSERT(JSSegmenter::Granularity::GRAPHEME <= GranularityBits::kMax);
59  STATIC_ASSERT(JSSegmenter::Granularity::WORD <= GranularityBits::kMax);
60  STATIC_ASSERT(JSSegmenter::Granularity::SENTENCE <= GranularityBits::kMax);
61
62  TQ_OBJECT_CONSTRUCTORS(JSSegmentIterator)
63};
64
65}  // namespace internal
66}  // namespace v8
67
68#include "src/objects/object-macros-undef.h"
69
70#endif  // V8_OBJECTS_JS_SEGMENT_ITERATOR_H_
71