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_FOREIGN_INL_H_
6 #define V8_OBJECTS_FOREIGN_INL_H_
7
8 #include "src/common/globals.h"
9 #include "src/heap/heap-write-barrier-inl.h"
10 #include "src/objects/foreign.h"
11 #include "src/objects/objects-inl.h"
12 #include "src/sandbox/external-pointer-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 #include "torque-generated/src/objects/foreign-tq-inl.inc"
21
TQ_OBJECT_CONSTRUCTORS_IMPL(Foreign)22 TQ_OBJECT_CONSTRUCTORS_IMPL(Foreign)
23
24 // static
25 bool Foreign::IsNormalized(Object value) {
26 if (value == Smi::zero()) return true;
27 return Foreign::cast(value).foreign_address() != kNullAddress;
28 }
29
DEF_GETTER(Foreign,foreign_address,Address)30 DEF_GETTER(Foreign, foreign_address, Address) {
31 Isolate* isolate = GetIsolateForSandbox(*this);
32 return ReadExternalPointerField(kForeignAddressOffset, isolate,
33 kForeignForeignAddressTag);
34 }
35
AllocateExternalPointerEntries(Isolate * isolate)36 void Foreign::AllocateExternalPointerEntries(Isolate* isolate) {
37 InitExternalPointerField(kForeignAddressOffset, isolate,
38 kForeignForeignAddressTag);
39 }
40
set_foreign_address(Isolate * isolate,Address value)41 void Foreign::set_foreign_address(Isolate* isolate, Address value) {
42 WriteExternalPointerField(kForeignAddressOffset, isolate, value,
43 kForeignForeignAddressTag);
44 }
45
46 } // namespace internal
47 } // namespace v8
48
49 #include "src/objects/object-macros-undef.h"
50
51 #endif // V8_OBJECTS_FOREIGN_INL_H_
52