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   Isolate* isolate = GetIsolateForHeapSandbox(*this);
33   return ReadExternalPointerField(kForeignAddressOffset, isolate,
34                                   kForeignForeignAddressTag);
35 }
36 
AllocateExternalPointerEntries(Isolate * isolate)37 void Foreign::AllocateExternalPointerEntries(Isolate* isolate) {
38   InitExternalPointerField(kForeignAddressOffset, isolate);
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