V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
property-array-inl.h
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_PROPERTY_ARRAY_INL_H_
6 #define V8_OBJECTS_PROPERTY_ARRAY_INL_H_
7 
8 #include "src/objects/property-array.h"
9 
10 #include "src/heap/heap-write-barrier-inl.h"
11 #include "src/objects/heap-object-inl.h"
12 #include "src/objects/smi-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 
20 OBJECT_CONSTRUCTORS_IMPL(PropertyArray, HeapObjectPtr)
21 CAST_ACCESSOR2(PropertyArray)
22 
23 Object* PropertyArray::get(int index) const {
24  DCHECK_GE(index, 0);
25  DCHECK_LE(index, this->length());
26  return RELAXED_READ_FIELD(this, kHeaderSize + index * kPointerSize);
27 }
28 
29 void PropertyArray::set(int index, Object* value) {
30  DCHECK(IsPropertyArray());
31  DCHECK_GE(index, 0);
32  DCHECK_LT(index, this->length());
33  int offset = kHeaderSize + index * kPointerSize;
34  RELAXED_WRITE_FIELD(this, offset, value);
35  WRITE_BARRIER(this, offset, value);
36 }
37 
38 void PropertyArray::set(int index, Object* value, WriteBarrierMode mode) {
39  DCHECK_GE(index, 0);
40  DCHECK_LT(index, this->length());
41  int offset = kHeaderSize + index * kPointerSize;
42  RELAXED_WRITE_FIELD(this, offset, value);
43  CONDITIONAL_WRITE_BARRIER(this, offset, value, mode);
44 }
45 
46 ObjectSlot PropertyArray::data_start() { return RawField(kHeaderSize); }
47 
48 int PropertyArray::length() const {
49  Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
50  int value = Smi::ToInt(value_obj);
51  return LengthField::decode(value);
52 }
53 
54 void PropertyArray::initialize_length(int len) {
55  SLOW_DCHECK(len >= 0);
56  SLOW_DCHECK(len < LengthField::kMax);
57  WRITE_FIELD(this, kLengthAndHashOffset, Smi::FromInt(len));
58 }
59 
60 int PropertyArray::synchronized_length() const {
61  Object* value_obj = ACQUIRE_READ_FIELD(this, kLengthAndHashOffset);
62  int value = Smi::ToInt(value_obj);
63  return LengthField::decode(value);
64 }
65 
66 int PropertyArray::Hash() const {
67  Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
68  int value = Smi::ToInt(value_obj);
69  return HashField::decode(value);
70 }
71 
72 void PropertyArray::SetHash(int hash) {
73  Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
74  int value = Smi::ToInt(value_obj);
75  value = HashField::update(value, hash);
76  WRITE_FIELD(this, kLengthAndHashOffset, Smi::FromInt(value));
77 }
78 
79 } // namespace internal
80 } // namespace v8
81 
82 #include "src/objects/object-macros-undef.h"
83 
84 #endif // V8_OBJECTS_PROPERTY_ARRAY_INL_H_
Definition: libplatform.h:13