v8::Local<Value> value) {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()",
bool);
- auto self = Utils::OpenHandle(this);
- auto key_obj = Utils::OpenHandle(*key);
- auto value_obj = Utils::OpenHandle(*value);
-
- if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) {
- isolate->ReportFailedAccessCheck(self);
- return Nothing<bool>();
- }
-
- if (!self->IsExtensible()) return Just(false);
-
- uint32_t index = 0;
- if (key_obj->AsArrayIndex(&index)) {
- return CreateDataProperty(context, index, value);
- }
-
- // Special case for Array.length.
- if (self->IsJSArray() &&
- key->StrictEquals(Utils::ToLocal(isolate->factory()->length_string()))) {
- // Length is not configurable, however, CreateDataProperty always attempts
- // to create a configurable property, so we just fail here.
- return Just(false);
- }
-
- i::LookupIterator it(self, key_obj, i::LookupIterator::OWN_SKIP_INTERCEPTOR);
- if (it.IsFound() && it.state() == i::LookupIterator::ACCESS_CHECK) {
- DCHECK(isolate->MayAccess(self));
- it.Next();
- }
-
- if (it.IsFound() && !it.IsConfigurable()) return Just(false);
+ i::Handle<i::JSObject> self = Utils::OpenHandle(this);
+ i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
+ i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
- has_pending_exception = i::JSObject::SetOwnPropertyIgnoreAttributes(
- self, key_obj, value_obj, NONE,
- i::JSObject::DONT_FORCE_FIELD).is_null();
+ i::LookupIterator it = i::LookupIterator::PropertyOrElement(
+ isolate, self, key_obj, i::LookupIterator::OWN);
+ Maybe<bool> result = i::JSObject::CreateDataProperty(&it, value_obj);
+ has_pending_exception = result.IsNothing();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
- return Just(true);
+ return result;
}
v8::Local<Value> value) {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()",
bool);
- auto self = Utils::OpenHandle(this);
- auto value_obj = Utils::OpenHandle(*value);
-
- if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) {
- isolate->ReportFailedAccessCheck(self);
- return Nothing<bool>();
- }
-
- if (!self->IsExtensible()) return Just(false);
-
- if (self->IsJSArray()) {
- size_t length =
- i::NumberToSize(isolate, i::Handle<i::JSArray>::cast(self)->length());
- if (index >= length) {
- return DefineOwnProperty(
- context, Utils::ToLocal(isolate->factory()->Uint32ToString(index)),
- value, v8::None);
- }
- }
-
- Maybe<PropertyAttributes> attributes =
- i::JSReceiver::GetOwnElementAttributes(self, index);
- if (attributes.IsJust() && attributes.FromJust() & DONT_DELETE) {
- return Just(false);
- }
+ i::Handle<i::JSObject> self = Utils::OpenHandle(this);
+ i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
- has_pending_exception = i::JSObject::SetOwnElementIgnoreAttributes(
- self, index, value_obj, NONE,
- i::JSObject::DONT_FORCE_FIELD).is_null();
+ i::LookupIterator it(isolate, self, index, i::LookupIterator::OWN);
+ Maybe<bool> result = i::JSObject::CreateDataProperty(&it, value_obj);
+ has_pending_exception = result.IsNothing();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
- return Just(true);
+ return result;
}
}
+Maybe<bool> JSObject::CreateDataProperty(LookupIterator* it,
+ Handle<Object> value) {
+ DCHECK(it->GetReceiver()->IsJSObject());
+ Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(it);
+ if (maybe.IsNothing()) return Nothing<bool>();
+
+ if (it->IsFound()) {
+ if (!it->IsConfigurable()) return Just(false);
+ } else {
+ if (!JSObject::cast(*it->GetReceiver())->IsExtensible()) return Just(false);
+ }
+
+ RETURN_ON_EXCEPTION_VALUE(
+ it->isolate(),
+ DefineOwnPropertyIgnoreAttributes(it, value, NONE, DONT_FORCE_FIELD),
+ Nothing<bool>());
+
+ return Just(true);
+}
+
+
Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithInterceptor(
LookupIterator* it) {
Isolate* isolate = it->isolate();