Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Unified Diff: src/objects.cc

Issue 321543004: Rewrite GetPropertyAttribute to use the LookupIterator (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove bogus asserts Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 91d90a21554ceda86620763d80f3717a8c57ee8e..10533bd68f805fdee0fe96fdb4c49bcc4e81e923 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -143,10 +143,9 @@ MaybeHandle<Object> Object::GetProperty(LookupIterator* it) {
if (it->isolate()->has_pending_exception()) return maybe_result;
break;
}
- case LookupIterator::ACCESS_CHECK: {
+ case LookupIterator::ACCESS_CHECK:
if (it->HasAccess(v8::ACCESS_GET)) break;
return JSObject::GetPropertyWithFailedAccessCheck(it);
- }
case LookupIterator::PROPERTY:
if (it->HasProperty()) {
switch (it->property_kind()) {
@@ -567,6 +566,8 @@ MaybeHandle<Object> Object::SetPropertyWithDefinedSetter(
static bool FindAllCanReadHolder(LookupIterator* it) {
+ it->skip_interceptor();
+ it->skip_access_check();
for (; it->IsFound(); it->Next()) {
if (it->state() == LookupIterator::PROPERTY &&
it->HasProperty() &&
@@ -596,17 +597,11 @@ MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck(
}
-PropertyAttributes JSObject::GetPropertyAttributeWithFailedAccessCheck(
- Handle<JSObject> object,
- LookupResult* result,
- Handle<Name> name,
- bool check_prototype) {
- LookupIterator::Configuration configuration = check_prototype
- ? LookupIterator::CHECK_DERIVED
- : LookupIterator::CHECK_OWN_REAL;
- LookupIterator it(object, name, object, configuration);
- if (FindAllCanReadHolder(&it)) return it.property_details().attributes();
- it.isolate()->ReportFailedAccessCheck(object, v8::ACCESS_HAS);
+PropertyAttributes JSObject::GetPropertyAttributesWithFailedAccessCheck(
+ LookupIterator* it) {
+ Handle<JSObject> checked = Handle<JSObject>::cast(it->GetHolder());
+ if (FindAllCanReadHolder(it)) return it->property_details().attributes();
+ it->isolate()->ReportFailedAccessCheck(checked, v8::ACCESS_HAS);
// TODO(yangguo): Issue 3269, check for scheduled exception missing?
return ABSENT;
}
@@ -3069,8 +3064,8 @@ MaybeHandle<Object> JSObject::SetPropertyViaPrototypes(
*done = result.IsReadOnly();
break;
case INTERCEPTOR: {
- PropertyAttributes attr = GetPropertyAttributeWithInterceptor(
- handle(result.holder()), object, name, true);
+ LookupIterator it(object, name, handle(result.holder()));
+ PropertyAttributes attr = GetPropertyAttributes(&it);
*done = !!(attr & READ_ONLY);
break;
}
@@ -3727,9 +3722,9 @@ MaybeHandle<Object> JSProxy::DeleteElementWithHandler(
}
-PropertyAttributes JSProxy::GetPropertyAttributeWithHandler(
+PropertyAttributes JSProxy::GetPropertyAttributesWithHandler(
Handle<JSProxy> proxy,
- Handle<JSReceiver> receiver,
+ Handle<Object> receiver,
Handle<Name> name) {
Isolate* isolate = proxy->GetIsolate();
HandleScope scope(isolate);
@@ -3811,7 +3806,7 @@ PropertyAttributes JSProxy::GetElementAttributeWithHandler(
uint32_t index) {
Isolate* isolate = proxy->GetIsolate();
Handle<String> name = isolate->factory()->Uint32ToString(index);
- return GetPropertyAttributeWithHandler(proxy, receiver, name);
+ return GetPropertyAttributesWithHandler(proxy, receiver, name);
}
@@ -4353,142 +4348,87 @@ MaybeHandle<Object> JSObject::SetOwnPropertyIgnoreAttributes(
}
-PropertyAttributes JSObject::GetPropertyAttributePostInterceptor(
- Handle<JSObject> object,
- Handle<JSObject> receiver,
- Handle<Name> name,
- bool check_prototype) {
- // Check own property, ignore interceptor.
- Isolate* isolate = object->GetIsolate();
- LookupResult result(isolate);
- object->LookupOwnRealNamedProperty(name, &result);
- if (result.IsFound()) return result.GetAttributes();
-
- if (check_prototype) {
- // Continue searching via the prototype chain.
- Handle<Object> proto(object->GetPrototype(), isolate);
- if (!proto->IsNull()) {
- return JSReceiver::GetPropertyAttributeWithReceiver(
- Handle<JSObject>::cast(proto), receiver, name);
- }
- }
- return ABSENT;
-}
-
-
-PropertyAttributes JSObject::GetPropertyAttributeWithInterceptor(
- Handle<JSObject> object,
- Handle<JSObject> receiver,
- Handle<Name> name,
- bool check_prototype) {
+Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithInterceptor(
+ Handle<JSObject> holder,
+ Handle<Object> receiver,
+ Handle<Name> name) {
// TODO(rossberg): Support symbols in the API.
- if (name->IsSymbol()) return ABSENT;
+ if (name->IsSymbol()) return Maybe<PropertyAttributes>(ABSENT);
- Isolate* isolate = object->GetIsolate();
+ Isolate* isolate = holder->GetIsolate();
HandleScope scope(isolate);
// Make sure that the top context does not change when doing
// callbacks or interceptor calls.
AssertNoContextChange ncc(isolate);
- Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
+ Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor());
PropertyCallbackArguments args(
- isolate, interceptor->data(), *receiver, *object);
+ isolate, interceptor->data(), *receiver, *holder);
if (!interceptor->query()->IsUndefined()) {
v8::NamedPropertyQueryCallback query =
v8::ToCData<v8::NamedPropertyQueryCallback>(interceptor->query());
LOG(isolate,
- ApiNamedPropertyAccess("interceptor-named-has", *object, *name));
+ ApiNamedPropertyAccess("interceptor-named-has", *holder, *name));
v8::Handle<v8::Integer> result =
args.Call(query, v8::Utils::ToLocal(Handle<String>::cast(name)));
if (!result.IsEmpty()) {
ASSERT(result->IsInt32());
- return static_cast<PropertyAttributes>(result->Int32Value());
+ return Maybe<PropertyAttributes>(
+ static_cast<PropertyAttributes>(result->Int32Value()));
}
} else if (!interceptor->getter()->IsUndefined()) {
v8::NamedPropertyGetterCallback getter =
v8::ToCData<v8::NamedPropertyGetterCallback>(interceptor->getter());
LOG(isolate,
- ApiNamedPropertyAccess("interceptor-named-get-has", *object, *name));
+ ApiNamedPropertyAccess("interceptor-named-get-has", *holder, *name));
v8::Handle<v8::Value> result =
args.Call(getter, v8::Utils::ToLocal(Handle<String>::cast(name)));
- if (!result.IsEmpty()) return DONT_ENUM;
+ if (!result.IsEmpty()) return Maybe<PropertyAttributes>(DONT_ENUM);
}
- return GetPropertyAttributePostInterceptor(
- object, receiver, name, check_prototype);
+ return Maybe<PropertyAttributes>();
}
-PropertyAttributes JSReceiver::GetPropertyAttributeWithReceiver(
- Handle<JSReceiver> object,
- Handle<JSReceiver> receiver,
- Handle<Name> key) {
+PropertyAttributes JSReceiver::GetOwnPropertyAttributes(
+ Handle<JSReceiver> object, Handle<Name> name) {
+ // Check whether the name is an array index.
uint32_t index = 0;
- if (object->IsJSObject() && key->AsArrayIndex(&index)) {
- return JSObject::GetElementAttributeWithReceiver(
- Handle<JSObject>::cast(object), receiver, index, true);
+ if (object->IsJSObject() && name->AsArrayIndex(&index)) {
+ return GetOwnElementAttribute(object, index);
}
- // Named property.
- LookupResult lookup(object->GetIsolate());
- object->Lookup(key, &lookup);
- return GetPropertyAttributeForResult(object, receiver, &lookup, key, true);
+ LookupIterator it(object, name, LookupIterator::CHECK_OWN);
+ return GetPropertyAttributes(&it);
}
-PropertyAttributes JSReceiver::GetPropertyAttributeForResult(
- Handle<JSReceiver> object,
- Handle<JSReceiver> receiver,
- LookupResult* lookup,
- Handle<Name> name,
- bool check_prototype) {
- // Check access rights if needed.
- if (object->IsAccessCheckNeeded()) {
- Heap* heap = object->GetHeap();
- Handle<JSObject> obj = Handle<JSObject>::cast(object);
- if (!heap->isolate()->MayNamedAccess(obj, name, v8::ACCESS_HAS)) {
- return JSObject::GetPropertyAttributeWithFailedAccessCheck(
- obj, lookup, name, check_prototype);
- }
- }
- if (lookup->IsFound()) {
- switch (lookup->type()) {
- case NORMAL: // fall through
- case FIELD:
- case CONSTANT:
- case CALLBACKS:
- return lookup->GetAttributes();
- case HANDLER: {
- return JSProxy::GetPropertyAttributeWithHandler(
- handle(lookup->proxy()), receiver, name);
- }
- case INTERCEPTOR:
- return JSObject::GetPropertyAttributeWithInterceptor(
- handle(lookup->holder()),
- Handle<JSObject>::cast(receiver),
- name,
- check_prototype);
- case NONEXISTENT:
+PropertyAttributes JSReceiver::GetPropertyAttributes(LookupIterator* it) {
+ for (; it->IsFound(); it->Next()) {
+ switch (it->state()) {
+ case LookupIterator::NOT_FOUND:
UNREACHABLE();
+ case LookupIterator::JSPROXY:
+ return JSProxy::GetPropertyAttributesWithHandler(
+ it->GetJSProxy(), it->GetReceiver(), it->name());
+ case LookupIterator::INTERCEPTOR: {
+ Maybe<PropertyAttributes> result =
+ JSObject::GetPropertyAttributesWithInterceptor(
+ it->GetHolder(), it->GetReceiver(), it->name());
+ if (result.has_value) return result.value;
+ break;
+ }
+ case LookupIterator::ACCESS_CHECK:
+ if (it->HasAccess(v8::ACCESS_HAS)) break;
+ return JSObject::GetPropertyAttributesWithFailedAccessCheck(it);
+ case LookupIterator::PROPERTY:
+ if (it->HasProperty()) return it->property_details().attributes();
+ break;
}
}
return ABSENT;
}
-PropertyAttributes JSReceiver::GetOwnPropertyAttribute(
- Handle<JSReceiver> object, Handle<Name> name) {
- // Check whether the name is an array index.
- uint32_t index = 0;
- if (object->IsJSObject() && name->AsArrayIndex(&index)) {
- return GetOwnElementAttribute(object, index);
- }
- // Named property.
- LookupResult lookup(object->GetIsolate());
- object->LookupOwn(name, &lookup, true);
- return GetPropertyAttributeForResult(object, object, &lookup, name, false);
-}
-
-
PropertyAttributes JSObject::GetElementAttributeWithReceiver(
Handle<JSObject> object,
Handle<JSReceiver> receiver,
@@ -5162,8 +5102,8 @@ void JSObject::DeleteHiddenProperty(Handle<JSObject> object, Handle<Name> key) {
bool JSObject::HasHiddenProperties(Handle<JSObject> object) {
Handle<Name> hidden = object->GetIsolate()->factory()->hidden_string();
- return GetPropertyAttributePostInterceptor(
- object, object, hidden, false) != ABSENT;
+ LookupIterator it(object, hidden, LookupIterator::CHECK_OWN_REAL);
+ return GetPropertyAttributes(&it) != ABSENT;
}
@@ -5978,7 +5918,7 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
ASSERT(names->get(i)->IsString());
Handle<String> key_string(String::cast(names->get(i)));
PropertyAttributes attributes =
- JSReceiver::GetOwnPropertyAttribute(copy, key_string);
+ JSReceiver::GetOwnPropertyAttributes(copy, key_string);
// Only deep copy fields from the object literal expression.
// In particular, don't try to copy the length attribute of
// an array.
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698