• 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_OBJECTS_ODDBALL_H_
6 #define V8_OBJECTS_ODDBALL_H_
7 
8 #include "src/objects/primitive-heap-object.h"
9 
10 // Has to be the last include (doesn't have include guards):
11 #include "src/objects/object-macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 #include "torque-generated/src/objects/oddball-tq.inc"
17 
18 // The Oddball describes objects null, undefined, true, and false.
19 class Oddball : public PrimitiveHeapObject {
20  public:
21   // [to_number_raw]: Cached raw to_number computed at startup.
22   DECL_PRIMITIVE_ACCESSORS(to_number_raw, double)
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   V8_INLINE bool ToBool(Isolate* isolate) const;
42 
43   DECL_CAST(Oddball)
44 
45   // Dispatched behavior.
46   DECL_VERIFIER(Oddball)
47 
48   // Initialize the fields.
49   static void Initialize(Isolate* isolate, Handle<Oddball> oddball,
50                          const char* to_string, Handle<Object> to_number,
51                          const char* type_of, byte kind);
52 
53   // Layout description.
54   DECL_FIELD_OFFSET_TQ(ToNumberRaw, HeapObject::kHeaderSize, "float64")
55   DECL_FIELD_OFFSET_TQ(ToString, kToNumberRawOffset + kDoubleSize, "String")
56   DECL_FIELD_OFFSET_TQ(ToNumber, kToStringOffset + kTaggedSize, "Number")
57   DECL_FIELD_OFFSET_TQ(TypeOf, kToNumberOffset + kTaggedSize, "String")
58   DECL_FIELD_OFFSET_TQ(Kind, kTypeOfOffset + kTaggedSize, "Smi")
59   static const int kSize = kKindOffset + kTaggedSize;
60 
61   static const byte kFalse = 0;
62   static const byte kTrue = 1;
63   static const byte kNotBooleanMask = static_cast<byte>(~1);
64   static const byte kTheHole = 2;
65   static const byte kNull = 3;
66   static const byte kArgumentsMarker = 4;
67   static const byte kUndefined = 5;
68   static const byte kUninitialized = 6;
69   static const byte kOther = 7;
70   static const byte kException = 8;
71   static const byte kOptimizedOut = 9;
72   static const byte kStaleRegister = 10;
73   static const byte kSelfReferenceMarker = 10;
74   static const byte kBasicBlockCountersMarker = 11;
75 
76   using BodyDescriptor =
77       FixedBodyDescriptor<kToStringOffset, kKindOffset, kSize>;
78 
79   STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset);
80   STATIC_ASSERT(kNull == Internals::kNullOddballKind);
81   STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind);
82 
83   DECL_PRINTER(Oddball)
84 
85   OBJECT_CONSTRUCTORS(Oddball, PrimitiveHeapObject);
86 };
87 
88 }  // namespace internal
89 }  // namespace v8
90 
91 #include "src/objects/object-macros-undef.h"
92 
93 #endif  // V8_OBJECTS_ODDBALL_H_
94