Commit 5676415b authored by jkummerow's avatar jkummerow Committed by Commit bot

Introduce LookupIterator::Restart() and use it

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

Cr-Commit-Position: refs/heads/master@{#31483}
parent 9a594e78
......@@ -80,13 +80,13 @@ void LookupIterator::Next() {
}
void LookupIterator::RestartLookupForNonMaskingInterceptors() {
interceptor_state_ = InterceptorState::kProcessNonMasking;
void LookupIterator::RestartInternal(InterceptorState interceptor_state) {
state_ = NOT_FOUND;
interceptor_state_ = interceptor_state;
property_details_ = PropertyDetails::Empty();
number_ = DescriptorArray::kNotFound;
holder_ = initial_holder_;
holder_map_ = handle(holder_->map(), isolate_);
number_ = DescriptorArray::kNotFound;
Next();
}
......
......@@ -162,6 +162,8 @@ class LookupIterator final BASE_EMBEDDED {
Isolate* isolate, Handle<Object> receiver, Handle<Object> key,
bool* success, Configuration configuration = DEFAULT);
void Restart() { RestartInternal(InterceptorState::kUninitialized); }
Isolate* isolate() const { return isolate_; }
State state() const { return state_; }
......@@ -260,7 +262,10 @@ class LookupIterator final BASE_EMBEDDED {
MUST_USE_RESULT inline JSReceiver* NextHolder(Map* map);
inline State LookupInHolder(Map* map, JSReceiver* holder);
void RestartLookupForNonMaskingInterceptors();
void RestartLookupForNonMaskingInterceptors() {
RestartInternal(InterceptorState::kProcessNonMasking);
}
void RestartInternal(InterceptorState interceptor_state);
State LookupNonMaskingInterceptorInHolder(Map* map, JSReceiver* holder);
Handle<Object> FetchValue() const;
void ReloadPropertyInformation();
......
......@@ -6054,8 +6054,8 @@ bool JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
return false;
}
// 3. Let extensible be the value of the [[Extensible]] internal slot of O.
Handle<JSObject> o = Handle<JSObject>::cast(it->GetReceiver());
bool extensible = JSObject::IsExtensible(o);
Handle<JSObject> object = Handle<JSObject>::cast(it->GetReceiver());
bool extensible = JSObject::IsExtensible(object);
bool desc_is_data_descriptor = PropertyDescriptor::IsDataDescriptor(desc);
bool desc_is_accessor_descriptor =
......@@ -6074,12 +6074,12 @@ bool JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
}
return false;
}
// We have to use a fresh LookupIterator to handle interceptors properly.
LookupIterator lookup_for_store =
it->IsElement() ? LookupIterator(isolate, it->GetReceiver(),
it->index(), LookupIterator::HIDDEN)
: LookupIterator(it->GetReceiver(), it->name(),
LookupIterator::HIDDEN);
// We have to reset the LookupIterator to handle interceptors properly.
Map* map = Handle<HeapObject>::cast(object)->map();
if ((it->IsElement() && map->has_indexed_interceptor()) ||
(!it->IsElement() && map->has_named_interceptor())) {
it->Restart();
}
// 2c. If IsGenericDescriptor(Desc) or IsDataDescriptor(Desc) is true, then:
// (This is equivalent to !IsAccessorDescriptor(desc).)
......@@ -6091,7 +6091,7 @@ bool JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
// [[Configurable]] attribute values are described by Desc. If the value
// of an attribute field of Desc is absent, the attribute of the newly
// created property is set to its default value.
if (!o->IsUndefined()) {
if (!object->IsUndefined()) {
if (!desc->has_writable()) desc->set_writable(false);
if (!desc->has_enumerable()) desc->set_enumerable(false);
if (!desc->has_configurable()) desc->set_configurable(false);
......@@ -6101,8 +6101,7 @@ bool JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
: Handle<Object>::cast(isolate->factory()->undefined_value()));
MaybeHandle<Object> result =
JSObject::DefineOwnPropertyIgnoreAttributes(
&lookup_for_store, value, desc->ToAttributes(),
JSObject::DONT_FORCE_FIELD);
it, value, desc->ToAttributes(), JSObject::DONT_FORCE_FIELD);
if (result.is_null()) return false;
}
} else {
......@@ -6113,7 +6112,7 @@ bool JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
// [[Configurable]] attribute values are described by Desc. If the value
// of an attribute field of Desc is absent, the attribute of the newly
// created property is set to its default value.
if (!o->IsUndefined()) {
if (!object->IsUndefined()) {
if (!desc->has_enumerable()) desc->set_enumerable(false);
if (!desc->has_configurable()) desc->set_configurable(false);
Handle<Object> getter(
......@@ -6124,8 +6123,8 @@ bool JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
desc->has_set()
? desc->set()
: Handle<Object>::cast(isolate->factory()->undefined_value()));
MaybeHandle<Object> result = JSObject::DefineAccessor(
&lookup_for_store, getter, setter, desc->ToAttributes());
MaybeHandle<Object> result =
JSObject::DefineAccessor(it, getter, setter, desc->ToAttributes());
if (result.is_null()) return false;
}
}
......@@ -6213,10 +6212,11 @@ bool JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
// [Strong mode] Disallow changing writable -> readonly for
// non-configurable properties.
if (current.writable() && desc->has_writable() && !desc->writable() &&
o->map()->is_strong()) {
object->map()->is_strong()) {
if (should_throw == THROW_ON_ERROR) {
isolate->Throw(*isolate->factory()->NewTypeError(
MessageTemplate::kStrongRedefineDisallowed, o, it->GetName()));
MessageTemplate::kStrongRedefineDisallowed, object,
it->GetName()));
}
return false;
}
......@@ -6271,7 +6271,7 @@ bool JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
}
// 10. If O is not undefined, then:
if (!o->IsUndefined()) {
if (!object->IsUndefined()) {
// 10a. For each field of Desc that is present, set the corresponding
// attribute of the property named P of object O to the value of the field.
PropertyAttributes attrs = NONE;
......
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