Commit d9c3867a authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[objects] Add CreateDataProperty helper

Similar to existings helpers like SetProperty,
WriteToReadOnlyProperty, etc, this create an helper for
CreateDataProperty that abstracts away the LookupIterator.

Bug: v8:5751
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I5ca02a2bad982adf233f3ea9de799e5706cd248a
Reviewed-on: https://chromium-review.googlesource.com/1156400Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54832}
parent 39519475
......@@ -4341,10 +4341,8 @@ Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
i::LookupIterator it = i::LookupIterator::PropertyOrElement(
isolate, self, key_obj, self, i::LookupIterator::OWN);
Maybe<bool> result =
i::JSReceiver::CreateDataProperty(&it, value_obj, i::kDontThrow);
Maybe<bool> result = i::JSReceiver::CreateDataProperty(
isolate, self, key_obj, value_obj, i::kDontThrow);
has_pending_exception = result.IsNothing();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return result;
......
......@@ -394,10 +394,8 @@ BUILTIN(ObjectGetOwnPropertyDescriptors) {
if (!did_get_descriptor.FromJust()) continue;
Handle<Object> from_descriptor = descriptor.ToObject(isolate);
LookupIterator it = LookupIterator::PropertyOrElement(
isolate, descriptors, key, descriptors, LookupIterator::OWN);
Maybe<bool> success =
JSReceiver::CreateDataProperty(&it, from_descriptor, kDontThrow);
Maybe<bool> success = JSReceiver::CreateDataProperty(
isolate, descriptors, key, from_descriptor, kDontThrow);
CHECK(success.FromJust());
}
......
......@@ -7393,6 +7393,16 @@ Maybe<bool> JSReceiver::ValidateAndApplyPropertyDescriptor(
return Just(true);
}
// static
Maybe<bool> JSReceiver::CreateDataProperty(Isolate* isolate,
Handle<JSReceiver> object,
Handle<Name> key,
Handle<Object> value,
ShouldThrow should_throw) {
LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, key,
LookupIterator::OWN);
return CreateDataProperty(&it, value, should_throw);
}
// static
Maybe<bool> JSReceiver::CreateDataProperty(LookupIterator* it,
......
......@@ -2097,6 +2097,9 @@ class JSReceiver : public HeapObject, public NeverReadOnlySpaceObject {
PropertyDescriptor* desc, ShouldThrow should_throw);
// ES6 7.3.4 (when passed kDontThrow)
V8_WARN_UNUSED_RESULT static Maybe<bool> CreateDataProperty(
Isolate* isolate, Handle<JSReceiver> object, Handle<Name> key,
Handle<Object> value, ShouldThrow should_throw);
V8_WARN_UNUSED_RESULT static Maybe<bool> CreateDataProperty(
LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
......
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