Commit bb23bccb authored by verwaest's avatar verwaest Committed by Commit bot

Support CreateDataProperty on JSObject in the runtime

BUG=v8:4137
LOG=n

Review URL: https://codereview.chromium.org/1181013011

Cr-Commit-Position: refs/heads/master@{#29080}
parent 5fca3947
......@@ -3503,43 +3503,16 @@ Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
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;
}
......@@ -3548,37 +3521,14 @@ Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
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;
}
......
......@@ -4301,6 +4301,27 @@ MaybeHandle<Object> JSObject::DefinePropertyOrElementIgnoreAttributes(
}
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();
......
......@@ -1864,6 +1864,11 @@ class JSObject: public JSReceiver {
PropertyAttributes attributes = NONE,
ExecutableAccessorInfoHandling handling = DEFAULT_HANDLING);
// Adds or reconfigures a property to attributes NONE. It will fail when it
// cannot.
MUST_USE_RESULT static Maybe<bool> CreateDataProperty(LookupIterator* it,
Handle<Object> value);
static void AddProperty(Handle<JSObject> object, Handle<Name> name,
Handle<Object> value, PropertyAttributes attributes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment