25 explicit InvokeScope(Isolate* isolate)
28 bool has_exception =
isolate_->has_exception();
41MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
42 DirectHandle<ObjectTemplateInfo> data,
46MaybeHandle<JSFunction> InstantiateFunction(
48 DirectHandle<FunctionTemplateInfo> data,
49 MaybeDirectHandle<Name> maybe_name = {});
51MaybeHandle<JSFunction> InstantiateFunction(
52 Isolate* isolate, DirectHandle<FunctionTemplateInfo> data,
53 MaybeDirectHandle<Name> maybe_name = {}) {
54 return InstantiateFunction(isolate, isolate->native_context(), data,
58MaybeDirectHandle<Object> Instantiate(Isolate* isolate,
59 DirectHandle<Object> data,
60 MaybeDirectHandle<Name> maybe_name = {}) {
61 if (IsFunctionTemplateInfo(*data)) {
64 }
else if (IsObjectTemplateInfo(*data)) {
72MaybeDirectHandle<Object> DefineAccessorProperty(
73 Isolate* isolate, DirectHandle<JSObject>
object, DirectHandle<Name> name,
74 DirectHandle<Object>
getter, DirectHandle<Object>
setter,
80 if (IsFunctionTemplateInfo(*
getter) &&
85 DirectHandle<Code> trampoline =
BUILTIN_CODE(isolate, DebugBreakTrampoline);
88 if (IsFunctionTemplateInfo(*
setter) &&
93 DirectHandle<Code> trampoline =
BUILTIN_CODE(isolate, DebugBreakTrampoline);
101MaybeDirectHandle<Object> DefineDataProperty(Isolate* isolate,
102 DirectHandle<JSObject>
object,
103 DirectHandle<Name> name,
104 DirectHandle<Object> prop_data,
106 DirectHandle<Object>
value;
108 Instantiate(isolate, prop_data, name));
110 PropertyKey
key(isolate, name);
119 NewTypeError(MessageTemplate::kDuplicateTemplateProperty, name));
129void DisableAccessChecks(Isolate* isolate, DirectHandle<JSObject>
object) {
130 DirectHandle<Map> old_map(object->map(), isolate);
132 DirectHandle<Map> new_map =
133 Map::Copy(isolate, old_map,
"DisableAccessChecks");
134 new_map->set_is_access_check_needed(
false);
138void EnableAccessChecks(Isolate* isolate, DirectHandle<JSObject>
object) {
139 DirectHandle<Map> old_map(object->map(), isolate);
141 DirectHandle<Map> new_map =
Map::Copy(isolate, old_map,
"EnableAccessChecks");
142 new_map->set_is_access_check_needed(
true);
143 new_map->set_may_have_interesting_properties(
true);
149 AccessCheckDisableScope(Isolate* isolate, DirectHandle<JSObject> obj)
157 ~AccessCheckDisableScope() {
173#define GET_INTRINSIC_VALUE(name, iname) \
175 return native_context->iname();
177#undef GET_INTRINSIC_VALUE
182template <
typename TemplateInfoT>
183MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate,
Handle<JSObject> obj,
184 DirectHandle<TemplateInfoT> data) {
185 RCS_SCOPE(isolate, RuntimeCallCounterId::kConfigureInstance);
186 HandleScope scope(isolate);
188 AccessCheckDisableScope access_check_scope(isolate, obj);
191 int max_number_of_properties = 0;
193 while (!info.is_null()) {
195 if (!IsUndefined(props, isolate)) {
198 info = info->GetParent(isolate);
201 if (max_number_of_properties > 0) {
202 int valid_descriptors = 0;
204 DirectHandle<FixedArray> array =
205 isolate->factory()->NewFixedArray(max_number_of_properties);
209 for (DirectHandle<TemplateInfoT> temp(*data, isolate); !(*temp).is_null();
213 if (!IsUndefined(maybe_properties, isolate)) {
221 for (
int i = 0;
i < valid_descriptors;
i++) {
226 accessor->initial_property_attributes())
232 if (IsUndefined(maybe_property_list, isolate))
return obj;
233 DirectHandle<ArrayList> properties(
Cast<ArrayList>(maybe_property_list),
235 if (properties->length() == 0)
return obj;
238 for (
int c = 0; c < data->number_of_properties(); c++) {
247 auto prop_data =
handle(properties->get(
i++), isolate);
249 prop_data, attributes));
254 isolate, DefineAccessorProperty(isolate, obj, name,
getter,
setter,
260 PropertyDetails details(
Cast<Smi>(properties->get(
i++)));
266 auto prop_data =
handle(GetIntrinsic(isolate, intrinsic), isolate);
269 prop_data, attributes));
281 if (!fun->shared()->IsApiFunction())
return false;
282 if (fun->shared()->api_func_data() != info->constructor())
return false;
283 if (info->immutable_proto())
return false;
284 return fun->native_context() == isolate->raw_native_context();
287MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
288 DirectHandle<ObjectTemplateInfo> info,
291 RCS_SCOPE(isolate, RuntimeCallCounterId::kInstantiateObject);
292 DirectHandle<JSFunction> constructor;
293 bool should_cache = info->is_cacheable();
295 if (IsSimpleInstantiation(isolate, *info, *
new_target)) {
299 should_cache =
false;
306 isolate, isolate->native_context(), info,
309 return isolate->factory()->CopyJSObject(
result);
313 if (constructor.is_null()) {
315 if (IsUndefined(maybe_constructor_info, isolate)) {
316 constructor = isolate->object_function();
319 HandleScope scope(isolate);
320 DirectHandle<FunctionTemplateInfo> cons_templ(
322 DirectHandle<JSFunction> tmp_constructor;
324 InstantiateFunction(isolate, cons_templ));
325 constructor = scope.CloseAndEscape(tmp_constructor);
331 const auto new_js_object_type =
332 constructor->has_initial_map() &&
344 ConfigureInstance(isolate,
object, info));
345 if (info->immutable_proto()) {
355 isolate, isolate->native_context(), info,
365MaybeDirectHandle<Object> GetInstancePrototype(
366 Isolate* isolate, DirectHandle<Object> function_template) {
368 HandleScope scope(isolate);
369 DirectHandle<JSFunction> parent_instance;
371 isolate, parent_instance,
372 InstantiateFunction(isolate,
374 Handle<Object> instance_prototype;
377 isolate, instance_prototype,
378 JSObject::GetProperty(isolate, parent_instance,
379 isolate->factory()->prototype_string()));
380 return scope.CloseAndEscape(instance_prototype);
384MaybeHandle<JSFunction> InstantiateFunction(
386 DirectHandle<FunctionTemplateInfo> info,
387 MaybeDirectHandle<Name> maybe_name) {
388 RCS_SCOPE(isolate, RuntimeCallCounterId::kInstantiateFunction);
389 bool should_cache = info->is_cacheable();
400 if (!info->remove_prototype()) {
401 DirectHandle<Object> prototype_templ(info->GetPrototypeTemplate(), isolate);
402 if (IsUndefined(*prototype_templ, isolate)) {
403 DirectHandle<Object> protoype_provider_templ(
404 info->GetPrototypeProviderTemplate(), isolate);
405 if (IsUndefined(*protoype_provider_templ, isolate)) {
406 prototype = isolate->factory()->NewJSObject(
411 GetInstancePrototype(isolate, protoype_provider_templ));
417 DirectHandle<JSReceiver>(),
true));
419 DirectHandle<Object> parent(info->GetParentTemplate(), isolate);
420 if (!IsUndefined(*parent, isolate)) {
421 DirectHandle<Object> parent_prototype;
423 GetInstancePrototype(isolate, parent));
424 DirectHandle<JSPrototype> checked_parent_prototype;
425 CHECK(
TryCast(parent_prototype, &checked_parent_prototype));
427 checked_parent_prototype);
430 InstanceType function_type = JS_SPECIAL_API_OBJECT_TYPE;
431 if (!info->needs_access_check() &&
432 IsUndefined(info->GetNamedPropertyHandler(), isolate) &&
433 IsUndefined(info->GetIndexedPropertyHandler(), isolate)) {
434 function_type =
v8_flags.experimental_embedder_instance_types
435 ? info->GetInstanceType()
436 : JS_API_OBJECT_TYPE;
437 DCHECK(InstanceTypeChecker::IsJSApiObject(function_type));
441 isolate,
native_context, info, prototype, function_type, maybe_name);
448 MaybeDirectHandle<JSObject>
result =
449 ConfigureInstance(isolate, function, info);
456 info->set_published(
true);
460void AddPropertyToPropertyList(Isolate* isolate,
461 DirectHandle<TemplateInfoWithProperties> info,
462 base::Vector<DirectHandle<Object>> data) {
464 DirectHandle<ArrayList> list;
465 if (IsUndefined(maybe_list, isolate)) {
471 info->set_number_of_properties(info->number_of_properties() + 1);
472 for (DirectHandle<Object> value : data) {
474 value =
Cast<Object>(isolate->factory()->undefined_value());
477 info->set_property_list(*list);
483DirectHandle<FunctionTemplateInfo>
488 auto isolate =
reinterpret_cast<v8::Isolate*
>(i_isolate);
499 InvokeScope invoke_scope(isolate);
500 return ::v8::internal::InstantiateFunction(isolate,
native_context, data,
507 InvokeScope invoke_scope(isolate);
508 return ::v8::internal::InstantiateFunction(isolate, data, maybe_name);
514 InvokeScope invoke_scope(isolate);
515 return ::v8::internal::InstantiateObject(isolate, data,
new_target,
false);
520 Isolate* isolate = data->GetIsolate();
521 InvokeScope invoke_scope(isolate);
526 JS_SPECIAL_API_OBJECT_TYPE,
527 JSSpecialObject::kHeaderSize +
530 object_map->SetConstructor(*constructor);
531 object_map->set_is_access_check_needed(
true);
532 object_map->set_may_have_interesting_properties(
true);
538 isolate->factory()->null_value());
561 auto intrinsic_marker = isolate->factory()->true_value();
587 if (IsUndefined(maybe_list, isolate)) {
593 info->set_property_accessors(*list);
600 RCS_SCOPE(isolate, RuntimeCallCounterId::kCreateApiFunction);
605 DCHECK(shared->HasSharedName());
610 if (obj->remove_prototype()) {
611 DCHECK(prototype.is_null());
622 if (obj->read_only_prototype()) {
624 *isolate->sloppy_function_with_readonly_prototype_map());
627 if (IsTheHole(*prototype, isolate)) {
628 prototype = isolate->factory()->NewFunctionPrototype(
result);
629 }
else if (IsUndefined(obj->GetPrototypeProviderTemplate(), isolate)) {
631 isolate->factory()->constructor_string(),
result,
635 int embedder_field_count = 0;
636 bool immutable_proto =
false;
637 if (!IsUndefined(obj->GetInstanceTemplate(), isolate)) {
640 embedder_field_count = GetInstanceTemplate->embedder_field_count();
641 immutable_proto = GetInstanceTemplate->immutable_proto();
645 DCHECK(!InstanceTypeChecker::IsJSFunction(type));
653 if (obj->undetectable()) {
659 CHECK(!IsUndefined(obj->GetInstanceCallHandler(), isolate));
661 if (Protectors::IsNoUndetectableObjectsIntact(isolate)) {
662 Protectors::InvalidateNoUndetectableObjects(isolate);
664 map->set_is_undetectable(
true);
668 if (obj->needs_access_check()) {
669 map->set_is_access_check_needed(
true);
670 map->set_may_have_interesting_properties(
true);
674 if (!IsUndefined(obj->GetNamedPropertyHandler(), isolate)) {
675 map->set_has_named_interceptor(
true);
676 map->set_may_have_interesting_properties(
true);
678 if (!IsUndefined(obj->GetIndexedPropertyHandler(), isolate)) {
679 map->set_has_indexed_interceptor(
true);
683 if (!IsUndefined(obj->GetInstanceCallHandler(), isolate)) {
684 map->set_is_callable(
true);
685 map->set_is_constructor(!obj->undetectable());
688 if (immutable_proto) map->set_is_immutable_proto(
true);
SaveContext save_context_
#define GET_INTRINSIC_VALUE(name, iname)
DirectHandle< JSObject > obj_
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
#define BUILTIN_CODE(isolate, name)
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 v8::internal::DirectHandle< To > OpenDirectHandle(v8::Local< From > handle)
static int AppendUnique(Isolate *isolate, DirectHandle< Object > descriptors, DirectHandle< FixedArray > array, int valid_descriptors)
static void AddDataProperty(Isolate *isolate, DirectHandle< TemplateInfoWithProperties > info, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
static DirectHandle< FunctionTemplateInfo > CreateAccessorFunctionTemplateInfo(Isolate *isolate, FunctionCallback callback, int length, v8::SideEffectType side_effect_type)
static Handle< JSFunction > CreateApiFunction(Isolate *isolate, DirectHandle< NativeContext > native_context, DirectHandle< FunctionTemplateInfo > obj, DirectHandle< Object > prototype, InstanceType type, MaybeDirectHandle< Name > name={})
static V8_WARN_UNUSED_RESULT MaybeHandle< JSObject > InstantiateRemoteObject(DirectHandle< ObjectTemplateInfo > data)
static V8_WARN_UNUSED_RESULT MaybeHandle< JSFunction > InstantiateFunction(Isolate *isolate, DirectHandle< NativeContext > native_context, DirectHandle< FunctionTemplateInfo > data, MaybeDirectHandle< Name > maybe_name={})
static V8_WARN_UNUSED_RESULT MaybeHandle< JSObject > InstantiateObject(Isolate *isolate, DirectHandle< ObjectTemplateInfo > data, DirectHandle< JSReceiver > new_target={})
static void AddAccessorProperty(Isolate *isolate, DirectHandle< TemplateInfoWithProperties > info, DirectHandle< Name > name, DirectHandle< FunctionTemplateInfo > getter, DirectHandle< FunctionTemplateInfo > setter, PropertyAttributes attributes)
static void AddNativeDataProperty(Isolate *isolate, DirectHandle< TemplateInfoWithProperties > info, DirectHandle< AccessorInfo > property)
static V8_EXPORT_PRIVATE DirectHandle< ArrayList > Add(Isolate *isolate, DirectHandle< ArrayList > array, Tagged< Smi > obj, AllocationType allocation=AllocationType::kYoung)
static DirectHandle< ArrayList > New(IsolateT *isolate, int capacity, AllocationType allocation=AllocationType::kYoung)
V8_WARN_UNUSED_RESULT Handle< JSFunction > Build()
static Handle< SharedFunctionInfo > GetOrCreateSharedFunctionInfo(Isolate *isolate, DirectHandle< FunctionTemplateInfo > info, MaybeDirectHandle< Name > maybe_name)
static void SetInitialMap(Isolate *isolate, DirectHandle< JSFunction > function, DirectHandle< Map > map, DirectHandle< JSPrototype > prototype)
static V8_EXPORT_PRIVATE void AddProperty(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
static V8_EXPORT_PRIVATE void MigrateSlowToFast(DirectHandle< JSObject > object, int unused_property_fields, const char *reason)
static void OptimizeAsPrototype(DirectHandle< JSObject > object, bool enable_setup_mode=true)
static V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT MaybeHandle< JSObject > New(DirectHandle< JSFunction > constructor, DirectHandle< JSReceiver > new_target, DirectHandle< AllocationSite > site, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
static void ForceSetPrototype(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< JSPrototype > proto)
static void SetImmutableProto(Isolate *isolate, DirectHandle< JSObject > object)
static V8_EXPORT_PRIVATE MaybeDirectHandle< Object > DefineOwnAccessorIgnoreAttributes(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > getter, DirectHandle< Object > setter, PropertyAttributes attributes)
static V8_EXPORT_PRIVATE void MigrateToMap(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< Map > new_map, int expected_additional_properties=0)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > SetAccessor(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< AccessorInfo > info, PropertyAttributes attributes)
static V8_EXPORT_PRIVATE int GetHeaderSize(InstanceType instance_type, bool function_has_prototype_slot=false)
static V8_WARN_UNUSED_RESULT Maybe< PropertyAttributes > GetPropertyAttributes(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > name)
static Handle< Map > Copy(Isolate *isolate, DirectHandle< Map > map, const char *reason, TransitionKindFlag kind=SPECIAL_TRANSITION)
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT Maybe< bool > AddDataProperty(LookupIterator *it, DirectHandle< Object > value, PropertyAttributes attributes, Maybe< ShouldThrow > should_throw, StoreOrigin store_origin, EnforceDefineSemantics semantics=EnforceDefineSemantics::kSet)
Tagged< Smi > AsSmi() const
static constexpr int ToInt(const Tagged< Object > object)
static constexpr Tagged< Smi > FromInt(int value)
static void CacheTemplateInstantiation(Isolate *isolate, DirectHandle< NativeContext > native_context, DirectHandle< TemplateInfo > info, CachingMode caching_mode, DirectHandle< Object > object)
static void UncacheTemplateInstantiation(Isolate *isolate, DirectHandle< NativeContext > native_context, DirectHandle< TemplateInfo > info, CachingMode caching_mode)
static MaybeHandle< ReturnType > ProbeInstantiationsCache(Isolate *isolate, DirectHandle< NativeContext > native_context, DirectHandle< TemplateInfo > info, CachingMode caching_mode)
#define RETURN_ON_EXCEPTION(isolate, call)
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
#define THROW_NEW_ERROR(isolate, call)
#define MAYBE_RETURN_NULL(call)
DirectHandle< Object > new_target
SharedFunctionInfoRef shared
ZoneVector< RpoNumber > & result
constexpr Vector< T > VectorOf(T *start, size_t size)
Map::Bits3::NumberOfOwnDescriptorsBits Map::Bits3::ConstructionCounterBits is_access_check_needed
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
bool TryCast(Tagged< From > value, Tagged< To > *out)
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
constexpr int kEmbedderDataSlotSize
Tagged(T object) -> Tagged< T >
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
@ TERMINAL_FAST_ELEMENTS_KIND
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
V8_EXPORT_PRIVATE FlagValues v8_flags
bool IsJSApiWrapperObject(Tagged< Map > map)
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset prototype
!IsContextMap !IsContextMap native_context
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Maybe< T > Just(const T &t)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
#define V8_INTRINSICS_LIST(F)