v8 11.3.244 (node 20.3.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-template.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_TEMPLATE_H_
6#define INCLUDE_V8_TEMPLATE_H_
7
8#include "v8-data.h" // NOLINT(build/include_directory)
9#include "v8-function-callback.h" // NOLINT(build/include_directory)
10#include "v8-local-handle.h" // NOLINT(build/include_directory)
11#include "v8-memory-span.h" // NOLINT(build/include_directory)
12#include "v8-object.h" // NOLINT(build/include_directory)
13#include "v8config.h" // NOLINT(build/include_directory)
14
15namespace v8 {
16
17class CFunction;
18class FunctionTemplate;
19class ObjectTemplate;
20class Signature;
21
22// --- Templates ---
23
24#define V8_INTRINSICS_LIST(F) \
25 F(ArrayProto_entries, array_entries_iterator) \
26 F(ArrayProto_forEach, array_for_each_iterator) \
27 F(ArrayProto_keys, array_keys_iterator) \
28 F(ArrayProto_values, array_values_iterator) \
29 F(ArrayPrototype, initial_array_prototype) \
30 F(AsyncIteratorPrototype, initial_async_iterator_prototype) \
31 F(ErrorPrototype, initial_error_prototype) \
32 F(IteratorPrototype, initial_iterator_prototype) \
33 F(MapIteratorPrototype, initial_map_iterator_prototype) \
34 F(ObjProto_valueOf, object_value_of_function) \
35 F(SetIteratorPrototype, initial_set_iterator_prototype)
36
38#define V8_DECL_INTRINSIC(name, iname) k##name,
40#undef V8_DECL_INTRINSIC
41};
42
46class V8_EXPORT Template : public Data {
47 public:
53 void Set(Local<Name> name, Local<Data> value,
54 PropertyAttribute attributes = None);
56 PropertyAttribute attributes = None);
57 V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value,
58 PropertyAttribute attributes = None);
59
61 Local<Name> name,
64 PropertyAttribute attribute = None, AccessControl settings = DEFAULT);
65
90 AccessorSetterCallback setter = nullptr,
91 Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
92 AccessControl settings = DEFAULT,
93 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
94 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
97 AccessorNameSetterCallback setter = nullptr,
98 Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
99 AccessControl settings = DEFAULT,
100 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
101 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
102
109 Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
110 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
111 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
112
118 PropertyAttribute attribute = None);
119
120 private:
121 Template();
122
123 friend class ObjectTemplate;
124 friend class FunctionTemplate;
125};
126
127// TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
128// NamedPropertyFooCallback.
129
168 void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
169
192 void (*)(Local<Name> property, Local<Value> value,
193 const PropertyCallbackInfo<Value>& info);
194
219 void (*)(Local<Name> property, const PropertyCallbackInfo<Integer>& info);
220
244 void (*)(Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
245
253 void (*)(const PropertyCallbackInfo<Array>& info);
254
276 void (*)(Local<Name> property, const PropertyDescriptor& desc,
277 const PropertyCallbackInfo<Value>& info);
278
299 void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
300
305 void (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
306
311 void (*)(uint32_t index, Local<Value> value,
312 const PropertyCallbackInfo<Value>& info);
313
318 void (*)(uint32_t index, const PropertyCallbackInfo<Integer>& info);
319
324 void (*)(uint32_t index, const PropertyCallbackInfo<Boolean>& info);
325
333 void (*)(const PropertyCallbackInfo<Array>& info);
334
339 void (*)(uint32_t index, const PropertyDescriptor& desc,
340 const PropertyCallbackInfo<Value>& info);
341
346 void (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
347
352using AccessCheckCallback = bool (*)(Local<Context> accessing_context,
353 Local<Object> accessed_object,
354 Local<Value> data);
355
357
466 public:
469 Isolate* isolate, FunctionCallback callback = nullptr,
470 Local<Value> data = Local<Value>(),
471 Local<Signature> signature = Local<Signature>(), int length = 0,
472 ConstructorBehavior behavior = ConstructorBehavior::kAllow,
473 SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
474 const CFunction* c_function = nullptr, uint16_t instance_type = 0,
475 uint16_t allowed_receiver_instance_type_range_start = 0,
476 uint16_t allowed_receiver_instance_type_range_end = 0);
477
480 Isolate* isolate, FunctionCallback callback = nullptr,
481 Local<Value> data = Local<Value>(),
482 Local<Signature> signature = Local<Signature>(), int length = 0,
483 ConstructorBehavior behavior = ConstructorBehavior::kAllow,
484 SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
485 const MemorySpan<const CFunction>& c_function_overloads = {});
486
491 Isolate* isolate, FunctionCallback callback,
492 Local<Private> cache_property, Local<Value> data = Local<Value>(),
493 Local<Signature> signature = Local<Signature>(), int length = 0,
494 SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
495
498 Local<Context> context);
499
508
516 FunctionCallback callback, Local<Value> data = Local<Value>(),
517 SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
518 const MemorySpan<const CFunction>& c_function_overloads = {});
519
521 void SetLength(int length);
522
525
532
538
546
553
558 void SetAcceptAnyReceiver(bool value);
559
565
571
577
586
587 V8_INLINE static FunctionTemplate* Cast(Data* data);
588
589 private:
591
592 static void CheckCast(Data* that);
593 friend class Context;
594 friend class ObjectTemplate;
595};
596
605 kNone = 0,
606
610 kAllCanRead = 1,
611
616 kNonMasking = 1 << 1,
617
622 kOnlyInterceptStrings = 1 << 2,
623
627 kHasNoSideEffect = 1 << 3,
628};
629
641 : getter(getter),
642 setter(setter),
643 query(query),
648 data(data),
649 flags(flags) {}
650
660 : getter(getter),
661 setter(setter),
662 query(query),
665 definer(nullptr),
666 descriptor(nullptr),
667 data(data),
668 flags(flags) {}
669
679 : getter(getter),
680 setter(setter),
681 query(nullptr),
686 data(data),
687 flags(flags) {}
688
698};
699
710 : getter(getter),
711 setter(setter),
712 query(query),
717 data(data),
718 flags(flags) {}
719
729 : getter(getter),
730 setter(setter),
731 query(query),
734 definer(nullptr),
735 descriptor(nullptr),
736 data(data),
737 flags(flags) {}
738
748 : getter(getter),
749 setter(setter),
750 query(nullptr),
755 data(data),
756 flags(flags) {}
757
767};
768
776 public:
779 Isolate* isolate,
781
784
811 AccessorSetterCallback setter = nullptr,
812 Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
813 PropertyAttribute attribute = None,
814 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
815 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
818 AccessorNameSetterCallback setter = nullptr,
819 Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
820 PropertyAttribute attribute = None,
821 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
822 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
823
836
853 // TODO(dcarney): deprecate
856 IndexedPropertySetterCallback setter = nullptr,
857 IndexedPropertyQueryCallback query = nullptr,
858 IndexedPropertyDeleterCallback deleter = nullptr,
859 IndexedPropertyEnumeratorCallback enumerator = nullptr,
860 Local<Value> data = Local<Value>()) {
861 SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
862 deleter, enumerator, data));
863 }
864
876
884 Local<Value> data = Local<Value>());
885
895
905 Local<Value> data = Local<Value>());
906
914 AccessCheckCallback callback,
915 const NamedPropertyHandlerConfiguration& named_handler,
916 const IndexedPropertyHandlerConfiguration& indexed_handler,
917 Local<Value> data = Local<Value>());
918
924
929 void SetInternalFieldCount(int value);
930
934 bool IsImmutableProto() const;
935
941
952 bool IsCodeLike() const;
953
954 V8_INLINE static ObjectTemplate* Cast(Data* data);
955
956 private:
958 static Local<ObjectTemplate> New(internal::Isolate* isolate,
959 Local<FunctionTemplate> constructor);
960 static void CheckCast(Data* that);
961 friend class FunctionTemplate;
962};
963
972class V8_EXPORT Signature : public Data {
973 public:
975 Isolate* isolate,
977
978 V8_INLINE static Signature* Cast(Data* data);
979
980 private:
981 Signature();
982
983 static void CheckCast(Data* that);
984};
985
986// --- Implementation ---
987
988void Template::Set(Isolate* isolate, const char* name, Local<Data> value,
989 PropertyAttribute attributes) {
991 .ToLocalChecked(),
992 value, attributes);
993}
994
996#ifdef V8_ENABLE_CHECKS
997 CheckCast(data);
998#endif
999 return reinterpret_cast<FunctionTemplate*>(data);
1000}
1001
1003#ifdef V8_ENABLE_CHECKS
1004 CheckCast(data);
1005#endif
1006 return reinterpret_cast<ObjectTemplate*>(data);
1007}
1008
1010#ifdef V8_ENABLE_CHECKS
1011 CheckCast(data);
1012#endif
1013 return reinterpret_cast<Signature*>(data);
1014}
1015
1016} // namespace v8
1017
1018#endif // INCLUDE_V8_TEMPLATE_H_
bool HasInstance(Local< Value > object)
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=nullptr, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect, const CFunction *c_function=nullptr, uint16_t instance_type=0, uint16_t allowed_receiver_instance_type_range_start=0, uint16_t allowed_receiver_instance_type_range_end=0)
static Local< FunctionTemplate > NewWithCache(Isolate *isolate, FunctionCallback callback, Local< Private > cache_property, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
void SetCallHandler(FunctionCallback callback, Local< Value > data=Local< Value >(), SideEffectType side_effect_type=SideEffectType::kHasSideEffect, const MemorySpan< const CFunction > &c_function_overloads={})
static Local< FunctionTemplate > NewWithCFunctionOverloads(Isolate *isolate, FunctionCallback callback=nullptr, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect, const MemorySpan< const CFunction > &c_function_overloads={})
Local< ObjectTemplate > InstanceTemplate()
void SetLength(int length)
bool IsLeafTemplateForApiObject(v8::Local< v8::Value > value) const
Local< ObjectTemplate > PrototypeTemplate()
void Inherit(Local< FunctionTemplate > parent)
V8_WARN_UNUSED_RESULT MaybeLocal< Function > GetFunction(Local< Context > context)
static V8_INLINE FunctionTemplate * Cast(Data *data)
V8_WARN_UNUSED_RESULT MaybeLocal< Object > NewRemoteInstance()
void SetPrototypeProviderTemplate(Local< FunctionTemplate > prototype_provider)
void SetClassName(Local< String > name)
void SetAcceptAnyReceiver(bool value)
void SetHandler(const NamedPropertyHandlerConfiguration &configuration)
void SetInternalFieldCount(int value)
static Local< ObjectTemplate > New(Isolate *isolate, Local< FunctionTemplate > constructor=Local< FunctionTemplate >())
bool IsCodeLike() const
void SetCallAsFunctionHandler(FunctionCallback callback, Local< Value > data=Local< Value >())
void SetAccessor(Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
void SetAccessCheckCallbackAndHandler(AccessCheckCallback callback, const NamedPropertyHandlerConfiguration &named_handler, const IndexedPropertyHandlerConfiguration &indexed_handler, Local< Value > data=Local< Value >())
void SetAccessCheckCallback(AccessCheckCallback callback, Local< Value > data=Local< Value >())
bool IsImmutableProto() const
void SetAccessor(Local< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
void SetHandler(const IndexedPropertyHandlerConfiguration &configuration)
V8_WARN_UNUSED_RESULT MaybeLocal< Object > NewInstance(Local< Context > context)
static V8_INLINE ObjectTemplate * Cast(Data *data)
void SetIndexedPropertyHandler(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter=nullptr, IndexedPropertyQueryCallback query=nullptr, IndexedPropertyDeleterCallback deleter=nullptr, IndexedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >())
int InternalFieldCount() const
static V8_INLINE Signature * Cast(Data *data)
static Local< Signature > New(Isolate *isolate, Local< FunctionTemplate > receiver=Local< FunctionTemplate >())
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=NewStringType::kNormal, int length=-1)
void SetNativeDataProperty(Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
void SetIntrinsicDataProperty(Local< Name > name, Intrinsic intrinsic, PropertyAttribute attribute=None)
void SetAccessorProperty(Local< Name > name, Local< FunctionTemplate > getter=Local< FunctionTemplate >(), Local< FunctionTemplate > setter=Local< FunctionTemplate >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT)
void SetPrivate(Local< Private > name, Local< Data > value, PropertyAttribute attributes=None)
void SetLazyDataProperty(Local< Name > name, AccessorNameGetterCallback getter, Local< Value > data=Local< Value >(), PropertyAttribute attribute=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
void Set(Local< Name > name, Local< Data > value, PropertyAttribute attributes=None)
void SetNativeDataProperty(Local< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
void(*)(Local< Name > property, const PropertyCallbackInfo< Value > &info) AccessorNameGetterCallback
Definition v8-object.h:156
Intrinsic
Definition v8-template.h:37
void(*)(Local< Name > property, const PropertyCallbackInfo< Boolean > &info) GenericNamedPropertyDeleterCallback
void(*)(uint32_t index, const PropertyCallbackInfo< Boolean > &info) IndexedPropertyDeleterCallback
void(*)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< void > &info) AccessorSetterCallback
Definition v8-object.h:160
void(*)(uint32_t index, const PropertyCallbackInfo< Value > &info) IndexedPropertyDescriptorCallback
bool(*)(Local< Context > accessing_context, Local< Object > accessed_object, Local< Value > data) AccessCheckCallback
AccessControl
Definition v8-object.h:174
void(*)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info) IndexedPropertySetterCallback
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
void(*)(uint32_t index, const PropertyCallbackInfo< Value > &info) IndexedPropertyGetterCallback
void(*)(Local< Name > property, const PropertyCallbackInfo< Value > &info) GenericNamedPropertyDescriptorCallback
SideEffectType
Definition v8-object.h:203
void(*)(const PropertyCallbackInfo< Array > &info) GenericNamedPropertyEnumeratorCallback
void(*)(Local< Name > property, const PropertyCallbackInfo< Value > &info) GenericNamedPropertyGetterCallback
void(*)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< void > &info) AccessorNameSetterCallback
Definition v8-object.h:163
void(*)(Local< Name > property, const PropertyCallbackInfo< Integer > &info) GenericNamedPropertyQueryCallback
PropertyAttribute
Definition v8-object.h:137
void(*)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< Value > &info) GenericNamedPropertySetterCallback
void(*)(uint32_t index, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info) IndexedPropertyDefinerCallback
ConstructorBehavior
void(*)(const PropertyCallbackInfo< Array > &info) IndexedPropertyEnumeratorCallback
void(*)(Local< String > property, const PropertyCallbackInfo< Value > &info) AccessorGetterCallback
Definition v8-object.h:154
void(*)(Local< Name > property, const PropertyDescriptor &desc, const PropertyCallbackInfo< Value > &info) GenericNamedPropertyDefinerCallback
PropertyHandlerFlags
void(*)(uint32_t index, const PropertyCallbackInfo< Integer > &info) IndexedPropertyQueryCallback
IndexedPropertyHandlerConfiguration(IndexedPropertyGetterCallback getter=nullptr, IndexedPropertySetterCallback setter=nullptr, IndexedPropertyQueryCallback query=nullptr, IndexedPropertyDeleterCallback deleter=nullptr, IndexedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
IndexedPropertyQueryCallback query
IndexedPropertyDefinerCallback definer
IndexedPropertyDeleterCallback deleter
IndexedPropertyDescriptorCallback descriptor
IndexedPropertyGetterCallback getter
IndexedPropertySetterCallback setter
IndexedPropertyHandlerConfiguration(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter, IndexedPropertyDescriptorCallback descriptor, IndexedPropertyDeleterCallback deleter, IndexedPropertyEnumeratorCallback enumerator, IndexedPropertyDefinerCallback definer, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
IndexedPropertyHandlerConfiguration(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter, IndexedPropertyQueryCallback query, IndexedPropertyDeleterCallback deleter, IndexedPropertyEnumeratorCallback enumerator, IndexedPropertyDefinerCallback definer, IndexedPropertyDescriptorCallback descriptor, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
IndexedPropertyEnumeratorCallback enumerator
NamedPropertyHandlerConfiguration(GenericNamedPropertyGetterCallback getter, GenericNamedPropertySetterCallback setter, GenericNamedPropertyDescriptorCallback descriptor, GenericNamedPropertyDeleterCallback deleter, GenericNamedPropertyEnumeratorCallback enumerator, GenericNamedPropertyDefinerCallback definer, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
GenericNamedPropertyQueryCallback query
GenericNamedPropertySetterCallback setter
GenericNamedPropertyGetterCallback getter
GenericNamedPropertyEnumeratorCallback enumerator
NamedPropertyHandlerConfiguration(GenericNamedPropertyGetterCallback getter, GenericNamedPropertySetterCallback setter, GenericNamedPropertyQueryCallback query, GenericNamedPropertyDeleterCallback deleter, GenericNamedPropertyEnumeratorCallback enumerator, GenericNamedPropertyDefinerCallback definer, GenericNamedPropertyDescriptorCallback descriptor, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
GenericNamedPropertyDefinerCallback definer
GenericNamedPropertyDescriptorCallback descriptor
GenericNamedPropertyDeleterCallback deleter
NamedPropertyHandlerConfiguration(GenericNamedPropertyGetterCallback getter=nullptr, GenericNamedPropertySetterCallback setter=nullptr, GenericNamedPropertyQueryCallback query=nullptr, GenericNamedPropertyDeleterCallback deleter=nullptr, GenericNamedPropertyEnumeratorCallback enumerator=nullptr, Local< Value > data=Local< Value >(), PropertyHandlerFlags flags=PropertyHandlerFlags::kNone)
#define V8_INTRINSICS_LIST(F)
Definition v8-template.h:24
#define V8_DECL_INTRINSIC(name, iname)
Definition v8-template.h:38
#define V8_EXPORT
Definition v8config.h:719
#define V8_INLINE
Definition v8config.h:460
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:609