From 028025f07e26ee7f962ff0a1ab9362868e58bac9 Mon Sep 17 00:00:00 2001 From: verwaest Date: Sat, 13 Jun 2015 04:16:00 -0700 Subject: [PATCH] Also handle elements in *RealNamed* api methods Apparently the *RealNamed* API methods only have named variants, but were always used by the embedder to find elements as well. We'd never find them though, since we wouldn't even look there. This CL ensures we check whether the name is actually an array index. I guess for all named API functions we should assume they are used similar to o["name"] where name could also be a number... At least we should make it uniform between embedder and V8. This matches us up with their expectations for now... BUG=v8:4137 LOG=n Review URL: https://codereview.chromium.org/1177383004 Cr-Commit-Position: refs/heads/master@{#29008} --- src/api.cc | 20 ++++++++++++-------- src/objects.cc | 6 ++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/api.cc b/src/api.cc index 750d7df..664b80e 100644 --- a/src/api.cc +++ b/src/api.cc @@ -4223,8 +4223,9 @@ MaybeLocal v8::Object::GetRealNamedPropertyInPrototypeChain( i::PrototypeIterator iter(isolate, self); if (iter.IsAtEnd()) return MaybeLocal(); auto proto = i::PrototypeIterator::GetCurrent(iter); - i::LookupIterator it(self, key_obj, i::Handle::cast(proto), - i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); + i::LookupIterator it = i::LookupIterator::PropertyOrElement( + isolate, self, key_obj, i::Handle::cast(proto), + i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); Local result; has_pending_exception = !ToLocal(i::Object::GetProperty(&it), &result); RETURN_ON_FAILED_EXECUTION(Value); @@ -4252,8 +4253,9 @@ v8::Object::GetRealNamedPropertyAttributesInPrototypeChain( i::PrototypeIterator iter(isolate, self); if (iter.IsAtEnd()) return Nothing(); auto proto = i::PrototypeIterator::GetCurrent(iter); - i::LookupIterator it(self, key_obj, i::Handle::cast(proto), - i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); + i::LookupIterator it = i::LookupIterator::PropertyOrElement( + isolate, self, key_obj, i::Handle::cast(proto), + i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); auto result = i::JSReceiver::GetPropertyAttributes(&it); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute); if (!it.IsFound()) return Nothing(); @@ -4277,8 +4279,9 @@ MaybeLocal v8::Object::GetRealNamedProperty(Local context, PREPARE_FOR_EXECUTION(context, "v8::Object::GetRealNamedProperty()", Value); auto self = Utils::OpenHandle(this); auto key_obj = Utils::OpenHandle(*key); - i::LookupIterator it(self, key_obj, - i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); + i::LookupIterator it = i::LookupIterator::PropertyOrElement( + isolate, self, key_obj, + i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); Local result; has_pending_exception = !ToLocal(i::Object::GetProperty(&it), &result); RETURN_ON_FAILED_EXECUTION(Value); @@ -4300,8 +4303,9 @@ Maybe v8::Object::GetRealNamedPropertyAttributes( PropertyAttribute); auto self = Utils::OpenHandle(this); auto key_obj = Utils::OpenHandle(*key); - i::LookupIterator it(self, key_obj, - i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); + i::LookupIterator it = i::LookupIterator::PropertyOrElement( + isolate, self, key_obj, + i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); auto result = i::JSReceiver::GetPropertyAttributes(&it); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute); if (!it.IsFound()) return Nothing(); diff --git a/src/objects.cc b/src/objects.cc index 5476269..d061874 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -13403,7 +13403,8 @@ MaybeHandle JSObject::GetKeysForIndexedInterceptor( Maybe JSObject::HasRealNamedProperty(Handle object, Handle name) { - LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); + LookupIterator it = LookupIterator::PropertyOrElement( + name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); Maybe maybe_result = GetPropertyAttributes(&it); if (!maybe_result.IsJust()) return Nothing(); return Just(it.IsFound()); @@ -13423,7 +13424,8 @@ Maybe JSObject::HasRealElementProperty(Handle object, Maybe JSObject::HasRealNamedCallbackProperty(Handle object, Handle name) { - LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); + LookupIterator it = LookupIterator::PropertyOrElement( + name->GetIsolate(), object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); Maybe maybe_result = GetPropertyAttributes(&it); return maybe_result.IsJust() ? Just(it.state() == LookupIterator::ACCESSOR) : Nothing(); -- 2.7.4