Commit 41775a3e authored by jkummerow's avatar jkummerow Committed by Commit bot

Fix HasProperty/HasElement for Proxies on the prototype chain

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

Cr-Commit-Position: refs/heads/master@{#31775}
parent 41f3e782
...@@ -7274,27 +7274,17 @@ MaybeHandle<Object> Object::GetPropertyOrElement(Handle<JSReceiver> holder, ...@@ -7274,27 +7274,17 @@ MaybeHandle<Object> Object::GetPropertyOrElement(Handle<JSReceiver> holder,
Maybe<bool> JSReceiver::HasProperty(Handle<JSReceiver> object, Maybe<bool> JSReceiver::HasProperty(Handle<JSReceiver> object,
Handle<Name> name) { Handle<Name> name) {
// Call the "has" trap on proxies. LookupIterator it =
if (object->IsJSProxy()) { LookupIterator::PropertyOrElement(object->GetIsolate(), object, name);
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object); return HasProperty(&it);
return JSProxy::HasPropertyWithHandler(proxy, name);
}
Maybe<PropertyAttributes> result = GetPropertyAttributes(object, name);
return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
} }
Maybe<bool> JSReceiver::HasOwnProperty(Handle<JSReceiver> object, Maybe<bool> JSReceiver::HasOwnProperty(Handle<JSReceiver> object,
Handle<Name> name) { Handle<Name> name) {
// Call the "has" trap on proxies. LookupIterator it = LookupIterator::PropertyOrElement(
if (object->IsJSProxy()) { object->GetIsolate(), object, name, LookupIterator::HIDDEN);
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object); return HasProperty(&it);
return JSProxy::HasPropertyWithHandler(proxy, name);
}
Maybe<PropertyAttributes> result = GetOwnPropertyAttributes(object, name);
return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
} }
...@@ -7315,31 +7305,16 @@ Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes( ...@@ -7315,31 +7305,16 @@ Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes(
Maybe<bool> JSReceiver::HasElement(Handle<JSReceiver> object, uint32_t index) { Maybe<bool> JSReceiver::HasElement(Handle<JSReceiver> object, uint32_t index) {
// Call the "has" trap on proxies. LookupIterator it(object->GetIsolate(), object, index);
if (object->IsJSProxy()) { return HasProperty(&it);
Isolate* isolate = object->GetIsolate();
Handle<Name> name = isolate->factory()->Uint32ToString(index);
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
return JSProxy::HasPropertyWithHandler(proxy, name);
}
Maybe<PropertyAttributes> result = GetElementAttributes(object, index);
return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
} }
Maybe<bool> JSReceiver::HasOwnElement(Handle<JSReceiver> object, Maybe<bool> JSReceiver::HasOwnElement(Handle<JSReceiver> object,
uint32_t index) { uint32_t index) {
// Call the "has" trap on proxies. LookupIterator it(object->GetIsolate(), object, index,
if (object->IsJSProxy()) { LookupIterator::HIDDEN);
Isolate* isolate = object->GetIsolate(); return HasProperty(&it);
Handle<Name> name = isolate->factory()->Uint32ToString(index);
Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
return JSProxy::HasPropertyWithHandler(proxy, name);
}
Maybe<PropertyAttributes> result = GetOwnElementAttributes(object, index);
return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
} }
......
...@@ -641,6 +641,44 @@ MaybeHandle<Object> Object::GetMethod(Handle<JSReceiver> receiver, ...@@ -641,6 +641,44 @@ MaybeHandle<Object> Object::GetMethod(Handle<JSReceiver> receiver,
} }
// static
Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) {
for (; it->IsFound(); it->Next()) {
switch (it->state()) {
case LookupIterator::NOT_FOUND:
case LookupIterator::TRANSITION:
UNREACHABLE();
case LookupIterator::JSPROXY:
// Call the "has" trap on proxies.
return JSProxy::HasPropertyWithHandler(it->GetHolder<JSProxy>(),
it->GetName());
case LookupIterator::INTERCEPTOR: {
Maybe<PropertyAttributes> result =
JSObject::GetPropertyAttributesWithInterceptor(it);
if (!result.IsJust()) return Nothing<bool>();
if (result.FromJust() != ABSENT) return Just(true);
break;
}
case LookupIterator::ACCESS_CHECK: {
if (it->HasAccess()) break;
Maybe<PropertyAttributes> result =
JSObject::GetPropertyAttributesWithFailedAccessCheck(it);
if (!result.IsJust()) return Nothing<bool>();
return Just(result.FromJust() != ABSENT);
}
case LookupIterator::INTEGER_INDEXED_EXOTIC:
// TypedArray out-of-bounds access.
return Just(false);
case LookupIterator::ACCESSOR:
case LookupIterator::DATA:
return Just(true);
}
}
return Just(false);
}
// static
MaybeHandle<Object> Object::GetProperty(LookupIterator* it, MaybeHandle<Object> Object::GetProperty(LookupIterator* it,
LanguageMode language_mode) { LanguageMode language_mode) {
for (; it->IsFound(); it->Next()) { for (; it->IsFound(); it->Next()) {
...@@ -14852,9 +14890,7 @@ Maybe<bool> JSObject::HasRealNamedProperty(Handle<JSObject> object, ...@@ -14852,9 +14890,7 @@ Maybe<bool> JSObject::HasRealNamedProperty(Handle<JSObject> object,
Handle<Name> name) { Handle<Name> name) {
LookupIterator it = LookupIterator::PropertyOrElement( LookupIterator it = LookupIterator::PropertyOrElement(
name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it); return HasProperty(&it);
if (!maybe_result.IsJust()) return Nothing<bool>();
return Just(it.IsFound());
} }
...@@ -14863,9 +14899,7 @@ Maybe<bool> JSObject::HasRealElementProperty(Handle<JSObject> object, ...@@ -14863,9 +14899,7 @@ Maybe<bool> JSObject::HasRealElementProperty(Handle<JSObject> object,
Isolate* isolate = object->GetIsolate(); Isolate* isolate = object->GetIsolate();
LookupIterator it(isolate, object, index, LookupIterator it(isolate, object, index,
LookupIterator::OWN_SKIP_INTERCEPTOR); LookupIterator::OWN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it); return HasProperty(&it);
if (!maybe_result.IsJust()) return Nothing<bool>();
return Just(it.IsFound());
} }
......
...@@ -1828,6 +1828,7 @@ class JSReceiver: public HeapObject { ...@@ -1828,6 +1828,7 @@ class JSReceiver: public HeapObject {
Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint); Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint);
// Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6. // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6.
MUST_USE_RESULT static Maybe<bool> HasProperty(LookupIterator* it);
MUST_USE_RESULT static inline Maybe<bool> HasProperty( MUST_USE_RESULT static inline Maybe<bool> HasProperty(
Handle<JSReceiver> object, Handle<Name> name); Handle<JSReceiver> object, Handle<Name> name);
MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(Handle<JSReceiver>, MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(Handle<JSReceiver>,
......
...@@ -1310,7 +1310,7 @@ function TestDescriptorGetOrder(handler) { ...@@ -1310,7 +1310,7 @@ function TestDescriptorGetOrder(handler) {
TestDescriptorGetOrder2(function(n) { return p[n] }, "vV") TestDescriptorGetOrder2(function(n) { return p[n] }, "vV")
TestDescriptorGetOrder2(function(n) { return n in p }, "") TestDescriptorGetOrder2(function(n) { return n in p }, "")
TestDescriptorGetOrder2(function(n) { return o[n] }, "vV") TestDescriptorGetOrder2(function(n) { return o[n] }, "vV")
TestDescriptorGetOrder2(function(n) { return n in o }, "eEcCvVwWgs") TestDescriptorGetOrder2(function(n) { return n in o }, "")
} }
function TestDescriptorGetOrder2(f, access) { function TestDescriptorGetOrder2(f, access) {
......
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