5#ifndef INCLUDE_V8_OBJECT_H_
6#define INCLUDE_V8_OBJECT_H_
8#include "cppgc/garbage-collected.h"
9#include "cppgc/name-provider.h"
29
30
31
32
33
34using EmbedderDataTypeTag = uint16_t;
37
38
39
40
44
45
49
50
55
56
57
58
59
60
61
62
70 static void CheckCast(
Data* that);
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
143 PrivateData* private_;
147
148
161
162
163
164
165using AccessorNameGetterCallback =
168using AccessorNameSetterCallback =
173
174
175
176
177
178
179
181 "This enum is no longer used and will be removed in V8 12.9.")
187
188
199
200
201
202
203
204
205
206
207
215
216
217
218
219
220
224
225
226
230
231
232
236
237
241
242
246
247
248
259
260
261
262
263
264
265
266
267
276
277
278
279
280
281
282
283
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
317
318
319
320
325
326
327
332
333
334
335
336
337
338
339
340
341
342
343
344
345
358
359
360
366
367
368
371 AccessorNameGetterCallback getter,
372 AccessorNameSetterCallback setter =
nullptr,
378
379
380
381
382
383
384
387 AccessorNameGetterCallback getter,
Local<
Value> data = Local<Value>(),
393
394
395
396
397
405
406
407
408
409
418
419
420
421
426
427
428
429
430
436
437
438
439
441 "V8 will stop providing access to hidden prototype (i.e. "
442 "JSGlobalObject). Use GetPrototypeV2() instead. "
443 "See http://crbug.com/333672197.")
447
448
449
450
451
455
456
457
458
460 "V8 will stop providing access to hidden prototype (i.e. "
461 "JSGlobalObject). Use SetPrototypeV2() instead. "
462 "See http://crbug.com/333672197.")
467
468
469
470
471
476
477
478
482
483
484
485
490
491
495
496
505 return object.
template value<
Object>()->InternalFieldCount();
511 return object.
template value<
Object>()->InternalFieldCount();
515
516
517
518
519
520
521
522
523
530
531
532
533
541 return object.
template value<
Object>()->GetAlignedPointerFromInternalField(
548 return object.
template value<
Object>()->GetAlignedPointerFromInternalField(
553
554
555
556
558 "Use SetAlignedPointerInInternalField with EmbedderDataTypeTag parameter "
560 void SetAlignedPointerInInternalField(
int index,
void*
value);
563 EmbedderDataTypeTag tag);
566 "Use SetAlignedPointerInInternalField with EmbedderDataTypeTag "
567 "parameter instead.")
568 void SetAlignedPointerInInternalFields(
int argc,
int indices[],
595
596
597
598
599
600
601
602
603
614 template <
typename T =
void>
618 template <
typename T =
void>
622 template <
typename T =
void>
628
629
630
631
632
633
634
635
672
673
674
675
676
682
683
684
685
686
687
688
689
690
691
692
693
702
703
704
709
710
711
712
718
719
720
721
726
727
728
729
740
741
742
743
744
745
749
750
751
752
753
758
759
760
761
767
768
769
770
778 return object.
template value<
Object>()->GetCreationContext(isolate);
785
786
787
788
789
790
791
792
793
794
795
796
797
803
804
805
806
810
811
815
816
817
818
819
820
821
822
823
824
828
829
830
831
835
836
837
844
845
846
847
852
853
855 "Use Isolate::GetCurrent() instead, which is guaranteed to return the "
856 "same isolate since https://crrev.com/c/6458560.")
860 "Use Isolate::GetCurrent() instead, which is guaranteed to return the "
861 "same isolate since https://crrev.com/c/6458560.")
863 return handle.
template value<
Object>()->GetIsolate();
867
868
869
870
871
872
873
874
880
881
882
883
884
885
886
894
895
896
897
898
899
900
910 static void CheckCast(
Value* obj);
911 Local<
Data> SlowGetInternalField(
int index);
912 void* SlowGetAlignedPointerFromInternalField(
int index);
913 void* SlowGetAlignedPointerFromInternalField(
v8::
Isolate* isolate,
int index);
919#ifndef V8_ENABLE_CHECKS
922 A obj =
internal::ValueHelper::ValueAsAddress(
this);
929 A value = I::ReadRawField<A>(obj, offset);
930#ifdef V8_COMPRESS_POINTERS
933 value = I::DecompressTaggedField(obj,
static_cast<uint32_t>(value));
937 return Local<Data>::New(isolate, value);
940 return SlowGetInternalField(index);
945#if !defined(V8_ENABLE_CHECKS)
948 A obj =
internal::ValueHelper::ValueAsAddress(
this);
959 isolate, obj, offset);
960 return reinterpret_cast<
void*>(value);
963 return SlowGetAlignedPointerFromInternalField(isolate, index);
967#if !defined(V8_ENABLE_CHECKS)
970 A obj =
internal::ValueHelper::ValueAsAddress(
this);
982 isolate, obj, offset);
983 return reinterpret_cast<
void*>(value);
986 return SlowGetAlignedPointerFromInternalField(index);
993 auto obj =
internal::ValueHelper::ValueAsAddress(*wrapper);
994#if !defined(V8_ENABLE_CHECKS)
995 return internal::ReadCppHeapPointerField<T>(
998 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1007 internal::ValueHelper::ValueAsAddress(wrapper.
template value<
Object>());
1008#if !defined(V8_ENABLE_CHECKS)
1009 return internal::ReadCppHeapPointerField<T>(
1012 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1022 internal::ValueHelper::ValueAsAddress(wrapper.
template value<
Object>());
1023#if !defined(V8_ENABLE_CHECKS)
1024 return internal::ReadCppHeapPointerField<T>(
1027 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1032template <
typename T>
1035 auto obj =
internal::ValueHelper::ValueAsAddress(*wrapper);
1036#if !defined(V8_ENABLE_CHECKS)
1037 return internal::ReadCppHeapPointerField<T>(
1040 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1045template <
typename T>
1049 internal::ValueHelper::ValueAsAddress(wrapper.
template value<
Object>());
1050#if !defined(V8_ENABLE_CHECKS)
1051 return internal::ReadCppHeapPointerField<T>(
1055 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1060template <
typename T>
1065 internal::ValueHelper::ValueAsAddress(wrapper.
template value<
Object>());
1066#if !defined(V8_ENABLE_CHECKS)
1067 return internal::ReadCppHeapPointerField<T>(
1070 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1078 auto obj =
internal::ValueHelper::ValueAsAddress(*wrapper);
1079 Wrap(isolate, obj, tag, wrappable);
1087 internal::ValueHelper::ValueAsAddress(wrapper.
template value<
Object>());
1088 Wrap(isolate, obj, tag, wrappable);
1097 internal::ValueHelper::ValueAsAddress(wrapper.
template value<
Object>());
1098 Wrap(isolate, obj, tag, wrappable);
1104 auto obj =
internal::ValueHelper::ValueAsAddress(*wrapper);
1105 Wrap(isolate, obj, tag, wrappable);
1112 internal::ValueHelper::ValueAsAddress(wrapper.
template value<
Object>());
1113 Wrap(isolate, obj, tag, wrappable);
1121 internal::ValueHelper::ValueAsAddress(wrapper.
template value<
Object>());
1122 Wrap(isolate, obj, tag, wrappable);
1126#ifdef V8_ENABLE_CHECKS
1129 return reinterpret_cast<
Private*>(data);
1133#ifdef V8_ENABLE_CHECKS
1136 return static_cast<
Object*>(value);
friend class TracedReference
friend class BasicTracedReference
virtual void Trace(cppgc::Visitor *visitor) const
const char * GetHumanReadableName() const override
virtual const WrapperTypeInfo * GetWrapperTypeInfo() const
static V8_INLINE void Wrap(v8::Isolate *isolate, const PersistentBase< Object > &wrapper, Wrappable *wrappable, CppHeapPointerTag tag)
bool HasNamedLookupInterceptor() const
static V8_INLINE int InternalFieldCount(const PersistentBase< Object > &object)
V8_WARN_UNUSED_RESULT MaybeLocal< Array > GetPropertyNames(Local< Context > context, KeyCollectionMode mode, PropertyFilter property_filter, IndexFilter index_filter, KeyConversionMode key_conversion=KeyConversionMode::kKeepNumbers)
V8_INLINE void * GetAlignedPointerFromInternalField(v8::Isolate *isolate, int index)
V8_WARN_UNUSED_RESULT Maybe< bool > HasOwnProperty(Local< Context > context, uint32_t index)
bool HasIndexedLookupInterceptor() const
static V8_INLINE void Wrap(v8::Isolate *isolate, const PersistentBase< Object > &wrapper, Wrappable *wrappable)
V8_WARN_UNUSED_RESULT Maybe< bool > Set(Local< Context > context, Local< Value > key, Local< Value > value, MaybeLocal< Object > receiver)
V8_WARN_UNUSED_RESULT Maybe< PropertyAttribute > GetPropertyAttributes(Local< Context > context, Local< Value > key)
V8_WARN_UNUSED_RESULT Maybe< bool > Has(Local< Context > context, Local< Value > key)
V8_WARN_UNUSED_RESULT Maybe< bool > SetPrototypeV2(Local< Context > context, Local< Value > prototype)
V8_WARN_UNUSED_RESULT MaybeLocal< Array > GetOwnPropertyNames(Local< Context > context)
static V8_INLINE int InternalFieldCount(const BasicTracedReference< Object > &object)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > CallAsConstructor(Local< Context > context, int argc, Local< Value > argv[])
V8_WARN_UNUSED_RESULT Maybe< bool > HasRealNamedProperty(Local< Context > context, Local< Name > key)
V8_WARN_UNUSED_RESULT Maybe< bool > Delete(Local< Context > context, Local< Value > key)
V8_WARN_UNUSED_RESULT Maybe< bool > SetLazyDataProperty(Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, Local< Value > data=Local< Value >(), PropertyAttribute attributes=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
Maybe< bool > SetIntegrityLevel(Local< Context > context, IntegrityLevel level)
static bool CheckGlobalWrappable(v8::Isolate *isolate, const v8::Local< v8::Object > &wrapper, CppHeapPointerTagRange tag_range)
V8_WARN_UNUSED_RESULT Maybe< bool > SetNativeDataProperty(Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attributes=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
Local< Context > GetCreationContextChecked()
void * GetAlignedPointerFromEmbedderDataInCreationContext(int index)
static V8_INLINE void * GetAlignedPointerFromInternalField(const BasicTracedReference< Object > &object, int index)
V8_WARN_UNUSED_RESULT Maybe< bool > DefineOwnProperty(Local< Context > context, Local< Name > key, Local< Value > value, PropertyAttribute attributes=None)
V8_INLINE void * GetAlignedPointerFromInternalField(int index)
static V8_INLINE void Wrap(v8::Isolate *isolate, const v8::Local< v8::Object > &wrapper, Wrappable *wrappable, CppHeapPointerTag tag)
V8_INLINE Local< Data > GetInternalField(int index)
bool IsApiWrapper() const
static V8_INLINE T * Unwrap(v8::Isolate *isolate, const v8::Local< v8::Object > &wrapper)
Local< String > GetConstructorName()
MaybeLocal< Context > GetCreationContext()
V8_WARN_UNUSED_RESULT MaybeLocal< Array > GetOwnPropertyNames(Local< Context > context, PropertyFilter filter, KeyConversionMode key_conversion=KeyConversionMode::kKeepNumbers)
static V8_INLINE void Wrap(v8::Isolate *isolate, const BasicTracedReference< Object > &wrapper, Wrappable *wrappable, CppHeapPointerTag tag)
void SetAlignedPointerInInternalField(int index, void *value, EmbedderDataTypeTag tag)
static V8_INLINE void Wrap(v8::Isolate *isolate, const v8::Local< v8::Object > &wrapper, Wrappable *wrappable)
Local< Object > Clone(v8::Isolate *isolate)
Maybe< bool > DeletePrivate(Local< Context > context, Local< Private > key)
V8_WARN_UNUSED_RESULT Maybe< PropertyAttribute > GetRealNamedPropertyAttributes(Local< Context > context, Local< Name > key)
void * GetAlignedPointerFromEmbedderDataInCreationContext(v8::Isolate *isolate, int index)
Maybe< bool > HasPrivate(Local< Context > context, Local< Private > key)
static V8_INLINE T * Unwrap(v8::Isolate *isolate, const BasicTracedReference< Object > &wrapper)
static V8_INLINE T * Unwrap(v8::Isolate *isolate, const BasicTracedReference< Object > &wrapper, CppHeapPointerTagRange tag_range)
void SetInternalField(int index, Local< Data > data)
V8_WARN_UNUSED_RESULT Maybe< bool > CreateDataProperty(Local< Context > context, uint32_t index, Local< Value > value)
static void WrapGlobal(v8::Isolate *isolate, const v8::Local< v8::Object > &wrapper, Wrappable *wrappable, CppHeapPointerTag tag)
MaybeLocal< Array > PreviewEntries(bool *is_key_value)
bool IsCodeLike(Isolate *isolate) const
Local< Value > GetPrototypeV2()
static V8_INLINE MaybeLocal< Context > GetCreationContext(const PersistentBase< Object > &object)
V8_WARN_UNUSED_RESULT MaybeLocal< String > ObjectProtoToString(Local< Context > context)
bool IsConstructor() const
static V8_INLINE Object * Cast(Value *obj)
void SetAccessorProperty(Local< Name > name, Local< Function > getter, Local< Function > setter=Local< Function >(), PropertyAttribute attributes=None)
V8_WARN_UNUSED_RESULT Maybe< bool > HasRealIndexedProperty(Local< Context > context, uint32_t index)
static V8_INLINE T * Unwrap(v8::Isolate *isolate, const PersistentBase< Object > &wrapper)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Get(Local< Context > context, Local< Value > key)
V8_WARN_UNUSED_RESULT MaybeLocal< Array > GetPropertyNames(Local< Context > context)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > CallAsFunction(Local< Context > context, Local< Value > recv, int argc, Local< Value > argv[])
Maybe< bool > SetPrivate(Local< Context > context, Local< Private > key, Local< Value > value)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > GetOwnPropertyDescriptor(Local< Context > context, Local< Name > key)
static V8_INLINE MaybeLocal< Context > GetCreationContext(v8::Isolate *isolate, const PersistentBase< Object > &object)
static V8_INLINE void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
V8_WARN_UNUSED_RESULT Maybe< bool > Set(Local< Context > context, uint32_t index, Local< Value > value)
V8_WARN_UNUSED_RESULT Maybe< bool > HasOwnProperty(Local< Context > context, Local< Name > key)
V8_WARN_UNUSED_RESULT Maybe< bool > Delete(Local< Context > context, uint32_t index)
V8_WARN_UNUSED_RESULT Maybe< bool > CreateDataProperty(Local< Context > context, Local< Name > key, Local< Value > value)
MaybeLocal< Context > GetCreationContext(v8::Isolate *isolate)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Get(Local< Context > context, uint32_t index)
V8_WARN_UNUSED_RESULT Maybe< bool > HasRealNamedCallbackProperty(Local< Context > context, Local< Name > key)
static V8_INLINE T * Unwrap(v8::Isolate *isolate, const v8::Local< v8::Object > &wrapper, CppHeapPointerTagRange tag_range)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Get(Local< Context > context, Local< Value > key, MaybeLocal< Object > receiver)
Local< Object > FindInstanceInPrototypeChain(Local< FunctionTemplate > tmpl)
static Local< Object > New(Isolate *isolate)
static Local< Object > New(Isolate *isolate, Local< Value > prototype_or_null, Local< Name > *names, Local< Value > *values, size_t length)
V8_WARN_UNUSED_RESULT Maybe< bool > DefineProperty(Local< Context > context, Local< Name > key, PropertyDescriptor &descriptor)
bool IsUndetectable() const
V8_WARN_UNUSED_RESULT Maybe< PropertyAttribute > GetRealNamedPropertyAttributesInPrototypeChain(Local< Context > context, Local< Name > key)
V8_WARN_UNUSED_RESULT Maybe< bool > Has(Local< Context > context, uint32_t index)
static V8_INLINE void Wrap(v8::Isolate *isolate, const BasicTracedReference< Object > &wrapper, Wrappable *wrappable)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > GetRealNamedProperty(Local< Context > context, Local< Name > key)
static V8_INLINE T * Unwrap(v8::Isolate *isolate, const PersistentBase< Object > &wrapper, CppHeapPointerTagRange tag_range)
Local< Context > GetCreationContextChecked(v8::Isolate *isolate)
MaybeLocal< Value > GetPrivate(Local< Context > context, Local< Private > key)
V8_WARN_UNUSED_RESULT Maybe< bool > Set(Local< Context > context, Local< Value > key, Local< Value > value)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > GetRealNamedPropertyInPrototypeChain(Local< Context > context, Local< Name > key)
int InternalFieldCount() const
friend class PersistentBase
Local< Value > Name() const
static Local< Private > ForApi(Isolate *isolate, Local< String > name)
static V8_INLINE Private * Cast(Data *data)
static Local< Private > New(Isolate *isolate, Local< String > name=Local< String >())
PrivateData * get_private() const
bool has_configurable() const
PropertyDescriptor(const PropertyDescriptor &)=delete
bool has_enumerable() const
Local< Value > set() const
void set_configurable(bool configurable)
void operator=(const PropertyDescriptor &)=delete
PropertyDescriptor(Local< Value > get, Local< Value > set)
bool has_writable() const
PropertyDescriptor(Local< Value > value)
Local< Value > value() const
void set_enumerable(bool enumerable)
Local< Value > get() const
PropertyDescriptor(Local< Value > value, bool writable)
bool configurable() const
static const int kEmbedderDataSlotExternalPointerOffset
static V8_INLINE constexpr bool CanHaveInternalField(int instance_type)
static V8_INLINE int GetInstanceType(Address obj)
static V8_INLINE v8::Isolate * GetCurrentIsolateForSandbox()
static const int kEmbedderDataSlotSize
static V8_EXPORT v8::Isolate * GetCurrentIsolate()
static const int kJSAPIObjectWithEmbedderSlotsHeaderSize
static const int kJSObjectHeaderSize
@ kHasSideEffectToReceiver
constexpr CppHeapPointerTagRange(CppHeapPointerTag lower, CppHeapPointerTag upper)
#define V8_DEPRECATE_SOON(message)
#define V8_DEPRECATED(message)
#define V8_LIKELY(condition)
#define V8_WARN_UNUSED_RESULT
#define V8_ENUM_DEPRECATE_SOON(message)