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_DEPRECATE_SOON("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_DEPRECATE_SOON("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_DEPRECATE_SOON("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_DEPRECATE_SOON("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_DEPRECATE_SOON("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_DEPRECATE_SOON("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
674 V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
675 Local<Name> key);
676 V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
677 uint32_t index);
691 V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
692 Local<Name> key);
693 V8_WARN_UNUSED_RESULT Maybe<bool> HasRealIndexedProperty(
694 Local<Context> context, uint32_t index);
695 V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedCallbackProperty(
696 Local<Context> context, Local<Name> key);
697
702 V8_WARN_UNUSED_RESULT MaybeLocal<Value> GetRealNamedPropertyInPrototypeChain(
703 Local<Context> context, Local<Name> key);
704
711 GetRealNamedPropertyAttributesInPrototypeChain(Local<Context> context,
712 Local<Name> key);
713
720 Local<Context> context, Local<Name> key);
721
727 V8_WARN_UNUSED_RESULT Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
728 Local<Context> context, Local<Name> key);
729
731 bool HasNamedLookupInterceptor() const;
732
734 bool HasIndexedLookupInterceptor() const;
735
743 int GetIdentityHash();
744
751 Local<Object> Clone(v8::Isolate* isolate);
752 Local<Object> Clone();
753
759 MaybeLocal<Context> GetCreationContext(v8::Isolate* isolate);
760 V8_DEPRECATE_SOON("Use the version with the isolate argument.")
761 MaybeLocal<Context> GetCreationContext();
762
768 Local<Context> GetCreationContextChecked(v8::Isolate* isolate);
769 V8_DEPRECATE_SOON("Use the version with the isolate argument.")
770 Local<Context> GetCreationContextChecked();
771
773 V8_INLINE static MaybeLocal<Context> GetCreationContext(
774 v8::Isolate* isolate, const PersistentBase<Object>& object) {
775 return object.template value<Object>()->GetCreationContext(isolate);
776 }
777 V8_DEPRECATE_SOON("Use the version with the isolate argument.")
778 V8_INLINE static MaybeLocal<Context> GetCreationContext(
779 const PersistentBase<Object>& object);
780
795 void* GetAlignedPointerFromEmbedderDataInCreationContext(v8::Isolate* isolate,
796 int index);
797 void* GetAlignedPointerFromEmbedderDataInCreationContext(int index);
798
804 bool IsCallable() const;
805
809 bool IsConstructor() const;
810
822 bool IsApiWrapper() const;
823
829 bool IsUndetectable() const;
830
836 Local<Value> recv,
837 int argc,
838 Local<Value> argv[]);
839
846 Local<Context> context, int argc, Local<Value> argv[]);
847
852 "Use Isolate::GetCurrent() instead, which is guaranteed to return the "
853 "same isolate since https://crrev.com/c/6458560.")
854 Isolate* GetIsolate();
855
857 "Use Isolate::GetCurrent() instead, which is guaranteed to return the "
858 "same isolate since https://crrev.com/c/6458560.")
859 V8_INLINE static Isolate* GetIsolate(const TracedReference<Object>& handle) {
860 return handle.template value<Object>()->GetIsolate();
861 }
862
873
874 static Local<Object> New(Isolate* isolate);
875
884 static Local<Object> New(Isolate* isolate, Local<Value> prototype_or_null,
885 Local<Name>* names, Local<Value>* values,
886 size_t length);
887
888 V8_INLINE static Object* Cast(Value* obj);
889
898 bool IsCodeLike(Isolate* isolate) const;
899
900 private:
901 static void* Unwrap(v8::Isolate* isolate, internal::Address wrapper_obj,
902 CppHeapPointerTagRange tag_range);
903 static void Wrap(v8::Isolate* isolate, internal::Address wrapper_obj,
904 CppHeapPointerTag tag, void* wrappable);
905
906 Object();
907 static void CheckCast(Value* obj);
908 Local<Data> SlowGetInternalField(int index);
909 void* SlowGetAlignedPointerFromInternalField(int index);
910 void* SlowGetAlignedPointerFromInternalField(v8::Isolate* isolate, int index);
911};
912
913// --- Implementation ---
914
916#ifndef V8_ENABLE_CHECKS
917 using A = internal::Address;
918 using I = internal::Internals;
920 // Fast path: If the object is a plain JSObject, which is the common case, we
921 // know where to find the internal fields and can return the value directly.
922 int instance_type = I::GetInstanceType(obj);
923 if (I::CanHaveInternalField(instance_type)) {
924 int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
925 (I::kEmbedderDataSlotSize * index);
926 A value = I::ReadRawField<A>(obj, offset);
927#ifdef V8_COMPRESS_POINTERS
928 // We read the full pointer value and then decompress it in order to avoid
929 // dealing with potential endiannes issues.
930 value = I::DecompressTaggedField(obj, static_cast<uint32_t>(value));
931#endif
932
933 auto* isolate = I::GetCurrentIsolate();
934 return Local<Data>::New(isolate, value);
935 }
936#endif
937 return SlowGetInternalField(index);
938}
939
941 int index) {
942#if !defined(V8_ENABLE_CHECKS)
943 using A = internal::Address;
944 using I = internal::Internals;
946 // Fast path: If the object is a plain JSObject, which is the common case, we
947 // know where to find the internal fields and can return the value directly.
948 auto instance_type = I::GetInstanceType(obj);
949 if (V8_LIKELY(I::CanHaveInternalField(instance_type))) {
950 int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
951 (I::kEmbedderDataSlotSize * index) +
952 I::kEmbedderDataSlotExternalPointerOffset;
953 A value =
954 I::ReadExternalPointerField<internal::kEmbedderDataSlotPayloadTag>(
955 isolate, obj, offset);
956 return reinterpret_cast<void*>(value);
957 }
958#endif
959 return SlowGetAlignedPointerFromInternalField(isolate, index);
960}
961
963#if !defined(V8_ENABLE_CHECKS)
964 using A = internal::Address;
965 using I = internal::Internals;
967 // Fast path: If the object is a plain JSObject, which is the common case, we
968 // know where to find the internal fields and can return the value directly.
969 auto instance_type = I::GetInstanceType(obj);
970 if (V8_LIKELY(I::CanHaveInternalField(instance_type))) {
971 int offset = I::kJSAPIObjectWithEmbedderSlotsHeaderSize +
972 (I::kEmbedderDataSlotSize * index) +
973 I::kEmbedderDataSlotExternalPointerOffset;
974 Isolate* isolate = I::GetCurrentIsolateForSandbox();
975 A value =
976 I::ReadExternalPointerField<internal::kEmbedderDataSlotPayloadTag>(
977 isolate, obj, offset);
978 return reinterpret_cast<void*>(value);
979 }
980#endif
981 return SlowGetAlignedPointerFromInternalField(index);
982}
983
984// static
985template <CppHeapPointerTag tag, typename T>
987 CppHeapPointerTagRange tag_range(tag, tag);
988 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
989#if !defined(V8_ENABLE_CHECKS)
990 return internal::ReadCppHeapPointerField<T>(
991 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
992#else // defined(V8_ENABLE_CHECKS)
993 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
994#endif // defined(V8_ENABLE_CHECKS)
995}
996
997// static
998template <CppHeapPointerTag tag, typename T>
1000 CppHeapPointerTagRange tag_range(tag, tag);
1001 auto obj =
1002 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1003#if !defined(V8_ENABLE_CHECKS)
1004 return internal::ReadCppHeapPointerField<T>(
1005 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1006#else // defined(V8_ENABLE_CHECKS)
1007 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1008#endif // defined(V8_ENABLE_CHECKS)
1009}
1010
1011// static
1012template <CppHeapPointerTag tag, typename T>
1014 const BasicTracedReference<Object>& wrapper) {
1015 CppHeapPointerTagRange tag_range(tag, tag);
1016 auto obj =
1017 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1018#if !defined(V8_ENABLE_CHECKS)
1019 return internal::ReadCppHeapPointerField<T>(
1020 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1021#else // defined(V8_ENABLE_CHECKS)
1022 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1023#endif // defined(V8_ENABLE_CHECKS)
1024}
1025
1026// static
1027template <typename T>
1029 CppHeapPointerTagRange tag_range) {
1030 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
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 =
1044 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1045#if !defined(V8_ENABLE_CHECKS)
1046 return internal::ReadCppHeapPointerField<T>(
1047 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1048#else // defined(V8_ENABLE_CHECKS)
1049
1050 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1051#endif // defined(V8_ENABLE_CHECKS)
1052}
1053
1054// static
1055template <typename T>
1057 const BasicTracedReference<Object>& wrapper,
1058 CppHeapPointerTagRange tag_range) {
1059 auto obj =
1060 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1061#if !defined(V8_ENABLE_CHECKS)
1062 return internal::ReadCppHeapPointerField<T>(
1063 isolate, obj, internal::Internals::kJSObjectHeaderSize, tag_range);
1064#else // defined(V8_ENABLE_CHECKS)
1065 return reinterpret_cast<T*>(Unwrap(isolate, obj, tag_range));
1066#endif // defined(V8_ENABLE_CHECKS)
1067}
1068
1069// static
1070template <CppHeapPointerTag tag>
1071void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1072 void* wrappable) {
1073 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1074 Wrap(isolate, obj, tag, wrappable);
1075}
1076
1077// static
1078template <CppHeapPointerTag tag>
1080 void* wrappable) {
1081 auto obj =
1082 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1083 Wrap(isolate, obj, tag, wrappable);
1084}
1085
1086// static
1087template <CppHeapPointerTag tag>
1089 const BasicTracedReference<Object>& wrapper,
1090 void* wrappable) {
1091 auto obj =
1092 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1093 Wrap(isolate, obj, tag, wrappable);
1094}
1095
1096// static
1097void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1098 void* wrappable, CppHeapPointerTag tag) {
1099 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1100 Wrap(isolate, obj, tag, wrappable);
1101}
1102
1103// static
1105 void* wrappable, CppHeapPointerTag tag) {
1106 auto obj =
1107 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1108 Wrap(isolate, obj, tag, wrappable);
1109}
1110
1111// static
1113 const BasicTracedReference<Object>& wrapper, void* wrappable,
1114 CppHeapPointerTag tag) {
1115 auto obj =
1116 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1117 Wrap(isolate, obj, tag, wrappable);
1118}
1119
1120// static
1121template <CppHeapPointerTag tag>
1122void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1123 v8::Object::Wrappable* wrappable) {
1124 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1125 Wrap(isolate, obj, tag, wrappable);
1126}
1127
1128// static
1129template <CppHeapPointerTag tag>
1131 v8::Object::Wrappable* wrappable) {
1132 auto obj =
1133 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1134 Wrap(isolate, obj, tag, wrappable);
1135}
1136
1137// static
1138template <CppHeapPointerTag tag>
1140 const BasicTracedReference<Object>& wrapper,
1141 v8::Object::Wrappable* wrappable) {
1142 auto obj =
1143 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1144 Wrap(isolate, obj, tag, wrappable);
1145}
1146
1147// static
1148void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper,
1149 v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1150 auto obj = internal::ValueHelper::ValueAsAddress(*wrapper);
1151 Wrap(isolate, obj, tag, wrappable);
1152}
1153
1154// static
1156 v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1157 auto obj =
1158 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1159 Wrap(isolate, obj, tag, wrappable);
1160}
1161
1162// static
1164 const BasicTracedReference<Object>& wrapper,
1165 v8::Object::Wrappable* wrappable, CppHeapPointerTag tag) {
1166 auto obj =
1167 internal::ValueHelper::ValueAsAddress(wrapper.template value<Object>());
1168 Wrap(isolate, obj, tag, wrappable);
1169}
1170
1172#ifdef V8_ENABLE_CHECKS
1173 CheckCast(data);
1174#endif
1175 return reinterpret_cast<Private*>(data);
1176}
1177
1179#ifdef V8_ENABLE_CHECKS
1180 CheckCast(value);
1181#endif
1182 return static_cast<Object*>(value);
1183}
1184
1185} // namespace v8
1186
1187#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:297
static Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8-local-handle.h:379
Definition: v8-local-handle.h:665
Definition: v8-maybe.h:33
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:1071
static Object * Cast(Value *obj)
Definition: v8-object.h:1178
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:962
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:915
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:986
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:1171
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:854
static const int kJSObjectHeaderSize
Definition: v8-internal.h:871
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1722
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:800
#define V8_INLINE
Definition: v8config.h:500
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:614
#define V8_LIKELY(condition)
Definition: v8config.h:661
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:671
#define V8_ENUM_DEPRECATE_SOON(message)
Definition: v8config.h:651