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_H_ 6 #define V8_OBJECTS_FOREIGN_H_ 7 8 #include "src/objects/heap-object.h" 9 10 // Has to be the last include (doesn't have include guards): 11 #include "src/objects/object-macros.h" 12 13 namespace v8 { 14 namespace internal { 15 16 #include "torque-generated/src/objects/foreign-tq.inc" 17 18 // Foreign describes objects pointing from JavaScript to C structures. 19 class Foreign : public TorqueGeneratedForeign<Foreign, HeapObject> { 20 public: 21 // [address]: field containing the address. 22 DECL_GETTER(foreign_address, Address) 23 24 static inline bool IsNormalized(Object object); 25 26 // Dispatched behavior. 27 DECL_PRINTER(Foreign) 28 29 #ifdef V8_COMPRESS_POINTERS 30 // TODO(ishell, v8:8875): When pointer compression is enabled the 31 // kForeignAddressOffset is only kTaggedSize aligned but we can keep using 32 // unaligned access since both x64 and arm64 architectures (where pointer 33 // compression is supported) allow unaligned access to full words. 34 STATIC_ASSERT(IsAligned(kForeignAddressOffset, kTaggedSize)); 35 #else 36 STATIC_ASSERT(IsAligned(kForeignAddressOffset, kExternalPointerSize)); 37 #endif 38 39 class BodyDescriptor; 40 41 private: 42 friend class Factory; 43 friend class SerializerDeserializer; 44 friend class StartupSerializer; 45 friend class WasmTypeInfo; 46 47 inline void AllocateExternalPointerEntries(Isolate* isolate); 48 49 inline void set_foreign_address(Isolate* isolate, Address value); 50 51 TQ_OBJECT_CONSTRUCTORS(Foreign) 52 }; 53 54 } // namespace internal 55 } // namespace v8 56 57 #include "src/objects/object-macros-undef.h" 58 59 #endif // V8_OBJECTS_FOREIGN_H_ 60