oddball.h 3.09 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_OBJECTS_ODDBALL_H_
#define V8_OBJECTS_ODDBALL_H_

8
#include "src/objects/heap-object.h"
9 10 11 12 13 14 15 16

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

// The Oddball describes objects null, undefined, true, and false.
17
class Oddball : public HeapObject {
18 19 20 21 22 23 24
 public:
  // [to_number_raw]: Cached raw to_number computed at startup.
  inline double to_number_raw() const;
  inline void set_to_number_raw(double value);
  inline void set_to_number_raw_as_bits(uint64_t bits);

  // [to_string]: Cached to_string computed at startup.
25
  DECL_ACCESSORS(to_string, String)
26 27 28 29 30

  // [to_number]: Cached to_number computed at startup.
  DECL_ACCESSORS(to_number, Object)

  // [typeof]: Cached type_of computed at startup.
31
  DECL_ACCESSORS(type_of, String)
32 33 34 35 36 37 38 39

  inline byte kind() const;
  inline void set_kind(byte kind);

  // ES6 section 7.1.3 ToNumber for Boolean, Null, Undefined.
  V8_WARN_UNUSED_RESULT static inline Handle<Object> ToNumber(
      Isolate* isolate, Handle<Oddball> input);

40
  DECL_CAST(Oddball)
41 42 43 44 45 46 47 48 49 50

  // Dispatched behavior.
  DECL_VERIFIER(Oddball)

  // Initialize the fields.
  static void Initialize(Isolate* isolate, Handle<Oddball> oddball,
                         const char* to_string, Handle<Object> to_number,
                         const char* type_of, byte kind);

  // Layout description.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#define ODDBALL_FIELDS(V)                  \
  V(kToNumberRawOffset, kDoubleSize)       \
  /* Tagged fields. */                     \
  V(kTaggedFieldsStartOffset, 0)           \
  V(kToStringOffset, kTaggedSize)          \
  V(kToNumberOffset, kTaggedSize)          \
  V(kTypeOfOffset, kTaggedSize)            \
  V(kTaggedFieldsEndOffset, 0)             \
  /* Raw data but still encoded as Smi. */ \
  V(kKindOffset, kTaggedSize)              \
  /* Total size. */                        \
  V(kSize, 0)

  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, ODDBALL_FIELDS)
#undef ODDBALL_FIELDS
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

  static const byte kFalse = 0;
  static const byte kTrue = 1;
  static const byte kNotBooleanMask = static_cast<byte>(~1);
  static const byte kTheHole = 2;
  static const byte kNull = 3;
  static const byte kArgumentsMarker = 4;
  static const byte kUndefined = 5;
  static const byte kUninitialized = 6;
  static const byte kOther = 7;
  static const byte kException = 8;
  static const byte kOptimizedOut = 9;
  static const byte kStaleRegister = 10;
  static const byte kSelfReferenceMarker = 10;

81
  typedef FixedBodyDescriptor<kTaggedFieldsStartOffset, kTaggedFieldsEndOffset,
82 83 84 85 86 87 88
                              kSize>
      BodyDescriptor;

  STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset);
  STATIC_ASSERT(kNull == Internals::kNullOddballKind);
  STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind);

89
  OBJECT_CONSTRUCTORS(Oddball, HeapObject);
90 91 92 93 94 95 96 97
};

}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_ODDBALL_H_