v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
api-natives.cc
Go to the documentation of this file.
1// Copyright 2015 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
6
7#include "src/api/api-inl.h"
12#include "src/heap/heap-inl.h"
15#include "src/objects/lookup.h"
17
18namespace v8 {
19namespace internal {
20
21namespace {
22
23class V8_NODISCARD InvokeScope {
24 public:
25 explicit InvokeScope(Isolate* isolate)
26 : isolate_(isolate), save_context_(isolate) {}
27 ~InvokeScope() {
28 bool has_exception = isolate_->has_exception();
29 if (has_exception) {
30 isolate_->ReportPendingMessages();
31 } else {
32 isolate_->clear_pending_message();
33 }
34 }
35
36 private:
37 Isolate* isolate_;
38 SaveContext save_context_;
39};
40
41MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
42 DirectHandle<ObjectTemplateInfo> data,
43 DirectHandle<JSReceiver> new_target,
44 bool is_prototype);
45
46MaybeHandle<JSFunction> InstantiateFunction(
47 Isolate* isolate, DirectHandle<NativeContext> native_context,
48 DirectHandle<FunctionTemplateInfo> data,
49 MaybeDirectHandle<Name> maybe_name = {});
50
51MaybeHandle<JSFunction> InstantiateFunction(
52 Isolate* isolate, DirectHandle<FunctionTemplateInfo> data,
53 MaybeDirectHandle<Name> maybe_name = {}) {
54 return InstantiateFunction(isolate, isolate->native_context(), data,
55 maybe_name);
56}
57
58MaybeDirectHandle<Object> Instantiate(Isolate* isolate,
59 DirectHandle<Object> data,
60 MaybeDirectHandle<Name> maybe_name = {}) {
61 if (IsFunctionTemplateInfo(*data)) {
62 return InstantiateFunction(isolate, Cast<FunctionTemplateInfo>(data),
63 maybe_name);
64 } else if (IsObjectTemplateInfo(*data)) {
65 return InstantiateObject(isolate, Cast<ObjectTemplateInfo>(data), {},
66 false);
67 } else {
68 return data;
69 }
70}
71
72MaybeDirectHandle<Object> DefineAccessorProperty(
73 Isolate* isolate, DirectHandle<JSObject> object, DirectHandle<Name> name,
74 DirectHandle<Object> getter, DirectHandle<Object> setter,
75 PropertyAttributes attributes) {
76 DCHECK_IMPLIES(IsFunctionTemplateInfo(*getter),
77 Cast<FunctionTemplateInfo>(*getter)->is_cacheable());
78 DCHECK_IMPLIES(IsFunctionTemplateInfo(*setter),
79 Cast<FunctionTemplateInfo>(*setter)->is_cacheable());
80 if (IsFunctionTemplateInfo(*getter) &&
81 Cast<FunctionTemplateInfo>(*getter)->BreakAtEntry(isolate)) {
83 isolate, getter,
84 InstantiateFunction(isolate, Cast<FunctionTemplateInfo>(getter)));
85 DirectHandle<Code> trampoline = BUILTIN_CODE(isolate, DebugBreakTrampoline);
86 Cast<JSFunction>(getter)->UpdateCode(*trampoline);
87 }
88 if (IsFunctionTemplateInfo(*setter) &&
89 Cast<FunctionTemplateInfo>(*setter)->BreakAtEntry(isolate)) {
91 isolate, setter,
92 InstantiateFunction(isolate, Cast<FunctionTemplateInfo>(setter)));
93 DirectHandle<Code> trampoline = BUILTIN_CODE(isolate, DebugBreakTrampoline);
94 Cast<JSFunction>(setter)->UpdateCode(*trampoline);
95 }
97 object, name, getter, setter, attributes));
98 return object;
99}
100
101MaybeDirectHandle<Object> DefineDataProperty(Isolate* isolate,
102 DirectHandle<JSObject> object,
103 DirectHandle<Name> name,
104 DirectHandle<Object> prop_data,
105 PropertyAttributes attributes) {
106 DirectHandle<Object> value;
107 ASSIGN_RETURN_ON_EXCEPTION(isolate, value,
108 Instantiate(isolate, prop_data, name));
109
110 PropertyKey key(isolate, name);
111 LookupIterator it(isolate, object, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
112
113#ifdef DEBUG
114 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
115 DCHECK(maybe.IsJust());
116 if (it.IsFound()) {
118 isolate,
119 NewTypeError(MessageTemplate::kDuplicateTemplateProperty, name));
120 }
121#endif
122
123 MAYBE_RETURN_NULL(Object::AddDataProperty(&it, value, attributes,
126 return value;
127}
128
129void DisableAccessChecks(Isolate* isolate, DirectHandle<JSObject> object) {
130 DirectHandle<Map> old_map(object->map(), isolate);
131 // Copy map so it won't interfere constructor's initial map.
132 DirectHandle<Map> new_map =
133 Map::Copy(isolate, old_map, "DisableAccessChecks");
134 new_map->set_is_access_check_needed(false);
135 JSObject::MigrateToMap(isolate, object, new_map);
136}
137
138void EnableAccessChecks(Isolate* isolate, DirectHandle<JSObject> object) {
139 DirectHandle<Map> old_map(object->map(), isolate);
140 // Copy map so it won't interfere constructor's initial map.
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);
144 JSObject::MigrateToMap(isolate, object, new_map);
145}
146
147class V8_NODISCARD AccessCheckDisableScope {
148 public:
149 AccessCheckDisableScope(Isolate* isolate, DirectHandle<JSObject> obj)
150 : isolate_(isolate),
151 disabled_(obj->map()->is_access_check_needed()),
152 obj_(obj) {
153 if (disabled_) {
154 DisableAccessChecks(isolate_, obj_);
155 }
156 }
157 ~AccessCheckDisableScope() {
158 if (disabled_) {
159 EnableAccessChecks(isolate_, obj_);
160 }
161 }
162
163 private:
164 Isolate* isolate_;
165 const bool disabled_;
166 DirectHandle<JSObject> obj_;
167};
168
169Tagged<Object> GetIntrinsic(Isolate* isolate, v8::Intrinsic intrinsic) {
170 DirectHandle<Context> native_context = isolate->native_context();
171 DCHECK(!native_context.is_null());
172 switch (intrinsic) {
173#define GET_INTRINSIC_VALUE(name, iname) \
174 case v8::k##name: \
175 return native_context->iname();
177#undef GET_INTRINSIC_VALUE
178 }
179 return Tagged<Object>();
180}
181
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);
187 // Disable access checks while instantiating the object.
188 AccessCheckDisableScope access_check_scope(isolate, obj);
189
190 // Walk the inheritance chain and copy all accessors to current object.
191 int max_number_of_properties = 0;
193 while (!info.is_null()) {
194 Tagged<Object> props = info->property_accessors();
195 if (!IsUndefined(props, isolate)) {
196 max_number_of_properties += Cast<ArrayList>(props)->length();
197 }
198 info = info->GetParent(isolate);
199 }
200
201 if (max_number_of_properties > 0) {
202 int valid_descriptors = 0;
203 // Use a temporary FixedArray to accumulate unique accessors.
204 DirectHandle<FixedArray> array =
205 isolate->factory()->NewFixedArray(max_number_of_properties);
206
207 // TODO(leszeks): Avoid creating unnecessary handles for cases where we
208 // don't need to append anything.
209 for (DirectHandle<TemplateInfoT> temp(*data, isolate); !(*temp).is_null();
210 temp = direct_handle(temp->GetParent(isolate), isolate)) {
211 // Accumulate accessors.
212 Tagged<Object> maybe_properties = temp->property_accessors();
213 if (!IsUndefined(maybe_properties, isolate)) {
214 valid_descriptors = AccessorInfo::AppendUnique(
215 isolate, direct_handle(maybe_properties, isolate), array,
216 valid_descriptors);
217 }
218 }
219
220 // Install accumulated accessors.
221 for (int i = 0; i < valid_descriptors; i++) {
222 DirectHandle<AccessorInfo> accessor(Cast<AccessorInfo>(array->get(i)),
223 isolate);
224 DirectHandle<Name> name(Cast<Name>(accessor->name()), isolate);
225 JSObject::SetAccessor(obj, name, accessor,
226 accessor->initial_property_attributes())
227 .Assert();
228 }
229 }
230
231 Tagged<Object> maybe_property_list = data->property_list();
232 if (IsUndefined(maybe_property_list, isolate)) return obj;
233 DirectHandle<ArrayList> properties(Cast<ArrayList>(maybe_property_list),
234 isolate);
235 if (properties->length() == 0) return obj;
236
237 int i = 0;
238 for (int c = 0; c < data->number_of_properties(); c++) {
239 auto name = direct_handle(Cast<Name>(properties->get(i++)), isolate);
240 Tagged<Object> bit = properties->get(i++);
241 if (IsSmi(bit)) {
242 PropertyDetails details(Cast<Smi>(bit));
243 PropertyAttributes attributes = details.attributes();
244 PropertyKind kind = details.kind();
245
246 if (kind == PropertyKind::kData) {
247 auto prop_data = handle(properties->get(i++), isolate);
248 RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name,
249 prop_data, attributes));
250 } else {
251 auto getter = direct_handle(properties->get(i++), isolate);
252 auto setter = direct_handle(properties->get(i++), isolate);
254 isolate, DefineAccessorProperty(isolate, obj, name, getter, setter,
255 attributes));
256 }
257 } else {
258 // Intrinsic data property --- Get appropriate value from the current
259 // context.
260 PropertyDetails details(Cast<Smi>(properties->get(i++)));
261 PropertyAttributes attributes = details.attributes();
262 DCHECK_EQ(PropertyKind::kData, details.kind());
263
264 v8::Intrinsic intrinsic =
265 static_cast<v8::Intrinsic>(Smi::ToInt(properties->get(i++)));
266 auto prop_data = handle(GetIntrinsic(isolate, intrinsic), isolate);
267
268 RETURN_ON_EXCEPTION(isolate, DefineDataProperty(isolate, obj, name,
269 prop_data, attributes));
270 }
271 }
272 return obj;
273}
274
275bool IsSimpleInstantiation(Isolate* isolate, Tagged<ObjectTemplateInfo> info,
278
279 if (!IsJSFunction(new_target)) return false;
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();
285}
286
287MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
288 DirectHandle<ObjectTemplateInfo> info,
289 DirectHandle<JSReceiver> new_target,
290 bool is_prototype) {
291 RCS_SCOPE(isolate, RuntimeCallCounterId::kInstantiateObject);
292 DirectHandle<JSFunction> constructor;
293 bool should_cache = info->is_cacheable();
294 if (!new_target.is_null()) {
295 if (IsSimpleInstantiation(isolate, *info, *new_target)) {
296 constructor = Cast<JSFunction>(new_target);
297 } else {
298 // Disable caching for subclass instantiation.
299 should_cache = false;
300 }
301 }
302 // Fast path.
304 if (should_cache) {
306 isolate, isolate->native_context(), info,
308 .ToHandle(&result)) {
309 return isolate->factory()->CopyJSObject(result);
310 }
311 }
312
313 if (constructor.is_null()) {
314 Tagged<Object> maybe_constructor_info = info->constructor();
315 if (IsUndefined(maybe_constructor_info, isolate)) {
316 constructor = isolate->object_function();
317 } else {
318 // Enter a new scope. Recursion could otherwise create a lot of handles.
319 HandleScope scope(isolate);
320 DirectHandle<FunctionTemplateInfo> cons_templ(
321 Cast<FunctionTemplateInfo>(maybe_constructor_info), isolate);
322 DirectHandle<JSFunction> tmp_constructor;
323 ASSIGN_RETURN_ON_EXCEPTION(isolate, tmp_constructor,
324 InstantiateFunction(isolate, cons_templ));
325 constructor = scope.CloseAndEscape(tmp_constructor);
326 }
327
328 if (new_target.is_null()) new_target = constructor;
329 }
330
331 const auto new_js_object_type =
332 constructor->has_initial_map() &&
333 IsJSApiWrapperObject(constructor->initial_map())
336 Handle<JSObject> object;
338 isolate, object,
339 JSObject::New(constructor, new_target, {}, new_js_object_type));
340
341 if (is_prototype) JSObject::OptimizeAsPrototype(object);
342
344 ConfigureInstance(isolate, object, info));
345 if (info->immutable_proto()) {
346 JSObject::SetImmutableProto(isolate, object);
347 }
348 if (!is_prototype) {
349 // Keep prototypes in slow-mode. Let them be lazily turned fast later on.
350 // TODO(dcarney): is this necessary?
351 JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject");
352 // Don't cache prototypes.
353 if (should_cache) {
355 isolate, isolate->native_context(), info,
357 result = isolate->factory()->CopyJSObject(result);
358 }
359 }
360
361 return result;
362}
363
364namespace {
365MaybeDirectHandle<Object> GetInstancePrototype(
366 Isolate* isolate, DirectHandle<Object> function_template) {
367 // Enter a new scope. Recursion could otherwise create a lot of handles.
368 HandleScope scope(isolate);
369 DirectHandle<JSFunction> parent_instance;
371 isolate, parent_instance,
372 InstantiateFunction(isolate,
373 Cast<FunctionTemplateInfo>(function_template)));
374 Handle<Object> instance_prototype;
375 // TODO(cbruni): decide what to do here.
377 isolate, instance_prototype,
378 JSObject::GetProperty(isolate, parent_instance,
379 isolate->factory()->prototype_string()));
380 return scope.CloseAndEscape(instance_prototype);
381}
382} // namespace
383
384MaybeHandle<JSFunction> InstantiateFunction(
385 Isolate* isolate, DirectHandle<NativeContext> native_context,
386 DirectHandle<FunctionTemplateInfo> info,
387 MaybeDirectHandle<Name> maybe_name) {
388 RCS_SCOPE(isolate, RuntimeCallCounterId::kInstantiateFunction);
389 bool should_cache = info->is_cacheable();
390 if (should_cache) {
393 isolate, native_context, info,
395 .ToHandle(&result)) {
396 return Cast<JSFunction>(result);
397 }
398 }
399 DirectHandle<Object> prototype;
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(
407 direct_handle(native_context->object_function(), isolate));
408 } else {
410 isolate, prototype,
411 GetInstancePrototype(isolate, protoype_provider_templ));
412 }
413 } else {
415 isolate, prototype,
416 InstantiateObject(isolate, Cast<ObjectTemplateInfo>(prototype_templ),
417 DirectHandle<JSReceiver>(), true));
418 }
419 DirectHandle<Object> parent(info->GetParentTemplate(), isolate);
420 if (!IsUndefined(*parent, isolate)) {
421 DirectHandle<Object> parent_prototype;
422 ASSIGN_RETURN_ON_EXCEPTION(isolate, parent_prototype,
423 GetInstancePrototype(isolate, parent));
424 DirectHandle<JSPrototype> checked_parent_prototype;
425 CHECK(TryCast(parent_prototype, &checked_parent_prototype));
427 checked_parent_prototype);
428 }
429 }
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));
438 }
439
441 isolate, native_context, info, prototype, function_type, maybe_name);
442 if (should_cache) {
443 // Cache the function.
446 function);
447 }
448 MaybeDirectHandle<JSObject> result =
449 ConfigureInstance(isolate, function, info);
450 if (result.is_null()) {
451 // Uncache on error.
454 return {};
455 }
456 info->set_published(true);
457 return function;
458}
459
460void AddPropertyToPropertyList(Isolate* isolate,
461 DirectHandle<TemplateInfoWithProperties> info,
462 base::Vector<DirectHandle<Object>> data) {
463 Tagged<Object> maybe_list = info->property_list();
464 DirectHandle<ArrayList> list;
465 if (IsUndefined(maybe_list, isolate)) {
466 list = ArrayList::New(isolate, static_cast<int>(data.size()),
468 } else {
469 list = direct_handle(Cast<ArrayList>(maybe_list), isolate);
470 }
471 info->set_number_of_properties(info->number_of_properties() + 1);
472 for (DirectHandle<Object> value : data) {
473 if (value.is_null())
474 value = Cast<Object>(isolate->factory()->undefined_value());
475 list = ArrayList::Add(isolate, list, value);
476 }
477 info->set_property_list(*list);
478}
479
480} // namespace
481
482// static
483DirectHandle<FunctionTemplateInfo>
485 Isolate* i_isolate, FunctionCallback callback, int length,
486 SideEffectType side_effect_type) {
487 // TODO(v8:5962): move FunctionTemplateNew() from api.cc here.
488 auto isolate = reinterpret_cast<v8::Isolate*>(i_isolate);
491 v8::ConstructorBehavior::kThrow, side_effect_type);
492 return Utils::OpenDirectHandle(*func_template);
493}
494
498 MaybeDirectHandle<Name> maybe_name) {
499 InvokeScope invoke_scope(isolate);
500 return ::v8::internal::InstantiateFunction(isolate, native_context, data,
501 maybe_name);
502}
503
506 MaybeDirectHandle<Name> maybe_name) {
507 InvokeScope invoke_scope(isolate);
508 return ::v8::internal::InstantiateFunction(isolate, data, maybe_name);
509}
510
514 InvokeScope invoke_scope(isolate);
515 return ::v8::internal::InstantiateObject(isolate, data, new_target, false);
516}
517
520 Isolate* isolate = data->GetIsolate();
521 InvokeScope invoke_scope(isolate);
522
524 Cast<FunctionTemplateInfo>(data->constructor()), isolate);
525 DirectHandle<Map> object_map = isolate->factory()->NewContextlessMap(
526 JS_SPECIAL_API_OBJECT_TYPE,
527 JSSpecialObject::kHeaderSize +
528 data->embedder_field_count() * kEmbedderDataSlotSize,
530 object_map->SetConstructor(*constructor);
531 object_map->set_is_access_check_needed(true);
532 object_map->set_may_have_interesting_properties(true);
533
534 Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(
537 JSObject::ForceSetPrototype(isolate, object,
538 isolate->factory()->null_value());
539
540 return object;
541}
542
547 PropertyAttributes attributes) {
548 PropertyDetails details(PropertyKind::kData, attributes,
550 DirectHandle<Object> data[] = {name, direct_handle(details.AsSmi(), isolate),
551 value};
552 AddPropertyToPropertyList(isolate, info, base::VectorOf(data));
553}
554
558 v8::Intrinsic intrinsic,
559 PropertyAttributes attributes) {
560 auto value = direct_handle(Smi::FromInt(intrinsic), isolate);
561 auto intrinsic_marker = isolate->factory()->true_value();
562 PropertyDetails details(PropertyKind::kData, attributes,
564 DirectHandle<Object> data[] = {
565 name, intrinsic_marker, direct_handle(details.AsSmi(), isolate), value};
566 AddPropertyToPropertyList(isolate, info, base::VectorOf(data));
567}
568
573 if (!getter.is_null()) getter->set_published(true);
574 if (!setter.is_null()) setter->set_published(true);
575 PropertyDetails details(PropertyKind::kAccessor, attributes,
577 DirectHandle<Object> data[] = {name, direct_handle(details.AsSmi(), isolate),
578 getter, setter};
579 AddPropertyToPropertyList(isolate, info, base::VectorOf(data));
580}
581
585 Tagged<Object> maybe_list = info->property_accessors();
587 if (IsUndefined(maybe_list, isolate)) {
588 list = ArrayList::New(isolate, 1, AllocationType::kOld);
589 } else {
590 list = direct_handle(Cast<ArrayList>(maybe_list), isolate);
591 }
592 list = ArrayList::Add(isolate, list, property);
593 info->set_property_accessors(*list);
594}
595
599 InstanceType type, MaybeDirectHandle<Name> maybe_name) {
600 RCS_SCOPE(isolate, RuntimeCallCounterId::kCreateApiFunction);
603 maybe_name);
604 // To simplify things, API functions always have shared name.
605 DCHECK(shared->HasSharedName());
606
609
610 if (obj->remove_prototype()) {
611 DCHECK(prototype.is_null());
612 DCHECK(result->shared()->IsApiFunction());
613 DCHECK(!IsConstructor(*result));
614 DCHECK(!result->has_prototype_slot());
615 return result;
616 }
617
618 // Down from here is only valid for API functions that can be used as a
619 // constructor (don't set the "remove prototype" flag).
620 DCHECK(result->has_prototype_slot());
621
622 if (obj->read_only_prototype()) {
623 result->set_map(isolate,
624 *isolate->sloppy_function_with_readonly_prototype_map());
625 }
626
627 if (IsTheHole(*prototype, isolate)) {
628 prototype = isolate->factory()->NewFunctionPrototype(result);
629 } else if (IsUndefined(obj->GetPrototypeProviderTemplate(), isolate)) {
630 JSObject::AddProperty(isolate, Cast<JSObject>(prototype),
631 isolate->factory()->constructor_string(), result,
632 DONT_ENUM);
633 }
634
635 int embedder_field_count = 0;
636 bool immutable_proto = false;
637 if (!IsUndefined(obj->GetInstanceTemplate(), isolate)) {
638 DirectHandle<ObjectTemplateInfo> GetInstanceTemplate(
639 Cast<ObjectTemplateInfo>(obj->GetInstanceTemplate()), isolate);
640 embedder_field_count = GetInstanceTemplate->embedder_field_count();
641 immutable_proto = GetInstanceTemplate->immutable_proto();
642 }
643
644 // JSFunction requires information about the prototype slot.
645 DCHECK(!InstanceTypeChecker::IsJSFunction(type));
646 int instance_size = JSObject::GetHeaderSize(type) +
647 kEmbedderDataSlotSize * embedder_field_count;
648
649 DirectHandle<Map> map = isolate->factory()->NewContextfulMap(
650 native_context, type, instance_size, TERMINAL_FAST_ELEMENTS_KIND);
651
652 // Mark as undetectable if needed.
653 if (obj->undetectable()) {
654 // We only allow callable undetectable receivers here, since this whole
655 // undetectable business is only to support document.all, which is both
656 // undetectable and callable. If we ever see the need to have an object
657 // that is undetectable but not callable, we need to update the types.h
658 // to allow encoding this.
659 CHECK(!IsUndefined(obj->GetInstanceCallHandler(), isolate));
660
661 if (Protectors::IsNoUndetectableObjectsIntact(isolate)) {
662 Protectors::InvalidateNoUndetectableObjects(isolate);
663 }
664 map->set_is_undetectable(true);
665 }
666
667 // Mark as needs_access_check if needed.
668 if (obj->needs_access_check()) {
669 map->set_is_access_check_needed(true);
670 map->set_may_have_interesting_properties(true);
671 }
672
673 // Set interceptor information in the map.
674 if (!IsUndefined(obj->GetNamedPropertyHandler(), isolate)) {
675 map->set_has_named_interceptor(true);
676 map->set_may_have_interesting_properties(true);
677 }
678 if (!IsUndefined(obj->GetIndexedPropertyHandler(), isolate)) {
679 map->set_has_indexed_interceptor(true);
680 }
681
682 // Mark instance as callable in the map.
683 if (!IsUndefined(obj->GetInstanceCallHandler(), isolate)) {
684 map->set_is_callable(true);
685 map->set_is_constructor(!obj->undetectable());
686 }
687
688 if (immutable_proto) map->set_is_immutable_proto(true);
689
690 JSFunction::SetInitialMap(isolate, result, map, Cast<JSObject>(prototype));
691 return result;
692}
693
694} // namespace internal
695} // namespace v8
const bool disabled_
SaveContext save_context_
Isolate * isolate_
#define GET_INTRINSIC_VALUE(name, iname)
DirectHandle< JSObject > obj_
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
Builtins::Kind kind
Definition builtins.cc:40
#define BUILTIN_CODE(isolate, name)
Definition builtins.h:45
PropertyT * getter
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)
Definition api.cc:1101
static v8::internal::DirectHandle< To > OpenDirectHandle(v8::Local< From > handle)
Definition api.h:279
static int AppendUnique(Isolate *isolate, DirectHandle< Object > descriptors, DirectHandle< FixedArray > array, int valid_descriptors)
Definition objects.cc:2841
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()
Definition factory.cc:4732
static Handle< SharedFunctionInfo > GetOrCreateSharedFunctionInfo(Isolate *isolate, DirectHandle< FunctionTemplateInfo > info, MaybeDirectHandle< Name > maybe_name)
Definition templates.cc:32
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)
Definition map.cc:1811
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)
Definition objects.cc:2667
Tagged< Smi > AsSmi() const
Definition objects-inl.h:79
static constexpr int ToInt(const Tagged< Object > object)
Definition smi.h:33
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
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)
Definition templates.h:70
#define RETURN_ON_EXCEPTION(isolate, call)
Definition isolate.h:395
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:291
#define THROW_NEW_ERROR(isolate, call)
Definition isolate.h:307
#define MAYBE_RETURN_NULL(call)
Definition isolate.h:413
DirectHandle< Object > new_target
Definition execution.cc:75
Isolate * isolate
SharedFunctionInfoRef shared
TNode< Object > callback
ZoneVector< RpoNumber > & result
constexpr Vector< T > VectorOf(T *start, size_t size)
Definition vector.h:360
Map::Bits3::NumberOfOwnDescriptorsBits Map::Bits3::ConstructionCounterBits is_access_check_needed
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
bool TryCast(Tagged< From > value, Tagged< To > *out)
Definition casting.h:77
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
constexpr int kEmbedderDataSlotSize
Definition globals.h:664
Tagged(T object) -> Tagged< T >
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:665
@ 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
Definition flags.cc:2086
V8_EXPORT_PRIVATE FlagValues v8_flags
return value
Definition map-inl.h:893
bool IsJSApiWrapperObject(Tagged< Map > map)
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset prototype
Definition map-inl.h:69
!IsContextMap !IsContextMap native_context
Definition map-inl.h:877
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
Local< T > Handle
SideEffectType
Definition v8-object.h:198
Intrinsic
Definition v8-template.h:41
void(*)(const FunctionCallbackInfo< Value > &info) FunctionCallback
Maybe< T > Just(const T &t)
Definition v8-maybe.h:117
#define RCS_SCOPE(...)
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_INTRINSICS_LIST(F)
Definition v8-template.h:28
#define V8_NODISCARD
Definition v8config.h:693