• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COLLATOR_H_
10 #define V8_OBJECTS_JS_COLLATOR_H_
11 
12 #include "src/heap/factory.h"
13 #include "src/isolate.h"
14 #include "src/objects.h"
15 #include "src/objects/intl-objects.h"
16 #include "src/objects/managed.h"
17 
18 // Has to be the last include (doesn't have include guards):
19 #include "src/objects/object-macros.h"
20 
21 namespace v8 {
22 namespace internal {
23 
24 class JSCollator : public JSObject {
25  public:
26   // ecma402/#sec-initializecollator
27   V8_WARN_UNUSED_RESULT static MaybeHandle<JSCollator> InitializeCollator(
28       Isolate* isolate, Handle<JSCollator> collator, Handle<Object> locales,
29       Handle<Object> options);
30 
31   // ecma402/#sec-intl.collator.prototype.resolvedoptions
32   static Handle<JSObject> ResolvedOptions(Isolate* isolate,
33                                           Handle<JSCollator> collator);
34 
35   DECL_CAST(JSCollator)
36   DECL_PRINTER(JSCollator)
37   DECL_VERIFIER(JSCollator)
38 
39   // [[Usage]] is one of the values "sort" or "search", identifying
40   // the collator usage.
41   enum class Usage {
42     SORT,
43     SEARCH,
44 
45     COUNT
46   };
47   inline void set_usage(Usage usage);
48   inline Usage usage() const;
49   static const char* UsageToString(Usage usage);
50 
51 // Layout description.
52 #define JS_COLLATOR_FIELDS(V)          \
53   V(kICUCollatorOffset, kPointerSize)  \
54   V(kFlagsOffset, kPointerSize)        \
55   V(kBoundCompareOffset, kPointerSize) \
56   /* Total size. */                    \
57   V(kSize, 0)
58 
59   DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, JS_COLLATOR_FIELDS)
60 #undef JS_COLLATOR_FIELDS
61 
62   // ContextSlot defines the context structure for the bound
63   // Collator.prototype.compare function.
64   enum ContextSlot {
65     // The collator instance that the function holding this context is bound to.
66     kCollator = Context::MIN_CONTEXT_SLOTS,
67     kLength
68   };
69 
70 // Bit positions in |flags|.
71 #define FLAGS_BIT_FIELDS(V, _) V(UsageBits, Usage, 1, _)
72 
73   DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
74 #undef FLAGS_BIT_FIELDS
75 
76   STATIC_ASSERT(Usage::SORT <= UsageBits::kMax);
77   STATIC_ASSERT(Usage::SEARCH <= UsageBits::kMax);
78 
79   DECL_ACCESSORS(icu_collator, Managed<icu::Collator>)
80   DECL_ACCESSORS(bound_compare, Object);
81   DECL_INT_ACCESSORS(flags)
82 
83  private:
84   DISALLOW_IMPLICIT_CONSTRUCTORS(JSCollator);
85 };
86 
87 }  // namespace internal
88 }  // namespace v8
89 
90 #include "src/objects/object-macros-undef.h"
91 
92 #endif  // V8_OBJECTS_JS_COLLATOR_H_
93