#ifndef V8_OBJECTS_TEMPLATES_H_
#define V8_OBJECTS_TEMPLATES_H_
#include <optional>
#include <string_view>
#include "include/v8-exception.h"
#include "include/v8-memory-span.h"
#include "src/handles/handles.h"
#include "src/objects/contexts.h"
#include "src/objects/struct.h"
#include "torque-generated/bit-fields.h"
#include "src/objects/object-macros.h"
namespace v8 {
class CFunctionInfo;
class StructBodyDescriptor;
namespace internal {
#include "torque-generated/src/objects/templates-tq.inc"
struct CFunctionWithSignature {
static constexpr ExternalPointerTag kManagedTag = kCFunctionWithSignatureTag;
const Address address;
const CFunctionInfo* signature;
CFunctionWithSignature(const Address address, const CFunctionInfo* signature)
: address(address), signature(signature) {}
};
class TemplateInfo
: public TorqueGeneratedTemplateInfo<TemplateInfo, HeapObject> {
public:
static const int kFastTemplateInstantiationsCacheSize = 1 * KB;
static constexpr int kMaxTemplateInstantiationsCacheSize = 1 * MB;
static const int kUninitializedSerialNumber = 0;
static const int kFirstNonUniqueSerialNumber =
kFastTemplateInstantiationsCacheSize;
DECL_BOOLEAN_ACCESSORS(is_cacheable)
DECL_BOOLEAN_ACCESSORS(should_promote_to_read_only)
DECL_PRIMITIVE_ACCESSORS(serial_number, uint32_t)
inline uint32_t EnsureHasSerialNumber(Isolate* isolate);
inline uint32_t GetHash() const;
using BodyDescriptor = StructBodyDescriptor;
enum class CachingMode { kLimited, kUnlimited };
template <typename ReturnType>
static MaybeHandle<ReturnType> ProbeInstantiationsCache(
Isolate* isolate, DirectHandle<NativeContext> native_context,
DirectHandle<TemplateInfo> info, CachingMode caching_mode) {
return Cast<ReturnType>(
ProbeInstantiationsCache(isolate, native_context, info, caching_mode));
}
inline static MaybeHandle<Object> ProbeInstantiationsCache(
Isolate* isolate, DirectHandle<NativeContext> native_context,
DirectHandle<TemplateInfo> info, CachingMode caching_mode);
inline static void CacheTemplateInstantiation(
Isolate* isolate, DirectHandle<NativeContext> native_context,
DirectHandle<TemplateInfo> info, CachingMode caching_mode,
DirectHandle<Object> object);
inline static void UncacheTemplateInstantiation(
Isolate* isolate, DirectHandle<NativeContext> native_context,
DirectHandle<TemplateInfo> info, CachingMode caching_mode);
DEFINE_TORQUE_GENERATED_TEMPLATE_INFO_FLAGS()
TQ_OBJECT_CONSTRUCTORS(TemplateInfo)
};
class TemplateInfoWithProperties
: public TorqueGeneratedTemplateInfoWithProperties<
TemplateInfoWithProperties, TemplateInfo> {
public:
TQ_OBJECT_CONSTRUCTORS(TemplateInfoWithProperties)
};
class FunctionTemplateRareData
: public TorqueGeneratedFunctionTemplateRareData<FunctionTemplateRareData,
Struct> {
public:
DECL_VERIFIER(FunctionTemplateRareData)
using BodyDescriptor = StructBodyDescriptor;
TQ_OBJECT_CONSTRUCTORS(FunctionTemplateRareData)
};
class FunctionTemplateInfo
: public TorqueGeneratedFunctionTemplateInfo<FunctionTemplateInfo,
TemplateInfoWithProperties> {
public:
#define DECL_RARE_ACCESSORS(Name, CamelName, ...) \
DECL_GETTER(Get##CamelName, Tagged<__VA_ARGS__>) \
static inline void Set##CamelName( \
Isolate* isolate, \
DirectHandle<FunctionTemplateInfo> function_template_info, \
DirectHandle<__VA_ARGS__> Name);
DECL_RARE_ACCESSORS(prototype_template, PrototypeTemplate,
UnionOf<Undefined, ObjectTemplateInfo>)
DECL_RARE_ACCESSORS(prototype_provider_template, PrototypeProviderTemplate,
UnionOf<Undefined, FunctionTemplateInfo>)
DECL_RARE_ACCESSORS(parent_template, ParentTemplate,
UnionOf<Undefined, FunctionTemplateInfo>)
DECL_RARE_ACCESSORS(named_property_handler, NamedPropertyHandler,
UnionOf<Undefined, InterceptorInfo>)
DECL_RARE_ACCESSORS(indexed_property_handler, IndexedPropertyHandler,
UnionOf<Undefined, InterceptorInfo>)
DECL_RARE_ACCESSORS(instance_template, InstanceTemplate,
UnionOf<Undefined, ObjectTemplateInfo>)
DECL_RARE_ACCESSORS(instance_call_handler, InstanceCallHandler,
UnionOf<Undefined, FunctionTemplateInfo>)
DECL_RARE_ACCESSORS(access_check_info, AccessCheckInfo,
UnionOf<Undefined, AccessCheckInfo>)
DECL_RARE_ACCESSORS(c_function_overloads, CFunctionOverloads, FixedArray)
#undef DECL_RARE_ACCESSORS
DECL_RELAXED_UINT32_ACCESSORS(flag)
DECL_BOOLEAN_ACCESSORS(is_object_template_call_handler)
DECL_BOOLEAN_ACCESSORS(has_side_effects)
DECL_BOOLEAN_ACCESSORS(undetectable)
DECL_BOOLEAN_ACCESSORS(needs_access_check)
DECL_BOOLEAN_ACCESSORS(read_only_prototype)
DECL_BOOLEAN_ACCESSORS(remove_prototype)
DECL_BOOLEAN_ACCESSORS(accept_any_receiver)
DECL_BOOLEAN_ACCESSORS(published)
DECL_PRIMITIVE_GETTER(allowed_receiver_instance_type_range_start,
InstanceType)
DECL_PRIMITIVE_GETTER(allowed_receiver_instance_type_range_end, InstanceType)
inline InstanceType GetInstanceType() const;
inline void SetInstanceType(int api_instance_type);
inline void SetAllowedReceiverInstanceTypeRange(int api_instance_type_start,
int api_instance_type_end);
static Handle<SharedFunctionInfo> GetOrCreateSharedFunctionInfo(
Isolate* isolate, DirectHandle<FunctionTemplateInfo> info,
MaybeDirectHandle<Name> maybe_name);
static Handle<SharedFunctionInfo> GetOrCreateSharedFunctionInfo(
LocalIsolate* isolate, DirectHandle<FunctionTemplateInfo> info,
DirectHandle<Name> maybe_name) {
UNREACHABLE();
}
inline Tagged<FunctionTemplateInfo> GetParent(Isolate* isolate);
inline bool IsTemplateFor(Tagged<JSObject> object) const;
bool IsTemplateFor(Tagged<Map> map) const;
bool IsLeafTemplateForApiObject(Tagged<Object> object) const;
inline bool instantiated();
static void SealAndPrepareForPromotionToReadOnly(
Isolate* isolate, DirectHandle<FunctionTemplateInfo> info);
bool BreakAtEntry(Isolate* isolate);
bool HasInstanceType();
static std::optional<Tagged<Name>> TryGetCachedPropertyName(
Isolate* isolate, Tagged<Object> getter);
int GetCFunctionsCount() const;
Address GetCFunction(Isolate* isolate, int index) const;
const CFunctionInfo* GetCSignature(Isolate* isolate, int index) const;
DEFINE_TORQUE_GENERATED_FUNCTION_TEMPLATE_INFO_FLAGS()
DECL_REDIRECTED_CALLBACK_ACCESSORS_MAYBE_READ_ONLY_HOST(callback, Address)
inline void RemoveCallbackRedirectionForSerialization(
IsolateForSandbox isolate);
inline void RestoreCallbackRedirectionAfterDeserialization(
IsolateForSandbox isolate);
template <class IsolateT>
inline bool has_callback(IsolateT* isolate) const;
DECL_PRINTER(FunctionTemplateInfo)
class BodyDescriptor;
private:
inline int32_t relaxed_flag() const;
inline void set_relaxed_flag(int32_t flags);
using TorqueGeneratedFunctionTemplateInfo<
FunctionTemplateInfo, TemplateInfoWithProperties>::set_instance_type;
DECL_PRIMITIVE_SETTER(allowed_receiver_instance_type_range_start,
InstanceType)
DECL_PRIMITIVE_SETTER(allowed_receiver_instance_type_range_end, InstanceType)
static constexpr int kNoJSApiObjectType = 0;
static inline Tagged<FunctionTemplateRareData> EnsureFunctionTemplateRareData(
Isolate* isolate,
DirectHandle<FunctionTemplateInfo> function_template_info);
static Tagged<FunctionTemplateRareData> AllocateFunctionTemplateRareData(
Isolate* isolate,
DirectHandle<FunctionTemplateInfo> function_template_info);
TQ_OBJECT_CONSTRUCTORS(FunctionTemplateInfo)
};
class ObjectTemplateInfo
: public TorqueGeneratedObjectTemplateInfo<ObjectTemplateInfo,
TemplateInfoWithProperties> {
public:
DECL_INT_ACCESSORS(embedder_field_count)
DECL_BOOLEAN_ACCESSORS(immutable_proto)
DECL_BOOLEAN_ACCESSORS(code_like)
inline Tagged<ObjectTemplateInfo> GetParent(Isolate* isolate);
static void SealAndPrepareForPromotionToReadOnly(
Isolate* isolate, DirectHandle<ObjectTemplateInfo> info);
using BodyDescriptor = StructBodyDescriptor;
private:
DEFINE_TORQUE_GENERATED_OBJECT_TEMPLATE_INFO_FLAGS()
TQ_OBJECT_CONSTRUCTORS(ObjectTemplateInfo)
};
class DictionaryTemplateInfo
: public TorqueGeneratedDictionaryTemplateInfo<DictionaryTemplateInfo,
TemplateInfo> {
public:
class BodyDescriptor;
static DirectHandle<DictionaryTemplateInfo> Create(
Isolate* isolate, const v8::MemorySpan<const std::string_view>& names);
static DirectHandle<JSObject> NewInstance(
DirectHandle<NativeContext> context,
DirectHandle<DictionaryTemplateInfo> self,
const MemorySpan<MaybeLocal<Value>>& property_values);
TQ_OBJECT_CONSTRUCTORS(DictionaryTemplateInfo)
};
}
}
#include "src/objects/object-macros-undef.h"
#endif