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/objects/foreign.h"
10
11 #include "src/common/external-pointer-inl.h"
12 #include "src/heap/heap-write-barrier-inl.h"
13 #include "src/objects/objects-inl.h"
14
15 // Has to be the last include (doesn't have include guards):
16 #include "src/objects/object-macros.h"
17
18 namespace v8 {
19 namespace internal {
20
21 #include "torque-generated/src/objects/foreign-tq-inl.inc"
22
TQ_OBJECT_CONSTRUCTORS_IMPL(Foreign)23 TQ_OBJECT_CONSTRUCTORS_IMPL(Foreign)
24
25 // static
26 bool Foreign::IsNormalized(Object value) {
27 if (value == Smi::zero()) return true;
28 return Foreign::cast(value).foreign_address() != kNullAddress;
29 }
30
DEF_GETTER(Foreign,foreign_address,Address)31 DEF_GETTER(Foreign, foreign_address, Address) {
32 return ReadExternalPointerField(kForeignAddressOffset, isolate,
33 kForeignForeignAddressTag);
34 }
35
AllocateExternalPointerEntries(Isolate * isolate)36 void Foreign::AllocateExternalPointerEntries(Isolate* isolate) {
37 InitExternalPointerField(kForeignAddressOffset, isolate);
38 }
39
set_foreign_address(Isolate * isolate,Address value)40 void Foreign::set_foreign_address(Isolate* isolate, Address value) {
41 WriteExternalPointerField(kForeignAddressOffset, isolate, value,
42 kForeignForeignAddressTag);
43 }
44
45 } // namespace internal
46 } // namespace v8
47
48 #include "src/objects/object-macros-undef.h"
49
50 #endif // V8_OBJECTS_FOREIGN_INL_H_
51