Loading...
Searching...
No Matches
v8-object.h
Go to the documentation of this file.
1// Copyright 2021 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 INCLUDE_V8_OBJECT_H_
6#define INCLUDE_V8_OBJECT_H_
7
10#include "v8-internal.h" // NOLINT(build/include_directory)
11#include "v8-local-handle.h" // NOLINT(build/include_directory)
12#include "v8-maybe.h" // NOLINT(build/include_directory)
13#include "v8-persistent-handle.h" // NOLINT(build/include_directory)
14#include "v8-primitive.h" // NOLINT(build/include_directory)
15#include "v8-sandbox.h" // NOLINT(build/include_directory)
16#include "v8-traced-handle.h" // NOLINT(build/include_directory)
17#include "v8-value.h" // NOLINT(build/include_directory)
18#include "v8config.h" // NOLINT(build/include_directory)
19
20namespace v8 {
21
22class Array;
23class Function;
24class FunctionTemplate;
25template <typename T>
26class PropertyCallbackInfo;
27
33class V8_EXPORT Private : public Data {
34 public:
39
43 static Local<Private> New(Isolate* isolate,
45
56
57 V8_INLINE static Private* Cast(Data* data);
58
59 private:
60 Private();
61
62 static void CheckCast(Data* that);
63};
64
94 public:
95 // GenericDescriptor
97
98 // DataDescriptor
100
101 // DataDescriptor with writable property
102 PropertyDescriptor(Local<Value> value, bool writable);
103
104 // AccessorDescriptor
106
108
110 bool has_value() const;
111
113 bool has_get() const;
115 bool has_set() const;
116
117 void set_enumerable(bool enumerable);
118 bool enumerable() const;
119 bool has_enumerable() const;
120
121 void set_configurable(bool configurable);
122 bool configurable() const;
123 bool has_configurable() const;
124
125 bool writable() const;
126 bool has_writable() const;
127
128 struct PrivateData;
129 PrivateData* get_private() const { return private_; }
130
132 void operator=(const PropertyDescriptor&) = delete;
133
134 private:
135 PrivateData* private_;
136};
137
143 None = 0,
145 ReadOnly = 1 << 0,
147 DontEnum = 1 << 1,
149 DontDelete = 1 << 2
151
158 void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
159
161 void (*)(Local<Name> property, Local<Value> value,
162 const PropertyCallbackInfo<void>& info);
163
173 "This enum is no longer used and will be removed in V8 12.9.")
176 };
177
187 SKIP_SYMBOLS = 16
189
200enum class SideEffectType {
204};
205
214
220
226
231
235class V8_EXPORT Object : public Value {
236 public:
242 Local<Value> key, Local<Value> value);
244 Local<Value> key, Local<Value> value,
245 MaybeLocal<Object> receiver);
246
248 Local<Value> value);
249
261 Local<Name> key,
262 Local<Value> value);
264 uint32_t index,
265 Local<Value> value);
266
277 Local<Context> context, Local<Name> key, Local<Value> value,
278 PropertyAttribute attributes = None);
279
297 Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
298
300 Local<Value> key);
302 Local<Value> key,
303 MaybeLocal<Object> receiver);
304
306 uint32_t index);
307
314 Local<Context> context, Local<Value> key);
315
321 Local<Context> context, Local<Name> key);
322
339 Local<Value> key);
340
342 Local<Value> key);
343
345
347 uint32_t index);
348
355 PropertyAttribute attributes = None);
356
362 Local<Context> context, Local<Name> name,
364 AccessorNameSetterCallback setter = nullptr,
365 Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
366 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
367 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
368
378 Local<Context> context, Local<Name> name,
380 PropertyAttribute attributes = None,
381 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
382 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
383
392 Local<Value> value);
395
403 Local<Context> context);
405 Local<Context> context, KeyCollectionMode mode,
406 PropertyFilter property_filter, IndexFilter index_filter,
407 KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
408
415 Local<Context> context);
416
424 Local<Context> context, PropertyFilter filter,
425 KeyConversionMode key_conversion = KeyConversionMode::kKeepNumbers);
426
433 "V8 will stop providing access to hidden prototype (i.e. "
434 "JSGlobalObject). Use GetPrototypeV2() instead. "
435 "See http://crbug.com/333672197.")
436 Local<Value> GetPrototype();
437
444 Local<Value> GetPrototypeV2();
445
452 "V8 will stop providing access to hidden prototype (i.e. "
453 "JSGlobalObject). Use SetPrototypeV2() instead. "
454 "See http://crbug.com/333672197.")
455 V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
456 Local<Value> prototype);
457
464 V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototypeV2(Local<Context> context,
465 Local<Value> prototype);
466
471 Local<Object> FindInstanceInPrototypeChain(Local<FunctionTemplate> tmpl);
472
479 Local<Context> context);
480
484 Local<String> GetConstructorName();
485
489 Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
490
492 int InternalFieldCount() const;
493
495 V8_INLINE static int InternalFieldCount(
496 const PersistentBase<Object>& object) {
497 return object.template value<Object>()->InternalFieldCount();
498 }
499
502 const BasicTracedReference<Object>& object) {
503 return object.template value<Object>()->InternalFieldCount();
504 }
505
516 V8_INLINE Local<Data> GetInternalField(int index);
517
519 void SetInternalField(int index, Local<Data> data);
520
526 V8_INLINE void* GetAlignedPointerFromInternalField(int index);
527 V8_INLINE void* GetAlignedPointerFromInternalField(v8::Isolate* isolate,
528 int index);
529
532 const PersistentBase<Object>& object, int index) {
533 return object.template value<Object>()->GetAlignedPointerFromInternalField(
534 index);
535 }
536
539 const BasicTracedReference<Object>& object, int index) {
540 return object.template value<Object>()->GetAlignedPointerFromInternalField(
541 index);
542 }
543
549 void SetAlignedPointerInInternalField(int index, void* value);
550 void SetAlignedPointerInInternalFields(int argc, int indices[],
551 void* values[]);
552
553 // Type information for a Wrappable object that got wrapped with
554 // `v8::Object::Wrap()`.
556 const int16_t type_id;
557 };
558
559 // v8::Object::Wrappable serves as the base class for all C++ objects that can
560 // be wrapped by a JavaScript object using `v8::Object::Wrap()`.
561 //
562 // Note that v8::Object::Wrappable` inherits from `NameProvider` and provides
563 // `GetWrapperTypeInfo` to allow subclasses to have smaller object sizes.
564 class Wrappable : public cppgc::GarbageCollected<Wrappable>,
565 public cppgc::NameProvider {
566 public:
567 virtual const WrapperTypeInfo* GetWrapperTypeInfo() const {
568 return nullptr;
569 }
570
571 const char* GetHumanReadableName() const override { return "internal"; }
572
573 virtual void Trace(cppgc::Visitor* visitor) const {}
574 };
575
586 template <CppHeapPointerTag tag, typename T = void>
587 static V8_INLINE T* Unwrap(v8::Isolate* isolate,
588 const v8::Local<v8::Object>& wrapper);
589 template <CppHeapPointerTag tag, typename T = void>
590 static V8_INLINE T* Unwrap(v8::Isolate* isolate,
591 const PersistentBase<Object>& wrapper);
592 template <CppHeapPointerTag tag, typename T = void>
593 static V8_INLINE T* Unwrap(v8::Isolate* isolate,
594 const BasicTracedReference<Object>& wrapper);
595
596 template <typename T = void>
597 static V8_INLINE T* Unwrap(v8::Isolate* isolate,
598 const v8::Local<v8::Object>& wrapper,
599 CppHeapPointerTagRange tag_range);
600 template <typename T = void>
601 static V8_INLINE T* Unwrap(v8::Isolate* isolate,
602 const PersistentBase<Object>& wrapper,
603 CppHeapPointerTagRange tag_range);
604 template <typename T = void>
605 static V8_INLINE T* Unwrap(v8::Isolate* isolate,
606 const BasicTracedReference<Object>& wrapper,
607 CppHeapPointerTagRange tag_range);
608
618 template <CppHeapPointerTag tag>
619 V8_DEPRECATED("Use `Wrap` with `Wrappable* wrappable` instead")
620 static V8_INLINE
621 void Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
622 void* wrappable);
623 template <CppHeapPointerTag tag>
624 V8_DEPRECATED("Use `Wrap` with `Wrappable* wrappable` instead")
625 static V8_INLINE
626 void Wrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper,
627 void* wrappable);
628 template <CppHeapPointerTag tag>
629 V8_DEPRECATED("Use `Wrap` with `Wrappable* wrappable` instead")
630 static V8_INLINE
631 void Wrap(v8::Isolate* isolate,
632 const BasicTracedReference<Object>& wrapper, void* wrappable);
633 V8_DEPRECATED("Use `Wrap` with `Wrappable* wrappable` instead")
634 static V8_INLINE void Wrap(v8::Isolate* isolate,
635 const v8::Local<v8::Object>& wrapper,
636 void* wrappable, CppHeapPointerTag tag);
637 V8_DEPRECATED("Use `Wrap` with `Wrappable* wrappable` instead")
638 static V8_INLINE void Wrap(v8::Isolate* isolate,
639 const PersistentBase<Object>& wrapper,
640 void* wrappable, CppHeapPointerTag tag);
641 V8_DEPRECATED("Use `Wrap` with `Wrappable* wrappable` instead")
642 static V8_INLINE void Wrap(v8::Isolate* isolate,
643 const BasicTracedReference<Object>& wrapper,
644 void* wrappable, CppHeapPointerTag tag);
645
646 template <CppHeapPointerTag tag>
647 static V8_INLINE void Wrap(v8::Isolate* isolate,
648 const v8::Local<v8::Object>& wrapper,
649 Wrappable* wrappable);
650 template <CppHeapPointerTag tag>
651 static V8_INLINE void Wrap(v8::Isolate* isolate,
652 const PersistentBase<Object>& wrapper,
653 Wrappable* wrappable);
654 template <CppHeapPointerTag tag>
655 static V8_INLINE void Wrap(v8::Isolate* isolate,
656 const BasicTracedReference<Object>& wrapper,
657 Wrappable* wrappable);
658 static V8_INLINE void Wrap(v8::Isolate* isolate,
659 const v8::Local<v8::Object>& wrapper,
660 Wrappable* wrappable, CppHeapPointerTag tag);
661 static V8_INLINE void Wrap(v8::Isolate* isolate,
662 const PersistentBase<Object>& wrapper,
663 Wrappable* wrappable, CppHeapPointerTag tag);
664 static V8_INLINE void Wrap(v8::Isolate* isolate,
665 const BasicTracedReference<Object>& wrapper,
666 Wrappable* wrappable, CppHeapPointerTag tag);
667
668 // Version of Wrap() function for v8::Context::Global() objects.
669 // Unlike the functions above it wraps both JSGlobalProxy and its hidden
670 // prototype (JSGlobalObject or remote object).
671 static void WrapGlobal(v8::Isolate* isolate,
672 const v8::Local<v8::Object>& wrapper,
673 Wrappable* wrappable, CppHeapPointerTag tag);
674
675 // Checks that wrappables set on JSGlobalProxy and its hidden prototype are
676 // the same.
677 static bool CheckGlobalWrappable(v8::Isolate* isolate,
678 const v8::Local<v8::Object>& wrapper,
679 CppHeapPointerTagRange tag_range);
680
687 V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
688 Local<Name> key);
689 V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
690 uint32_t index);
704 V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
705 Local<Name> key);
706 V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
707 Local<Context> context, uint32_t index);
708 V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
709 Local<Context> context, Local<Name> key);
710
715 V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
716 Local<Context> context, Local<Name> key);
717
724 GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
725 Local<Name> key);
726
733 Local<Context> context, Local<Name> key);
734
740 V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
741 Local<Context> context, Local<Name> key);
742
744 bool HasNamedLookupInterceptor() const;
745
747 bool HasIndexedLookupInterceptor() const;
748
756 int GetIdentityHash();
757
764 Local<Object> Clone(v8::Isolate* isolate);
765 Local<Object> Clone();
766
772 MaybeLocal<Context> GetCreationContext(v8::Isolate* isolate);
773 V8_DEPRECATE_SOON("Use the version with the isolate argument.")
774 MaybeLocal<Context> GetCreationContext();
775
781 Local<Context> GetCreationContextChecked(v8::Isolate* isolate);
782 V8_DEPRECATE_SOON("Use the version with the isolate argument.")
783 Local<Context> GetCreationContextChecked();
784
786 V8_INLINE static MaybeLocal<Context> GetCreationContext(
787 v8::Isolate* isolate, const PersistentBase<Object>& object) {
788 return object.template value<Object>()->GetCreationContext(isolate);
789 }
790 V8_DEPRECATE_SOON("Use the version with the isolate argument.")
791 V8_INLINE static MaybeLocal<Context> GetCreationContext(
792 const PersistentBase<Object>& object);
793
808 void* GetAlignedPointerFromEmbedderDataInCreationContext(v8::Isolate* isolate,
809 int index);
810 void* GetAlignedPointerFromEmbedderDataInCreationContext(int index);
811
817 bool IsCallable() const;
818
822 bool IsConstructor() const;
823
835 bool IsApiWrapper() const;
836
842 bool IsUndetectable() const;
843
849 Local<Value> recv,
850 int argc,
851 Local<Value> argv[]);
852
859 Local<Context> context, int argc, Local<Value> argv[]);
860
865 "Use Isolate::GetCurrent() instead, which is guaranteed to return the "
866 "same isolate since https://crrev.com/c/6458560.")
867 Isolate* GetIsolate();
868
870 "Use Isolate::GetCurrent() instead, which is guaranteed to return the "
871 "same isolate since https://crrev.com/c/6458560.")
872 V8_INLINE static Isolate* GetIsolate(const TracedReference<Object>& handle) {
873 return handle.template value<Object>()->GetIsolate();
874 }
875
886
887 static Local<Object> New(Isolate* isolate);
888
897 static Local<Object> New(Isolate* isolate, Local<Value> prototype_or_null,
898 Local<Name>* names, Local<Value>* values,
899 size_t length);
900
901 V8_INLINE static Object* Cast(Value* obj);
902
911 bool IsCodeLike(Isolate* isolate) const;
912
913 private:
914 static void* Unwrap(v8::Isolate* isolate, internal::Address wrapper_obj,
915 CppHeapPointerTagRange tag_range);
916 static void Wrap(v8::Isolate* isolate, internal::Address wrapper_obj,
917 CppHeapPointerTag tag, void* wrappable);
918
919 Object();
920 static void CheckCast(Value* obj);
921 Local<Data> SlowGetInternalField(int index);
922 void* SlowGetAlignedPointerFromInternalField(int index);
923 void* SlowGetAlignedPointerFromInternalField(v8::Isolate* isolate, int index);
924};
925
926// --- Implementation ---
927
929#ifndef V8_ENABLE_CHECKS
930 using A = internal::Address;
931 using I = internal::Internals;
933 // Fast path: If the object is a plain JSObject, which is the common case, we
934 // know where to find the internal fields and can return the value directly.
935 int instance_type = I::GetInstanceType(obj);
936 if (I::CanHaveInternalField(instance_type)) {
937 int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
938 (I::kEmbedderDataSlotSize * index);
939 A value = I::ReadRawField<A>(obj, offset);
940#ifdef V8_COMPRESS_POINTERS
941 // We read the full pointer value and then decompress it in order to avoid
942 // dealing with potential endiannes issues.
943 value = I::DecompressTaggedField(obj, static_cast<uint32_t>(value));
944#endif
945
946 auto* isolate = I::GetCurrentIsolate();
947 return Local<Data>::New(isolate, value);
948 }
949#endif
950 return SlowGetInternalField(index);
951}
952
954 int index) {
955#if !defined(V8_ENABLE_CHECKS)
956 using A = internal::Address;
957 using I = internal::Internals;
959 // Fast path: If the object is a plain JSObject, which is the common case, we
960 // know where to find the internal fields and can return the value directly.
961 auto instance_type = I::GetInstanceType(obj);
962 if (V8_LIKELY(I::CanHaveInternalField(instance_type))) {
963 int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
964 (I::kEmbedderDataSlotSize * index) +
965 I::kEmbedderDataSlotExternalPointerOffset;
966 A value =
967 I::ReadExternalPointerField<internal::kEmbedderDataSlotPayloadTag>(
968 isolate, obj, offset);
969 return reinterpret_cast<void*>(value);
970 }
971#endif
972 return SlowGetAlignedPointerFromInternalField(isolate, index);
973}
974
976#if !defined(V8_ENABLE_CHECKS)
977 using A = internal::Address;
978 using I = internal::Internals;
980 // Fast path: If the object is a plain JSObject, which is the common case, we
981 // know where to find the internal fields and can return the value directly.
982 auto instance_type = I::GetInstanceType(obj);
983 if (V8_LIKELY(I::CanHaveInternalField(instance_type))) {
984 int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
985 (I::kEmbedderDataSlotSize * index) +
986 I::kEmbedderDataSlotExternalPointerOffset;
987 Isolate* isolate = I::GetCurrentIsolateForSandbox();
988 A value =
989 I::ReadExternalPointerField<internal::kEmbedderDataSlotPayloadTag>(
990 isolate, obj, offset);
991 return reinterpret_cast<void*>(value);
992 }
993#endif
994 return SlowGetAlignedPointerFromInternalField(index);
995}
996
997// static
998template <CppHeapPointerTag tag, typename T>
1000 CppHeapPointerTagRange tag_range(tag, tag);
1001 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1002#if !defined(V8_ENABLE_CHECKS)
1003 return internal::ReadCppHeapPointerField<T>(
1004 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1005#else // defined(V8_ENABLE_CHECKS)
1006 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1007#endif // defined(V8_ENABLE_CHECKS)
1008}
1009
1010// static
1011template <CppHeapPointerTag tag, typename T>
1013 CppHeapPointerTagRange tag_range(tag, tag);
1014 auto obj =
1015 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1016#if !defined(V8_ENABLE_CHECKS)
1017 return internal::ReadCppHeapPointerField<T>(
1018 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1019#else // defined(V8_ENABLE_CHECKS)
1020 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1021#endif // defined(V8_ENABLE_CHECKS)
1022}
1023
1024// static
1025template <CppHeapPointerTag tag, typename T>
1027 const BasicTracedReference<Object>& wrapper) {
1028 CppHeapPointerTagRange tag_range(tag, tag);
1029 auto obj =
1030 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1031#if !defined(V8_ENABLE_CHECKS)
1032 return internal::ReadCppHeapPointerField<T>(
1033 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1034#else // defined(V8_ENABLE_CHECKS)
1035 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1036#endif // defined(V8_ENABLE_CHECKS)
1037}
1038
1039// static
1040template <typename T>
1042 CppHeapPointerTagRange tag_range) {
1043 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1044#if !defined(V8_ENABLE_CHECKS)
1045 return internal::ReadCppHeapPointerField<T>(
1046 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1047#else // defined(V8_ENABLE_CHECKS)
1048 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1049#endif // defined(V8_ENABLE_CHECKS)
1050}
1051
1052// static
1053template <typename T>
1055 CppHeapPointerTagRange tag_range) {
1056 auto obj =
1057 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1058#if !defined(V8_ENABLE_CHECKS)
1059 return internal::ReadCppHeapPointerField<T>(
1060 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1061#else // defined(V8_ENABLE_CHECKS)
1062
1063 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1064#endif // defined(V8_ENABLE_CHECKS)
1065}
1066
1067// static
1068template <typename T>
1070 const BasicTracedReference<Object>& wrapper,
1071 CppHeapPointerTagRange tag_range) {
1072 auto obj =
1073 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1074#if !defined(V8_ENABLE_CHECKS)
1075 return internal::ReadCppHeapPointerField<T>(
1076 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1077#else // defined(V8_ENABLE_CHECKS)
1078 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1079#endif // defined(V8_ENABLE_CHECKS)
1080}
1081
1082// static
1083template <CppHeapPointerTag tag>
1084void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1085 void* wrappable) {
1086 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1087 Wrap(isolate, obj, tag, wrappable);
1088}
1089
1090// static
1091template <CppHeapPointerTag tag>
1093 void* wrappable) {
1094 auto obj =
1095 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1096 Wrap(isolate, obj, tag, wrappable);
1097}
1098
1099// static
1100template <CppHeapPointerTag tag>
1102 const BasicTracedReference<Object>& wrapper,
1103 void* wrappable) {
1104 auto obj =
1105 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1106 Wrap(isolate, obj, tag, wrappable);
1107}
1108
1109// static
1110void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1111 void* wrappable, CppHeapPointerTag tag) {
1112 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1113 Wrap(isolate, obj, tag, wrappable);
1114}
1115
1116// static
1118 void* wrappable, CppHeapPointerTag tag) {
1119 auto obj =
1120 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1121 Wrap(isolate, obj, tag, wrappable);
1122}
1123
1124// static
1126 const BasicTracedReference<Object>& wrapper, void* wrappable,
1127 CppHeapPointerTag tag) {
1128 auto obj =
1129 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1130 Wrap(isolate, obj, tag, wrappable);
1131}
1132
1133// static
1134template <CppHeapPointerTag tag>
1135void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1136 v8::Object::Wrappable* wrappable) {
1137 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1138 Wrap(isolate, obj, tag, wrappable);
1139}
1140
1141// static
1142template <CppHeapPointerTag tag>
1144 v8::Object::Wrappable* wrappable) {
1145 auto obj =
1146 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1147 Wrap(isolate, obj, tag, wrappable);
1148}
1149
1150// static
1151template <CppHeapPointerTag tag>
1153 const BasicTracedReference<Object>& wrapper,
1154 v8::Object::Wrappable* wrappable) {
1155 auto obj =
1156 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1157 Wrap(isolate, obj, tag, wrappable);
1158}
1159
1160// static
1161void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1162 v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1163 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1164 Wrap(isolate, obj, tag, wrappable);
1165}
1166
1167// static
1169 v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1170 auto obj =
1171 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1172 Wrap(isolate, obj, tag, wrappable);
1173}
1174
1175// static
1177 const BasicTracedReference<Object>& wrapper,
1178 v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1179 auto obj =
1180 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1181 Wrap(isolate, obj, tag, wrappable);
1182}
1183
1185#ifdef V8_ENABLE_CHECKS
1186 CheckCast(data);
1187#endif
1188 return reinterpret_cast<Private*>(data);
1189}
1190
1192#ifdef V8_ENABLE_CHECKS
1193 CheckCast(value);
1194#endif
1195 return static_cast<Object*>(value);
1196}
1197
1198} // namespace v8
1199
1200#endif // INCLUDE_V8_OBJECT_H_
Definition: garbage-collected.h:53
Definition: name-provider.h:26
Definition: visitor.h:75
Definition: v8-traced-handle.h:124
Definition: v8-context.h:48
Definition: v8-data.h:18
Definition: v8-template.h:583
Definition: v8-isolate.h:290
Definition: v8-local-handle.h:364
static Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8-local-handle.h:446
Definition: v8-local-handle.h:732
Definition: v8-maybe.h:39
Definition: v8-primitive.h:79
Definition: v8-object.h:565
const char * GetHumanReadableName() const override
Definition: v8-object.h:571
virtual const WrapperTypeInfo * GetWrapperTypeInfo() const
Definition: v8-object.h:567
virtual void Trace(cppgc::Visitor *visitor) const
Definition: v8-object.h:573
Definition: v8-object.h:235
Maybe< PropertyAttribute > GetPropertyAttributes(Local< Context > context, Local< Value > key)
void SetAlignedPointerInInternalField(int index, void *value)
Maybe< bool > CreateDataProperty(Local< Context > context, uint32_t index, Local< Value > value)
MaybeLocal< Value > GetOwnPropertyDescriptor(Local< Context > context, Local< Name > key)
static void Wrap(v8::Isolate *isolate, const v8::Local< v8::Object > &wrapper, void *wrappable)
Definition: v8-object.h:1084
static Object * Cast(Value *obj)
Definition: v8-object.h:1191
Maybe< bool > SetPrivate(Local< Context > context, Local< Private > key, Local< Value > value)
MaybeLocal< Array > GetPropertyNames(Local< Context > context)
Maybe< bool > Delete(Local< Context > context, uint32_t index)
Maybe< bool > DefineProperty(Local< Context > context, Local< Name > key, PropertyDescriptor &descriptor)
Maybe< bool > Delete(Local< Context > context, Local< Value > key)
Maybe< bool > DefineOwnProperty(Local< Context > context, Local< Name > key, Local< Value > value, PropertyAttribute attributes=None)
void * GetAlignedPointerFromInternalField(int index)
Definition: v8-object.h:975
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)
static int InternalFieldCount(const BasicTracedReference< Object > &object)
Definition: v8-object.h:501
Maybe< bool > Has(Local< Context > context, Local< Value > key)
MaybeLocal< Array > GetOwnPropertyNames(Local< Context > context)
bool IsCodeLike(Isolate *isolate) const
Maybe< bool > Set(Local< Context > context, Local< Value > key, Local< Value > value)
static void * GetAlignedPointerFromInternalField(const PersistentBase< Object > &object, int index)
Definition: v8-object.h:531
MaybeLocal< Value > GetPrivate(Local< Context > context, Local< Private > key)
void SetAccessorProperty(Local< Name > name, Local< Function > getter, Local< Function > setter=Local< Function >(), PropertyAttribute attributes=None)
Maybe< bool > CreateDataProperty(Local< Context > context, Local< Name > key, Local< Value > value)
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)
MaybeLocal< Value > Get(Local< Context > context, uint32_t index)
MaybeLocal< Array > GetPropertyNames(Local< Context > context, KeyCollectionMode mode, PropertyFilter property_filter, IndexFilter index_filter, KeyConversionMode key_conversion=KeyConversionMode::kKeepNumbers)
Local< Data > GetInternalField(int index)
Definition: v8-object.h:928
Maybe< bool > HasPrivate(Local< Context > context, Local< Private > key)
MaybeLocal< Value > Get(Local< Context > context, Local< Value > key)
static Local< Object > New(Isolate *isolate)
void SetInternalField(int index, Local< Data > data)
static T * Unwrap(v8::Isolate *isolate, const v8::Local< v8::Object > &wrapper)
Definition: v8-object.h:999
MaybeLocal< Array > GetOwnPropertyNames(Local< Context > context, PropertyFilter filter, KeyConversionMode key_conversion=KeyConversionMode::kKeepNumbers)
Maybe< bool > Set(Local< Context > context, uint32_t index, Local< Value > value)
Maybe< bool > Has(Local< Context > context, uint32_t index)
MaybeLocal< Array > PreviewEntries(bool *is_key_value)
Maybe< bool > DeletePrivate(Local< Context > context, Local< Private > key)
MaybeLocal< Value > Get(Local< Context > context, Local< Value > key, MaybeLocal< Object > receiver)
void SetAlignedPointerInInternalFields(int argc, int indices[], void *values[])
Maybe< bool > Set(Local< Context > context, Local< Value > key, Local< Value > value, MaybeLocal< Object > receiver)
static void * GetAlignedPointerFromInternalField(const BasicTracedReference< Object > &object, int index)
Definition: v8-object.h:538
static Local< Object > New(Isolate *isolate, Local< Value > prototype_or_null, Local< Name > *names, Local< Value > *values, size_t length)
Definition: v8-persistent-handle.h:93
Definition: v8-object.h:33
static Private * Cast(Data *data)
Definition: v8-object.h:1184
Local< Value > Name() const
static Local< Private > ForApi(Isolate *isolate, Local< String > name)
static Local< Private > New(Isolate *isolate, Local< String > name=Local< String >())
Definition: v8-function-callback.h:187
Definition: v8-object.h:93
void set_enumerable(bool enumerable)
bool has_writable() const
bool has_value() const
Local< Value > get() const
Local< Value > set() const
PropertyDescriptor(Local< Value > get, Local< Value > set)
bool has_enumerable() const
PropertyDescriptor(Local< Value > value)
PrivateData * get_private() const
Definition: v8-object.h:129
void operator=(const PropertyDescriptor &)=delete
Local< Value > value() const
bool enumerable() const
PropertyDescriptor(Local< Value > value, bool writable)
void set_configurable(bool configurable)
PropertyDescriptor(const PropertyDescriptor &)=delete
bool has_configurable() const
bool configurable() const
Definition: v8-primitive.h:124
Definition: v8-traced-handle.h:165
Definition: v8-initialization.h:61
Definition: v8-value.h:32
Definition: v8-internal.h:874
static const int kJSObjectHeaderSize
Definition: v8-internal.h:891
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1748
uintptr_t Address
Definition: v8-internal.h:52
Definition: libplatform.h:15
IntegrityLevel
Definition: v8-object.h:230
PropertyAttribute
Definition: v8-object.h:141
@ DontEnum
Definition: v8-object.h:147
@ None
Definition: v8-object.h:143
@ DontDelete
Definition: v8-object.h:149
@ ReadOnly
Definition: v8-object.h:145
KeyCollectionMode
Definition: v8-object.h:213
void(*)(Local< Name > property, const PropertyCallbackInfo< Value > &info) AccessorNameGetterCallback
Definition: v8-object.h:158
SideEffectType
Definition: v8-object.h:200
AccessControl
Definition: v8-object.h:174
@ DEFAULT
Definition: v8-object.h:175
IndexFilter
Definition: v8-object.h:219
KeyConversionMode
Definition: v8-object.h:225
CppHeapPointerTag
Definition: v8-sandbox.h:28
void(*)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< void > &info) AccessorNameSetterCallback
Definition: v8-object.h:162
PropertyFilter
Definition: v8-object.h:181
@ ONLY_CONFIGURABLE
Definition: v8-object.h:185
@ SKIP_SYMBOLS
Definition: v8-object.h:187
@ ONLY_WRITABLE
Definition: v8-object.h:183
@ ALL_PROPERTIES
Definition: v8-object.h:182
@ SKIP_STRINGS
Definition: v8-object.h:186
@ ONLY_ENUMERABLE
Definition: v8-object.h:184
Definition: v8-sandbox.h:70
Definition: v8-object.h:555
const int16_t type_id
Definition: v8-object.h:556
#define V8_EXPORT
Definition: v8config.h:849
#define V8_INLINE
Definition: v8config.h:513
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:627
#define V8_DEPRECATED(message)
Definition: v8config.h:619
#define V8_LIKELY(condition)
Definition: v8config.h:674
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:684
#define V8_ENUM_DEPRECATE_SOON(message)
Definition: v8config.h:664