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

Side by Side Diff: src/objects.cc

Issue 967243002: Polish Maybe API a bit, removing useless creativity and fixing some signatures. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Simplified friendship. Added check in FromJust. Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iomanip> 5 #include <iomanip>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(it->isolate(), Object); 474 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(it->isolate(), Object);
475 return it->factory()->undefined_value(); 475 return it->factory()->undefined_value();
476 } 476 }
477 477
478 478
479 Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithFailedAccessCheck( 479 Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithFailedAccessCheck(
480 LookupIterator* it) { 480 LookupIterator* it) {
481 Handle<JSObject> checked = it->GetHolder<JSObject>(); 481 Handle<JSObject> checked = it->GetHolder<JSObject>();
482 while (FindAllCanReadHolder(it)) { 482 while (FindAllCanReadHolder(it)) {
483 if (it->state() == LookupIterator::ACCESSOR) { 483 if (it->state() == LookupIterator::ACCESSOR) {
484 return maybe(it->property_details().attributes()); 484 return Just(it->property_details().attributes());
485 } 485 }
486 DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state()); 486 DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state());
487 auto result = GetPropertyAttributesWithInterceptor( 487 auto result = GetPropertyAttributesWithInterceptor(
488 it->GetHolder<JSObject>(), it->GetReceiver(), it->name()); 488 it->GetHolder<JSObject>(), it->GetReceiver(), it->name());
489 if (it->isolate()->has_scheduled_exception()) break; 489 if (it->isolate()->has_scheduled_exception()) break;
490 if (result.has_value && result.value != ABSENT) return result; 490 if (result.has_value && result.value != ABSENT) return result;
491 } 491 }
492 it->isolate()->ReportFailedAccessCheck(checked); 492 it->isolate()->ReportFailedAccessCheck(checked);
493 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(it->isolate(), 493 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(it->isolate(),
494 Maybe<PropertyAttributes>()); 494 Nothing<PropertyAttributes>());
495 return maybe(ABSENT); 495 return Just(ABSENT);
496 } 496 }
497 497
498 498
499 static bool FindAllCanWriteHolder(LookupIterator* it) { 499 static bool FindAllCanWriteHolder(LookupIterator* it) {
500 for (; it->IsFound(); it->Next()) { 500 for (; it->IsFound(); it->Next()) {
501 if (it->state() == LookupIterator::ACCESSOR) { 501 if (it->state() == LookupIterator::ACCESSOR) {
502 Handle<Object> accessors = it->GetAccessors(); 502 Handle<Object> accessors = it->GetAccessors();
503 if (accessors->IsAccessorInfo()) { 503 if (accessors->IsAccessorInfo()) {
504 if (AccessorInfo::cast(*accessors)->all_can_write()) return true; 504 if (AccessorInfo::cast(*accessors)->all_can_write()) return true;
505 } 505 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 auto all_can_read_holder = 622 auto all_can_read_holder =
623 FindIndexedAllCanReadHolder(isolate, holder, where_to_start); 623 FindIndexedAllCanReadHolder(isolate, holder, where_to_start);
624 if (!all_can_read_holder.ToHandle(&holder)) break; 624 if (!all_can_read_holder.ToHandle(&holder)) break;
625 auto result = 625 auto result =
626 JSObject::GetElementAttributeFromInterceptor(object, receiver, index); 626 JSObject::GetElementAttributeFromInterceptor(object, receiver, index);
627 if (isolate->has_scheduled_exception()) break; 627 if (isolate->has_scheduled_exception()) break;
628 if (result.has_value && result.value != ABSENT) return result; 628 if (result.has_value && result.value != ABSENT) return result;
629 where_to_start = PrototypeIterator::START_AT_PROTOTYPE; 629 where_to_start = PrototypeIterator::START_AT_PROTOTYPE;
630 } 630 }
631 isolate->ReportFailedAccessCheck(object); 631 isolate->ReportFailedAccessCheck(object);
632 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Maybe<PropertyAttributes>()); 632 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<PropertyAttributes>());
633 return maybe(ABSENT); 633 return Just(ABSENT);
634 } 634 }
635 635
636 636
637 MaybeHandle<Object> Object::GetElementWithReceiver(Isolate* isolate, 637 MaybeHandle<Object> Object::GetElementWithReceiver(Isolate* isolate,
638 Handle<Object> object, 638 Handle<Object> object,
639 Handle<Object> receiver, 639 Handle<Object> receiver,
640 uint32_t index) { 640 uint32_t index) {
641 if (object->IsUndefined()) { 641 if (object->IsUndefined()) {
642 // TODO(verwaest): Why is this check here? 642 // TODO(verwaest): Why is this check here?
643 UNREACHABLE(); 643 UNREACHABLE();
(...skipping 3124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3768 Handle<Map> map(object->map()); 3768 Handle<Map> map(object->map());
3769 return Map::TransitionElementsTo(map, to_kind); 3769 return Map::TransitionElementsTo(map, to_kind);
3770 } 3770 }
3771 3771
3772 3772
3773 Maybe<bool> JSProxy::HasPropertyWithHandler(Handle<JSProxy> proxy, 3773 Maybe<bool> JSProxy::HasPropertyWithHandler(Handle<JSProxy> proxy,
3774 Handle<Name> name) { 3774 Handle<Name> name) {
3775 Isolate* isolate = proxy->GetIsolate(); 3775 Isolate* isolate = proxy->GetIsolate();
3776 3776
3777 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 3777 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
3778 if (name->IsSymbol()) return maybe(false); 3778 if (name->IsSymbol()) return Just(false);
3779 3779
3780 Handle<Object> args[] = { name }; 3780 Handle<Object> args[] = { name };
3781 Handle<Object> result; 3781 Handle<Object> result;
3782 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 3782 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
3783 isolate, result, CallTrap(proxy, "has", isolate->derived_has_trap(), 3783 isolate, result, CallTrap(proxy, "has", isolate->derived_has_trap(),
3784 arraysize(args), args), 3784 arraysize(args), args),
3785 Maybe<bool>()); 3785 Nothing<bool>());
3786 3786
3787 return maybe(result->BooleanValue()); 3787 return Just(result->BooleanValue());
3788 } 3788 }
3789 3789
3790 3790
3791 MaybeHandle<Object> JSProxy::SetPropertyWithHandler( 3791 MaybeHandle<Object> JSProxy::SetPropertyWithHandler(
3792 Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name, 3792 Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name,
3793 Handle<Object> value, LanguageMode language_mode) { 3793 Handle<Object> value, LanguageMode language_mode) {
3794 Isolate* isolate = proxy->GetIsolate(); 3794 Isolate* isolate = proxy->GetIsolate();
3795 3795
3796 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 3796 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
3797 if (name->IsSymbol()) return value; 3797 if (name->IsSymbol()) return value;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
3944 return JSProxy::DeletePropertyWithHandler(proxy, name, language_mode); 3944 return JSProxy::DeletePropertyWithHandler(proxy, name, language_mode);
3945 } 3945 }
3946 3946
3947 3947
3948 Maybe<PropertyAttributes> JSProxy::GetPropertyAttributesWithHandler( 3948 Maybe<PropertyAttributes> JSProxy::GetPropertyAttributesWithHandler(
3949 Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name) { 3949 Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name) {
3950 Isolate* isolate = proxy->GetIsolate(); 3950 Isolate* isolate = proxy->GetIsolate();
3951 HandleScope scope(isolate); 3951 HandleScope scope(isolate);
3952 3952
3953 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 3953 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
3954 if (name->IsSymbol()) return maybe(ABSENT); 3954 if (name->IsSymbol()) return Just(ABSENT);
3955 3955
3956 Handle<Object> args[] = { name }; 3956 Handle<Object> args[] = { name };
3957 Handle<Object> result; 3957 Handle<Object> result;
3958 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 3958 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
3959 isolate, result, 3959 isolate, result, proxy->CallTrap(proxy, "getPropertyDescriptor",
3960 proxy->CallTrap(proxy, "getPropertyDescriptor", Handle<Object>(), 3960 Handle<Object>(), arraysize(args), args),
3961 arraysize(args), args), 3961 Nothing<PropertyAttributes>());
3962 Maybe<PropertyAttributes>());
3963 3962
3964 if (result->IsUndefined()) return maybe(ABSENT); 3963 if (result->IsUndefined()) return Just(ABSENT);
3965 3964
3966 Handle<Object> argv[] = { result }; 3965 Handle<Object> argv[] = { result };
3967 Handle<Object> desc; 3966 Handle<Object> desc;
3968 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 3967 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
3969 isolate, desc, 3968 isolate, desc,
3970 Execution::Call(isolate, isolate->to_complete_property_descriptor(), 3969 Execution::Call(isolate, isolate->to_complete_property_descriptor(),
3971 result, arraysize(argv), argv), 3970 result, arraysize(argv), argv),
3972 Maybe<PropertyAttributes>()); 3971 Nothing<PropertyAttributes>());
3973 3972
3974 // Convert result to PropertyAttributes. 3973 // Convert result to PropertyAttributes.
3975 Handle<String> enum_n = isolate->factory()->InternalizeOneByteString( 3974 Handle<String> enum_n = isolate->factory()->InternalizeOneByteString(
3976 STATIC_CHAR_VECTOR("enumerable_")); 3975 STATIC_CHAR_VECTOR("enumerable_"));
3977 Handle<Object> enumerable; 3976 Handle<Object> enumerable;
3978 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, enumerable, 3977 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, enumerable,
3979 Object::GetProperty(desc, enum_n), 3978 Object::GetProperty(desc, enum_n),
3980 Maybe<PropertyAttributes>()); 3979 Nothing<PropertyAttributes>());
3981 Handle<String> conf_n = isolate->factory()->InternalizeOneByteString( 3980 Handle<String> conf_n = isolate->factory()->InternalizeOneByteString(
3982 STATIC_CHAR_VECTOR("configurable_")); 3981 STATIC_CHAR_VECTOR("configurable_"));
3983 Handle<Object> configurable; 3982 Handle<Object> configurable;
3984 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, configurable, 3983 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, configurable,
3985 Object::GetProperty(desc, conf_n), 3984 Object::GetProperty(desc, conf_n),
3986 Maybe<PropertyAttributes>()); 3985 Nothing<PropertyAttributes>());
3987 Handle<String> writ_n = isolate->factory()->InternalizeOneByteString( 3986 Handle<String> writ_n = isolate->factory()->InternalizeOneByteString(
3988 STATIC_CHAR_VECTOR("writable_")); 3987 STATIC_CHAR_VECTOR("writable_"));
3989 Handle<Object> writable; 3988 Handle<Object> writable;
3990 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, writable, 3989 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, writable,
3991 Object::GetProperty(desc, writ_n), 3990 Object::GetProperty(desc, writ_n),
3992 Maybe<PropertyAttributes>()); 3991 Nothing<PropertyAttributes>());
3993 if (!writable->BooleanValue()) { 3992 if (!writable->BooleanValue()) {
3994 Handle<String> set_n = isolate->factory()->InternalizeOneByteString( 3993 Handle<String> set_n = isolate->factory()->InternalizeOneByteString(
3995 STATIC_CHAR_VECTOR("set_")); 3994 STATIC_CHAR_VECTOR("set_"));
3996 Handle<Object> setter; 3995 Handle<Object> setter;
3997 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, setter, 3996 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, setter,
3998 Object::GetProperty(desc, set_n), 3997 Object::GetProperty(desc, set_n),
3999 Maybe<PropertyAttributes>()); 3998 Nothing<PropertyAttributes>());
4000 writable = isolate->factory()->ToBoolean(!setter->IsUndefined()); 3999 writable = isolate->factory()->ToBoolean(!setter->IsUndefined());
4001 } 4000 }
4002 4001
4003 if (configurable->IsFalse()) { 4002 if (configurable->IsFalse()) {
4004 Handle<Object> handler(proxy->handler(), isolate); 4003 Handle<Object> handler(proxy->handler(), isolate);
4005 Handle<String> trap = isolate->factory()->InternalizeOneByteString( 4004 Handle<String> trap = isolate->factory()->InternalizeOneByteString(
4006 STATIC_CHAR_VECTOR("getPropertyDescriptor")); 4005 STATIC_CHAR_VECTOR("getPropertyDescriptor"));
4007 Handle<Object> args[] = { handler, trap, name }; 4006 Handle<Object> args[] = { handler, trap, name };
4008 Handle<Object> error = isolate->factory()->NewTypeError( 4007 Handle<Object> error = isolate->factory()->NewTypeError(
4009 "proxy_prop_not_configurable", HandleVector(args, arraysize(args))); 4008 "proxy_prop_not_configurable", HandleVector(args, arraysize(args)));
4010 isolate->Throw(*error); 4009 isolate->Throw(*error);
4011 return maybe(NONE); 4010 return Just(NONE);
4012 } 4011 }
4013 4012
4014 int attributes = NONE; 4013 int attributes = NONE;
4015 if (!enumerable->BooleanValue()) attributes |= DONT_ENUM; 4014 if (!enumerable->BooleanValue()) attributes |= DONT_ENUM;
4016 if (!configurable->BooleanValue()) attributes |= DONT_DELETE; 4015 if (!configurable->BooleanValue()) attributes |= DONT_DELETE;
4017 if (!writable->BooleanValue()) attributes |= READ_ONLY; 4016 if (!writable->BooleanValue()) attributes |= READ_ONLY;
4018 return maybe(static_cast<PropertyAttributes>(attributes)); 4017 return Just(static_cast<PropertyAttributes>(attributes));
4019 } 4018 }
4020 4019
4021 4020
4022 Maybe<PropertyAttributes> JSProxy::GetElementAttributeWithHandler( 4021 Maybe<PropertyAttributes> JSProxy::GetElementAttributeWithHandler(
4023 Handle<JSProxy> proxy, Handle<JSReceiver> receiver, uint32_t index) { 4022 Handle<JSProxy> proxy, Handle<JSReceiver> receiver, uint32_t index) {
4024 Isolate* isolate = proxy->GetIsolate(); 4023 Isolate* isolate = proxy->GetIsolate();
4025 Handle<String> name = isolate->factory()->Uint32ToString(index); 4024 Handle<String> name = isolate->factory()->Uint32ToString(index);
4026 return GetPropertyAttributesWithHandler(proxy, receiver, name); 4025 return GetPropertyAttributesWithHandler(proxy, receiver, name);
4027 } 4026 }
4028 4027
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
4295 Handle<Name> name) { 4294 Handle<Name> name) {
4296 Isolate* isolate = holder->GetIsolate(); 4295 Isolate* isolate = holder->GetIsolate();
4297 HandleScope scope(isolate); 4296 HandleScope scope(isolate);
4298 4297
4299 // Make sure that the top context does not change when doing 4298 // Make sure that the top context does not change when doing
4300 // callbacks or interceptor calls. 4299 // callbacks or interceptor calls.
4301 AssertNoContextChange ncc(isolate); 4300 AssertNoContextChange ncc(isolate);
4302 4301
4303 Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor()); 4302 Handle<InterceptorInfo> interceptor(holder->GetNamedInterceptor());
4304 if (name->IsSymbol() && !interceptor->can_intercept_symbols()) { 4303 if (name->IsSymbol() && !interceptor->can_intercept_symbols()) {
4305 return maybe(ABSENT); 4304 return Just(ABSENT);
4306 } 4305 }
4307 PropertyCallbackArguments args( 4306 PropertyCallbackArguments args(
4308 isolate, interceptor->data(), *receiver, *holder); 4307 isolate, interceptor->data(), *receiver, *holder);
4309 if (!interceptor->query()->IsUndefined()) { 4308 if (!interceptor->query()->IsUndefined()) {
4310 v8::GenericNamedPropertyQueryCallback query = 4309 v8::GenericNamedPropertyQueryCallback query =
4311 v8::ToCData<v8::GenericNamedPropertyQueryCallback>( 4310 v8::ToCData<v8::GenericNamedPropertyQueryCallback>(
4312 interceptor->query()); 4311 interceptor->query());
4313 LOG(isolate, 4312 LOG(isolate,
4314 ApiNamedPropertyAccess("interceptor-named-has", *holder, *name)); 4313 ApiNamedPropertyAccess("interceptor-named-has", *holder, *name));
4315 v8::Handle<v8::Integer> result = args.Call(query, v8::Utils::ToLocal(name)); 4314 v8::Handle<v8::Integer> result = args.Call(query, v8::Utils::ToLocal(name));
4316 if (!result.IsEmpty()) { 4315 if (!result.IsEmpty()) {
4317 DCHECK(result->IsInt32()); 4316 DCHECK(result->IsInt32());
4318 return maybe(static_cast<PropertyAttributes>(result->Int32Value())); 4317 return Just(static_cast<PropertyAttributes>(result->Int32Value()));
4319 } 4318 }
4320 } else if (!interceptor->getter()->IsUndefined()) { 4319 } else if (!interceptor->getter()->IsUndefined()) {
4321 v8::GenericNamedPropertyGetterCallback getter = 4320 v8::GenericNamedPropertyGetterCallback getter =
4322 v8::ToCData<v8::GenericNamedPropertyGetterCallback>( 4321 v8::ToCData<v8::GenericNamedPropertyGetterCallback>(
4323 interceptor->getter()); 4322 interceptor->getter());
4324 LOG(isolate, 4323 LOG(isolate,
4325 ApiNamedPropertyAccess("interceptor-named-get-has", *holder, *name)); 4324 ApiNamedPropertyAccess("interceptor-named-get-has", *holder, *name));
4326 v8::Handle<v8::Value> result = args.Call(getter, v8::Utils::ToLocal(name)); 4325 v8::Handle<v8::Value> result = args.Call(getter, v8::Utils::ToLocal(name));
4327 if (!result.IsEmpty()) return maybe(DONT_ENUM); 4326 if (!result.IsEmpty()) return Just(DONT_ENUM);
4328 } 4327 }
4329 4328
4330 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Maybe<PropertyAttributes>()); 4329 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<PropertyAttributes>());
4331 return maybe(ABSENT); 4330 return Just(ABSENT);
4332 } 4331 }
4333 4332
4334 4333
4335 Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes( 4334 Maybe<PropertyAttributes> JSReceiver::GetOwnPropertyAttributes(
4336 Handle<JSReceiver> object, Handle<Name> name) { 4335 Handle<JSReceiver> object, Handle<Name> name) {
4337 // Check whether the name is an array index. 4336 // Check whether the name is an array index.
4338 uint32_t index = 0; 4337 uint32_t index = 0;
4339 if (object->IsJSObject() && name->AsArrayIndex(&index)) { 4338 if (object->IsJSObject() && name->AsArrayIndex(&index)) {
4340 return GetOwnElementAttribute(object, index); 4339 return GetOwnElementAttribute(object, index);
4341 } 4340 }
(...skipping 18 matching lines...) Expand all
4360 it->GetHolder<JSObject>(), it->GetReceiver(), it->name()); 4359 it->GetHolder<JSObject>(), it->GetReceiver(), it->name());
4361 if (!result.has_value) return result; 4360 if (!result.has_value) return result;
4362 if (result.value != ABSENT) return result; 4361 if (result.value != ABSENT) return result;
4363 break; 4362 break;
4364 } 4363 }
4365 case LookupIterator::ACCESS_CHECK: 4364 case LookupIterator::ACCESS_CHECK:
4366 if (it->HasAccess()) break; 4365 if (it->HasAccess()) break;
4367 return JSObject::GetPropertyAttributesWithFailedAccessCheck(it); 4366 return JSObject::GetPropertyAttributesWithFailedAccessCheck(it);
4368 case LookupIterator::ACCESSOR: 4367 case LookupIterator::ACCESSOR:
4369 case LookupIterator::DATA: 4368 case LookupIterator::DATA:
4370 return maybe(it->property_details().attributes()); 4369 return Just(it->property_details().attributes());
4371 } 4370 }
4372 } 4371 }
4373 return maybe(ABSENT); 4372 return Just(ABSENT);
4374 } 4373 }
4375 4374
4376 4375
4377 Maybe<PropertyAttributes> JSObject::GetElementAttributeWithReceiver( 4376 Maybe<PropertyAttributes> JSObject::GetElementAttributeWithReceiver(
4378 Handle<JSObject> object, Handle<JSReceiver> receiver, uint32_t index, 4377 Handle<JSObject> object, Handle<JSReceiver> receiver, uint32_t index,
4379 bool check_prototype) { 4378 bool check_prototype) {
4380 Isolate* isolate = object->GetIsolate(); 4379 Isolate* isolate = object->GetIsolate();
4381 4380
4382 // Check access rights if needed. 4381 // Check access rights if needed.
4383 if (object->IsAccessCheckNeeded()) { 4382 if (object->IsAccessCheckNeeded()) {
4384 if (!isolate->MayAccess(object)) { 4383 if (!isolate->MayAccess(object)) {
4385 return GetElementAttributesWithFailedAccessCheck(isolate, object, 4384 return GetElementAttributesWithFailedAccessCheck(isolate, object,
4386 receiver, index); 4385 receiver, index);
4387 } 4386 }
4388 } 4387 }
4389 4388
4390 if (object->IsJSGlobalProxy()) { 4389 if (object->IsJSGlobalProxy()) {
4391 PrototypeIterator iter(isolate, object); 4390 PrototypeIterator iter(isolate, object);
4392 if (iter.IsAtEnd()) return maybe(ABSENT); 4391 if (iter.IsAtEnd()) return Just(ABSENT);
4393 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); 4392 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject());
4394 return JSObject::GetElementAttributeWithReceiver( 4393 return JSObject::GetElementAttributeWithReceiver(
4395 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), receiver, 4394 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), receiver,
4396 index, check_prototype); 4395 index, check_prototype);
4397 } 4396 }
4398 4397
4399 // Check for lookup interceptor except when bootstrapping. 4398 // Check for lookup interceptor except when bootstrapping.
4400 if (object->HasIndexedInterceptor() && !isolate->bootstrapper()->IsActive()) { 4399 if (object->HasIndexedInterceptor() && !isolate->bootstrapper()->IsActive()) {
4401 return JSObject::GetElementAttributeWithInterceptor( 4400 return JSObject::GetElementAttributeWithInterceptor(
4402 object, receiver, index, check_prototype); 4401 object, receiver, index, check_prototype);
4403 } 4402 }
4404 4403
4405 return GetElementAttributeWithoutInterceptor( 4404 return GetElementAttributeWithoutInterceptor(
4406 object, receiver, index, check_prototype); 4405 object, receiver, index, check_prototype);
4407 } 4406 }
4408 4407
4409 4408
4410 Maybe<PropertyAttributes> JSObject::GetElementAttributeWithInterceptor( 4409 Maybe<PropertyAttributes> JSObject::GetElementAttributeWithInterceptor(
4411 Handle<JSObject> object, Handle<JSReceiver> receiver, uint32_t index, 4410 Handle<JSObject> object, Handle<JSReceiver> receiver, uint32_t index,
4412 bool check_prototype) { 4411 bool check_prototype) {
4413 Isolate* isolate = object->GetIsolate(); 4412 Isolate* isolate = object->GetIsolate();
4414 HandleScope scope(isolate); 4413 HandleScope scope(isolate);
4415 4414
4416 // Make sure that the top context does not change when doing 4415 // Make sure that the top context does not change when doing
4417 // callbacks or interceptor calls. 4416 // callbacks or interceptor calls.
4418 AssertNoContextChange ncc(isolate); 4417 AssertNoContextChange ncc(isolate);
4419 4418
4420 Maybe<PropertyAttributes> from_interceptor = 4419 Maybe<PropertyAttributes> from_interceptor =
4421 GetElementAttributeFromInterceptor(object, receiver, index); 4420 GetElementAttributeFromInterceptor(object, receiver, index);
4422 if (!from_interceptor.has_value) return Maybe<PropertyAttributes>(); 4421 if (!from_interceptor.has_value) return Nothing<PropertyAttributes>();
4423 if (from_interceptor.value != ABSENT) return maybe(from_interceptor.value); 4422 if (from_interceptor.value != ABSENT) return Just(from_interceptor.value);
4424 4423
4425 return GetElementAttributeWithoutInterceptor(object, receiver, index, 4424 return GetElementAttributeWithoutInterceptor(object, receiver, index,
4426 check_prototype); 4425 check_prototype);
4427 } 4426 }
4428 4427
4429 4428
4430 Maybe<PropertyAttributes> JSObject::GetElementAttributeFromInterceptor( 4429 Maybe<PropertyAttributes> JSObject::GetElementAttributeFromInterceptor(
4431 Handle<JSObject> object, Handle<Object> receiver, uint32_t index) { 4430 Handle<JSObject> object, Handle<Object> receiver, uint32_t index) {
4432 Isolate* isolate = object->GetIsolate(); 4431 Isolate* isolate = object->GetIsolate();
4433 AssertNoContextChange ncc(isolate); 4432 AssertNoContextChange ncc(isolate);
4434 4433
4435 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor()); 4434 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
4436 PropertyCallbackArguments args( 4435 PropertyCallbackArguments args(
4437 isolate, interceptor->data(), *receiver, *object); 4436 isolate, interceptor->data(), *receiver, *object);
4438 if (!interceptor->query()->IsUndefined()) { 4437 if (!interceptor->query()->IsUndefined()) {
4439 v8::IndexedPropertyQueryCallback query = 4438 v8::IndexedPropertyQueryCallback query =
4440 v8::ToCData<v8::IndexedPropertyQueryCallback>(interceptor->query()); 4439 v8::ToCData<v8::IndexedPropertyQueryCallback>(interceptor->query());
4441 LOG(isolate, 4440 LOG(isolate,
4442 ApiIndexedPropertyAccess("interceptor-indexed-has", *object, index)); 4441 ApiIndexedPropertyAccess("interceptor-indexed-has", *object, index));
4443 v8::Handle<v8::Integer> result = args.Call(query, index); 4442 v8::Handle<v8::Integer> result = args.Call(query, index);
4444 if (!result.IsEmpty()) 4443 if (!result.IsEmpty())
4445 return maybe(static_cast<PropertyAttributes>(result->Int32Value())); 4444 return Just(static_cast<PropertyAttributes>(result->Int32Value()));
4446 } else if (!interceptor->getter()->IsUndefined()) { 4445 } else if (!interceptor->getter()->IsUndefined()) {
4447 v8::IndexedPropertyGetterCallback getter = 4446 v8::IndexedPropertyGetterCallback getter =
4448 v8::ToCData<v8::IndexedPropertyGetterCallback>(interceptor->getter()); 4447 v8::ToCData<v8::IndexedPropertyGetterCallback>(interceptor->getter());
4449 LOG(isolate, 4448 LOG(isolate,
4450 ApiIndexedPropertyAccess( 4449 ApiIndexedPropertyAccess(
4451 "interceptor-indexed-get-has", *object, index)); 4450 "interceptor-indexed-get-has", *object, index));
4452 v8::Handle<v8::Value> result = args.Call(getter, index); 4451 v8::Handle<v8::Value> result = args.Call(getter, index);
4453 if (!result.IsEmpty()) return maybe(NONE); 4452 if (!result.IsEmpty()) return Just(NONE);
4454 } 4453 }
4455 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Maybe<PropertyAttributes>()); 4454 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<PropertyAttributes>());
4456 return maybe(ABSENT); 4455 return Just(ABSENT);
4457 } 4456 }
4458 4457
4459 4458
4460 Maybe<PropertyAttributes> JSObject::GetElementAttributeWithoutInterceptor( 4459 Maybe<PropertyAttributes> JSObject::GetElementAttributeWithoutInterceptor(
4461 Handle<JSObject> object, Handle<JSReceiver> receiver, uint32_t index, 4460 Handle<JSObject> object, Handle<JSReceiver> receiver, uint32_t index,
4462 bool check_prototype) { 4461 bool check_prototype) {
4463 PropertyAttributes attr = 4462 PropertyAttributes attr =
4464 object->GetElementsAccessor()->GetAttributes(object, index); 4463 object->GetElementsAccessor()->GetAttributes(object, index);
4465 if (attr != ABSENT) return maybe(attr); 4464 if (attr != ABSENT) return Just(attr);
4466 4465
4467 // Handle [] on String objects. 4466 // Handle [] on String objects.
4468 if (object->IsStringObjectWithCharacterAt(index)) { 4467 if (object->IsStringObjectWithCharacterAt(index)) {
4469 return maybe(static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE)); 4468 return Just(static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE));
4470 } 4469 }
4471 4470
4472 if (!check_prototype) return maybe(ABSENT); 4471 if (!check_prototype) return Just(ABSENT);
4473 4472
4474 PrototypeIterator iter(object->GetIsolate(), object); 4473 PrototypeIterator iter(object->GetIsolate(), object);
4475 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { 4474 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) {
4476 // We need to follow the spec and simulate a call to [[GetOwnProperty]]. 4475 // We need to follow the spec and simulate a call to [[GetOwnProperty]].
4477 return JSProxy::GetElementAttributeWithHandler( 4476 return JSProxy::GetElementAttributeWithHandler(
4478 Handle<JSProxy>::cast(PrototypeIterator::GetCurrent(iter)), receiver, 4477 Handle<JSProxy>::cast(PrototypeIterator::GetCurrent(iter)), receiver,
4479 index); 4478 index);
4480 } 4479 }
4481 if (iter.IsAtEnd()) return maybe(ABSENT); 4480 if (iter.IsAtEnd()) return Just(ABSENT);
4482 return GetElementAttributeWithReceiver( 4481 return GetElementAttributeWithReceiver(
4483 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), receiver, 4482 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), receiver,
4484 index, true); 4483 index, true);
4485 } 4484 }
4486 4485
4487 4486
4488 Handle<NormalizedMapCache> NormalizedMapCache::New(Isolate* isolate) { 4487 Handle<NormalizedMapCache> NormalizedMapCache::New(Isolate* isolate) {
4489 Handle<FixedArray> array( 4488 Handle<FixedArray> array(
4490 isolate->factory()->NewFixedArray(kEntries, TENURED)); 4489 isolate->factory()->NewFixedArray(kEntries, TENURED));
4491 return Handle<NormalizedMapCache>::cast(array); 4490 return Handle<NormalizedMapCache>::cast(array);
(...skipping 9417 matching lines...) Expand 10 before | Expand all | Expand 10 after
13909 v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements()); 13908 v8::Utils::OpenHandle(*result)->HasSloppyArgumentsElements());
13910 // Rebox before returning. 13909 // Rebox before returning.
13911 return handle(*v8::Utils::OpenHandle(*result), isolate); 13910 return handle(*v8::Utils::OpenHandle(*result), isolate);
13912 } 13911 }
13913 13912
13914 13913
13915 Maybe<bool> JSObject::HasRealNamedProperty(Handle<JSObject> object, 13914 Maybe<bool> JSObject::HasRealNamedProperty(Handle<JSObject> object,
13916 Handle<Name> key) { 13915 Handle<Name> key) {
13917 LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR); 13916 LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
13918 Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it); 13917 Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it);
13919 if (!maybe_result.has_value) return Maybe<bool>(); 13918 if (!maybe_result.has_value) return Nothing<bool>();
13920 return maybe(it.IsFound()); 13919 return Just(it.IsFound());
13921 } 13920 }
13922 13921
13923 13922
13924 Maybe<bool> JSObject::HasRealElementProperty(Handle<JSObject> object, 13923 Maybe<bool> JSObject::HasRealElementProperty(Handle<JSObject> object,
13925 uint32_t index) { 13924 uint32_t index) {
13926 Isolate* isolate = object->GetIsolate(); 13925 Isolate* isolate = object->GetIsolate();
13927 HandleScope scope(isolate); 13926 HandleScope scope(isolate);
13928 // Check access rights if needed. 13927 // Check access rights if needed.
13929 if (object->IsAccessCheckNeeded()) { 13928 if (object->IsAccessCheckNeeded()) {
13930 if (!isolate->MayAccess(object)) { 13929 if (!isolate->MayAccess(object)) {
13931 isolate->ReportFailedAccessCheck(object); 13930 isolate->ReportFailedAccessCheck(object);
13932 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Maybe<bool>()); 13931 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>());
13933 return maybe(false); 13932 return Just(false);
13934 } 13933 }
13935 } 13934 }
13936 13935
13937 if (object->IsJSGlobalProxy()) { 13936 if (object->IsJSGlobalProxy()) {
13938 HandleScope scope(isolate); 13937 HandleScope scope(isolate);
13939 PrototypeIterator iter(isolate, object); 13938 PrototypeIterator iter(isolate, object);
13940 if (iter.IsAtEnd()) return maybe(false); 13939 if (iter.IsAtEnd()) return Just(false);
13941 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); 13940 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject());
13942 return HasRealElementProperty( 13941 return HasRealElementProperty(
13943 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), index); 13942 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), index);
13944 } 13943 }
13945 13944
13946 Maybe<PropertyAttributes> result = 13945 Maybe<PropertyAttributes> result =
13947 GetElementAttributeWithoutInterceptor(object, object, index, false); 13946 GetElementAttributeWithoutInterceptor(object, object, index, false);
13948 if (!result.has_value) return Maybe<bool>(); 13947 return result.has_value ? Just(result.value != ABSENT) : Nothing<bool>();
13949 return maybe(result.value != ABSENT);
13950 } 13948 }
13951 13949
13952 13950
13953 Maybe<bool> JSObject::HasRealNamedCallbackProperty(Handle<JSObject> object, 13951 Maybe<bool> JSObject::HasRealNamedCallbackProperty(Handle<JSObject> object,
13954 Handle<Name> key) { 13952 Handle<Name> key) {
13955 LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR); 13953 LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
13956 Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it); 13954 Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it);
13957 if (!maybe_result.has_value) return Maybe<bool>(); 13955 return maybe_result.has_value ? Just(it.state() == LookupIterator::ACCESSOR)
13958 return maybe(it.state() == LookupIterator::ACCESSOR); 13956 : Nothing<bool>();
13959 } 13957 }
13960 13958
13961 13959
13962 int JSObject::NumberOfOwnProperties(PropertyAttributes filter) { 13960 int JSObject::NumberOfOwnProperties(PropertyAttributes filter) {
13963 if (HasFastProperties()) { 13961 if (HasFastProperties()) {
13964 Map* map = this->map(); 13962 Map* map = this->map();
13965 if (filter == NONE) return map->NumberOfOwnDescriptors(); 13963 if (filter == NONE) return map->NumberOfOwnDescriptors();
13966 if (filter & DONT_ENUM) { 13964 if (filter & DONT_ENUM) {
13967 int result = map->EnumLength(); 13965 int result = map->EnumLength();
13968 if (result != kInvalidEnumCacheSentinel) return result; 13966 if (result != kInvalidEnumCacheSentinel) return result;
(...skipping 3196 matching lines...) Expand 10 before | Expand all | Expand 10 after
17165 CompilationInfo* info) { 17163 CompilationInfo* info) {
17166 Handle<DependentCode> codes = DependentCode::InsertCompilationInfo( 17164 Handle<DependentCode> codes = DependentCode::InsertCompilationInfo(
17167 handle(cell->dependent_code(), info->isolate()), 17165 handle(cell->dependent_code(), info->isolate()),
17168 DependentCode::kPropertyCellChangedGroup, info->object_wrapper()); 17166 DependentCode::kPropertyCellChangedGroup, info->object_wrapper());
17169 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); 17167 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes);
17170 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( 17168 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add(
17171 cell, info->zone()); 17169 cell, info->zone());
17172 } 17170 }
17173 17171
17174 } } // namespace v8::internal 17172 } } // namespace v8::internal
OLDNEW
« include/v8.h ('K') | « src/ic/ic-state.cc ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698