V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
embedder-data-slot-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_EMBEDDER_DATA_SLOT_INL_H_
6 #define V8_OBJECTS_EMBEDDER_DATA_SLOT_INL_H_
7 
8 #include "src/heap/heap-write-barrier-inl.h"
9 #include "src/objects/embedder-data-array.h"
10 #include "src/objects/embedder-data-slot.h"
11 #include "src/objects/js-objects.h"
12 
13 // Has to be the last include (doesn't have include guards):
14 #include "src/objects/object-macros.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 EmbedderDataSlot::EmbedderDataSlot(EmbedderDataArray array, int entry_index)
20  : SlotBase(FIELD_ADDR(array,
21  EmbedderDataArray::OffsetOfElementAt(entry_index))) {}
22 
23 EmbedderDataSlot::EmbedderDataSlot(JSObject* object, int embedder_field_index)
24  : SlotBase(FIELD_ADDR(
25  object, object->GetEmbedderFieldOffset(embedder_field_index))) {}
26 
27 Object* EmbedderDataSlot::load_tagged() const {
28  return ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Load();
29 }
30 
31 void EmbedderDataSlot::store_smi(Smi value) {
32  ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Store(value);
33 }
34 
35 // static
36 void EmbedderDataSlot::store_tagged(EmbedderDataArray array, int entry_index,
37  Object* value) {
38  int slot_offset = EmbedderDataArray::OffsetOfElementAt(entry_index);
39  ObjectSlot(FIELD_ADDR(array, slot_offset + kTaggedPayloadOffset))
40  .Relaxed_Store(ObjectPtr(value->ptr()));
41  WRITE_BARRIER(array, slot_offset, value);
42 }
43 
44 // static
45 void EmbedderDataSlot::store_tagged(JSObject* object, int embedder_field_index,
46  Object* value) {
47  int slot_offset = object->GetEmbedderFieldOffset(embedder_field_index);
48  ObjectSlot(FIELD_ADDR(object, slot_offset + kTaggedPayloadOffset))
49  .Relaxed_Store(ObjectPtr(value->ptr()));
50  WRITE_BARRIER(object, slot_offset, value);
51 }
52 
53 bool EmbedderDataSlot::ToAlignedPointer(void** out_pointer) const {
54  Object* tagged_value =
55  ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Load();
56  if (!tagged_value->IsSmi()) return false;
57  *out_pointer = reinterpret_cast<void*>(tagged_value);
58  return true;
59 }
60 
61 bool EmbedderDataSlot::store_aligned_pointer(void* ptr) {
62  Address value = reinterpret_cast<Address>(ptr);
63  if (!HAS_SMI_TAG(value)) return false;
64  ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Store(Smi(value));
65  return true;
66 }
67 
68 EmbedderDataSlot::RawData EmbedderDataSlot::load_raw(
69  const DisallowHeapAllocation& no_gc) const {
70  return RawData{
71  ObjectSlot(address() + kTaggedPayloadOffset).Relaxed_Load()->ptr(),
72  };
73 }
74 
75 void EmbedderDataSlot::store_raw(const EmbedderDataSlot::RawData& data,
76  const DisallowHeapAllocation& no_gc) {
77  ObjectSlot(address() + kTaggedPayloadOffset)
78  .Relaxed_Store(ObjectPtr(data.data_[0]));
79 }
80 
81 } // namespace internal
82 } // namespace v8
83 
84 #include "src/objects/object-macros-undef.h"
85 
86 #endif // V8_OBJECTS_EMBEDDER_DATA_SLOT_INL_H_
Definition: libplatform.h:13