• 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_INL_H_
6 #define V8_OBJECTS_ODDBALL_INL_H_
7 
8 #include "src/objects/oddball.h"
9 
10 #include "src/handles/handles.h"
11 #include "src/heap/heap-write-barrier-inl.h"
12 #include "src/objects/objects-inl.h"
13 
14 // Has to be the last include (doesn't have include guards):
15 #include "src/objects/object-macros.h"
16 
17 namespace v8 {
18 namespace internal {
19 
TQ_CPP_OBJECT_DEFINITION_ASSERTS(Oddball,PrimitiveHeapObject)20 TQ_CPP_OBJECT_DEFINITION_ASSERTS(Oddball, PrimitiveHeapObject)
21 
22 OBJECT_CONSTRUCTORS_IMPL(Oddball, PrimitiveHeapObject)
23 
24 CAST_ACCESSOR(Oddball)
25 
26 DEF_PRIMITIVE_ACCESSORS(Oddball, to_number_raw, kToNumberRawOffset, double)
27 
28 void Oddball::set_to_number_raw_as_bits(uint64_t bits) {
29   // Bug(v8:8875): HeapNumber's double may be unaligned.
30   base::WriteUnalignedValue<uint64_t>(field_address(kToNumberRawOffset), bits);
31 }
32 
ACCESSORS(Oddball,to_string,String,kToStringOffset)33 ACCESSORS(Oddball, to_string, String, kToStringOffset)
34 ACCESSORS(Oddball, to_number, Object, kToNumberOffset)
35 ACCESSORS(Oddball, type_of, String, kTypeOfOffset)
36 
37 byte Oddball::kind() const {
38   return Smi::ToInt(TaggedField<Smi>::load(*this, kKindOffset));
39 }
40 
set_kind(byte value)41 void Oddball::set_kind(byte value) {
42   WRITE_FIELD(*this, kKindOffset, Smi::FromInt(value));
43 }
44 
45 // static
ToNumber(Isolate * isolate,Handle<Oddball> input)46 Handle<Object> Oddball::ToNumber(Isolate* isolate, Handle<Oddball> input) {
47   return Handle<Object>(input->to_number(), isolate);
48 }
49 
DEF_GETTER(HeapObject,IsBoolean,bool)50 DEF_GETTER(HeapObject, IsBoolean, bool) {
51   return IsOddball(cage_base) &&
52          ((Oddball::cast(*this).kind() & Oddball::kNotBooleanMask) == 0);
53 }
54 
ToBool(Isolate * isolate)55 bool Oddball::ToBool(Isolate* isolate) const {
56   DCHECK(IsBoolean(isolate));
57   return IsTrue(isolate);
58 }
59 
60 }  // namespace internal
61 }  // namespace v8
62 
63 #include "src/objects/object-macros-undef.h"
64 
65 #endif  // V8_OBJECTS_ODDBALL_INL_H_
66