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_OBJECTS_ODDBALL_H_ |
6 | #define V8_OBJECTS_ODDBALL_H_ |
7 | |
8 | #include "src/objects/heap-object.h" |
9 | #include "torque-generated/class-definitions-from-dsl.h" |
10 | |
11 | // Has to be the last include (doesn't have include guards): |
12 | #include "src/objects/object-macros.h" |
13 | |
14 | namespace v8 { |
15 | namespace internal { |
16 | |
17 | // The Oddball describes objects null, undefined, true, and false. |
18 | class Oddball : public HeapObject { |
19 | public: |
20 | // [to_number_raw]: Cached raw to_number computed at startup. |
21 | inline double to_number_raw() const; |
22 | inline void set_to_number_raw(double value); |
23 | inline void set_to_number_raw_as_bits(uint64_t bits); |
24 | |
25 | // [to_string]: Cached to_string computed at startup. |
26 | DECL_ACCESSORS(to_string, String) |
27 | |
28 | // [to_number]: Cached to_number computed at startup. |
29 | DECL_ACCESSORS(to_number, Object) |
30 | |
31 | // [typeof]: Cached type_of computed at startup. |
32 | DECL_ACCESSORS(type_of, String) |
33 | |
34 | inline byte kind() const; |
35 | inline void set_kind(byte kind); |
36 | |
37 | // ES6 section 7.1.3 ToNumber for Boolean, Null, Undefined. |
38 | V8_WARN_UNUSED_RESULT static inline Handle<Object> ToNumber( |
39 | Isolate* isolate, Handle<Oddball> input); |
40 | |
41 | DECL_CAST(Oddball) |
42 | |
43 | // Dispatched behavior. |
44 | DECL_VERIFIER(Oddball) |
45 | |
46 | // Initialize the fields. |
47 | static void Initialize(Isolate* isolate, Handle<Oddball> oddball, |
48 | const char* to_string, Handle<Object> to_number, |
49 | const char* type_of, byte kind); |
50 | |
51 | DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, |
52 | TORQUE_GENERATED_ODDBALL_FIELDS) |
53 | // TODO(v8:8989): [torque] Support marker constants. |
54 | static const int kTaggedFieldsStartOffset = kToStringOffset; |
55 | static const int kTaggedFieldsEndOffset = kKindOffset; |
56 | |
57 | static const byte kFalse = 0; |
58 | static const byte kTrue = 1; |
59 | static const byte kNotBooleanMask = static_cast<byte>(~1); |
60 | static const byte kTheHole = 2; |
61 | static const byte kNull = 3; |
62 | static const byte kArgumentsMarker = 4; |
63 | static const byte kUndefined = 5; |
64 | static const byte kUninitialized = 6; |
65 | static const byte kOther = 7; |
66 | static const byte kException = 8; |
67 | static const byte kOptimizedOut = 9; |
68 | static const byte kStaleRegister = 10; |
69 | static const byte kSelfReferenceMarker = 10; |
70 | |
71 | using BodyDescriptor = FixedBodyDescriptor<kTaggedFieldsStartOffset, |
72 | kTaggedFieldsEndOffset, kSize>; |
73 | |
74 | STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset); |
75 | STATIC_ASSERT(kNull == Internals::kNullOddballKind); |
76 | STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind); |
77 | |
78 | OBJECT_CONSTRUCTORS(Oddball, HeapObject); |
79 | }; |
80 | |
81 | } // namespace internal |
82 | } // namespace v8 |
83 | |
84 | #include "src/objects/object-macros-undef.h" |
85 | |
86 | #endif // V8_OBJECTS_ODDBALL_H_ |
87 | |