24bool GetPropertyIfPresent(Isolate* isolate, DirectHandle<JSReceiver>
receiver,
30 if (has_property.IsNothing())
return false;
32 if (has_property.FromJust() ==
true) {
44bool ToPropertyDescriptorFastPath(Isolate* isolate,
45 DirectHandle<JSReceiver> obj,
46 PropertyDescriptor* desc) {
50 if (!IsJSObject(*raw_obj))
return false;
51 Tagged<Map> raw_map = raw_obj->map(isolate);
52 if (raw_map->instance_type() != JS_OBJECT_TYPE)
return false;
53 if (raw_map->is_access_check_needed())
return false;
54 if (raw_map->prototype() != *isolate->initial_object_prototype())
58 if (isolate->bootstrapper()->IsActive())
return false;
60 isolate->raw_native_context()->object_function_prototype_map()) {
64 if (raw_map->is_dictionary_map())
return false;
67 DirectHandle<Map>
map(obj->map(isolate), isolate);
69 DirectHandle<DescriptorArray> descs(map->instance_descriptors(isolate),
71 ReadOnlyRoots roots(isolate);
72 for (InternalIndex
i : map->IterateOwnDescriptors()) {
73 PropertyDetails details = descs->GetDetails(
i);
74 DirectHandle<Object>
value;
78 details.representation(),
97 if (
key == roots.enumerable_string()) {
99 }
else if (
key == roots.configurable_string()) {
101 }
else if (
key == roots.value_string()) {
103 }
else if (
key == roots.writable_string()) {
105 }
else if (
key == roots.get_string()) {
107 if (!IsCallable(*value))
return false;
109 }
else if (
key == roots.set_string()) {
111 if (!IsCallable(*value))
return false;
115 if ((desc->has_get() || desc->has_set()) &&
116 (desc->has_value() || desc->has_writable())) {
123void CreateDataProperty(Isolate* isolate, DirectHandle<JSObject>
object,
124 Handle<String> name, DirectHandle<Object> value) {
126 isolate,
object, PropertyKey(isolate,
Cast<Name>(name)), value);
136 Factory* factory = isolate->factory();
140 isolate->accessor_property_descriptor_map());
141 result->InObjectPropertyAtPut(JSAccessorPropertyDescriptor::kGetIndex,
145 result->InObjectPropertyAtPut(
148 result->InObjectPropertyAtPut(
157 result->InObjectPropertyAtPut(JSDataPropertyDescriptor::kValueIndex,
160 isolate->heap()->ToBoolean(
writable()));
170 CreateDataProperty(isolate,
result, factory->value_string(), value());
173 CreateDataProperty(isolate,
result, factory->writable_string(),
177 CreateDataProperty(isolate,
result, factory->get_string(), get());
180 CreateDataProperty(isolate,
result, factory->set_string(), set());
183 CreateDataProperty(isolate,
result, factory->enumerable_string(),
187 CreateDataProperty(isolate,
result, factory->configurable_string(),
201 if (!IsJSReceiver(*obj)) {
202 isolate->Throw(*isolate->factory()->NewTypeError(
203 MessageTemplate::kPropertyDescObject, obj));
210 if (ToPropertyDescriptorFastPath(isolate,
receiver, desc)) {
217 if (!GetPropertyIfPresent(isolate,
receiver,
218 isolate->factory()->enumerable_string(),
230 if (!GetPropertyIfPresent(isolate,
receiver,
231 isolate->factory()->configurable_string(),
243 if (!GetPropertyIfPresent(isolate,
receiver,
244 isolate->factory()->value_string(), &value)) {
248 if (!value.is_null()) desc->set_value(value);
253 if (!GetPropertyIfPresent(isolate,
receiver,
254 isolate->factory()->writable_string(), &
writable)) {
264 if (!GetPropertyIfPresent(isolate,
receiver, isolate->factory()->get_string(),
271 if (!IsCallable(*
getter) && !IsUndefined(*
getter, isolate)) {
272 isolate->Throw(*isolate->factory()->NewTypeError(
273 MessageTemplate::kObjectGetterCallable,
getter));
282 if (!GetPropertyIfPresent(isolate,
receiver, isolate->factory()->set_string(),
289 if (!IsCallable(*
setter) && !IsUndefined(*
setter, isolate)) {
290 isolate->Throw(*isolate->factory()->NewTypeError(
291 MessageTemplate::kObjectSetterCallable,
setter));
301 if ((desc->has_get() || desc->has_set()) &&
302 (desc->has_value() || desc->has_writable())) {
303 isolate->Throw(*isolate->factory()->NewTypeError(
304 MessageTemplate::kValueAndAccessor, obj));
327 if (!desc->has_value()) {
328 desc->set_value(isolate->factory()->undefined_value());
332 if (!desc->has_writable()) desc->set_writable(
false);
337 if (!desc->has_get()) {
338 desc->set_get(isolate->factory()->undefined_value());
342 if (!desc->has_set()) {
343 desc->set_set(isolate->factory()->undefined_value());
348 if (!desc->has_enumerable()) desc->set_enumerable(
false);
351 if (!desc->has_configurable()) desc->set_configurable(
false);
358 isolate->factory()->NewPropertyDescriptorObject();
361 PropertyDescriptorObject::IsEnumerableBit::encode(
enumerable_) |
363 PropertyDescriptorObject::IsConfigurableBit::encode(
configurable_) |
365 PropertyDescriptorObject::IsWritableBit::encode(
writable_) |
366 PropertyDescriptorObject::HasWritableBit::encode(
has_writable_) |
367 PropertyDescriptorObject::HasValueBit::encode(
has_value()) |
368 PropertyDescriptorObject::HasGetBit::encode(
has_get()) |
369 PropertyDescriptorObject::HasSetBit::encode(
has_set());
371 obj->set_flags(flags);
Handle< Boolean > ToBoolean(bool value)
Handle< JSObject > NewJSObject(DirectHandle< JSFunction > constructor, AllocationType allocation=AllocationType::kYoung, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
Handle< JSObject > NewJSObjectFromMap(DirectHandle< Map > map, AllocationType allocation=AllocationType::kYoung, DirectHandle< AllocationSite > allocation_site=DirectHandle< AllocationSite >::null(), NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
static FieldIndex ForDetails(Tagged< Map > map, PropertyDetails details)
static const int kSetIndex
static const int kEnumerableIndex
static const int kConfigurableIndex
static const int kWritableIndex
static const int kConfigurableIndex
static const int kEnumerableIndex
static Handle< JSAny > FastPropertyAt(Isolate *isolate, DirectHandle< JSObject > object, Representation representation, FieldIndex index)
static V8_WARN_UNUSED_RESULT Maybe< bool > CreateDataProperty(Isolate *isolate, DirectHandle< JSObject > object, PropertyKey key, DirectHandle< Object > value, Maybe< ShouldThrow > should_throw=Just(kDontThrow))
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT Maybe< bool > HasProperty(LookupIterator *it)
static V8_EXPORT_PRIVATE bool BooleanValue(Tagged< Object > obj, IsolateT *isolate)
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it, bool is_global_reference=false)
bool IsRegularDataProperty() const
bool has_writable() const
static bool IsAccessorDescriptor(PropertyDescriptor *desc)
Handle< JSAny > value() const
Handle< UnionOf< JSAny, FunctionTemplateInfo > > get() const
static void CompletePropertyDescriptor(Isolate *isolate, PropertyDescriptor *desc)
static bool ToPropertyDescriptor(Isolate *isolate, Handle< JSAny > obj, PropertyDescriptor *desc)
bool configurable() const
bool has_configurable() const
Handle< UnionOf< JSAny, FunctionTemplateInfo > > set() const
static bool IsDataDescriptor(PropertyDescriptor *desc)
bool has_enumerable() const
IndirectHandle< JSAny > value_
DirectHandle< JSObject > ToObject(Isolate *isolate)
bool IsRegularAccessorProperty() const
DirectHandle< PropertyDescriptorObject > ToPropertyDescriptorObject(Isolate *isolate)
IndirectHandle< UnionOf< JSAny, FunctionTemplateInfo > > get_
IndirectHandle< UnionOf< JSAny, FunctionTemplateInfo > > set_
ZoneVector< RpoNumber > & result
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
Tagged(T object) -> Tagged< T >
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)