| OLD | NEW |
| 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 "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 | 646 |
| 647 // static | 647 // static |
| 648 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) { | 648 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) { |
| 649 for (; it->IsFound(); it->Next()) { | 649 for (; it->IsFound(); it->Next()) { |
| 650 switch (it->state()) { | 650 switch (it->state()) { |
| 651 case LookupIterator::NOT_FOUND: | 651 case LookupIterator::NOT_FOUND: |
| 652 case LookupIterator::TRANSITION: | 652 case LookupIterator::TRANSITION: |
| 653 UNREACHABLE(); | 653 UNREACHABLE(); |
| 654 case LookupIterator::JSPROXY: | 654 case LookupIterator::JSPROXY: |
| 655 // Call the "has" trap on proxies. | 655 // Call the "has" trap on proxies. |
| 656 return JSProxy::HasPropertyWithHandler(it->GetHolder<JSProxy>(), | 656 return JSProxy::HasProperty(it->isolate(), it->GetHolder<JSProxy>(), |
| 657 it->GetName()); | 657 it->GetName()); |
| 658 case LookupIterator::INTERCEPTOR: { | 658 case LookupIterator::INTERCEPTOR: { |
| 659 Maybe<PropertyAttributes> result = | 659 Maybe<PropertyAttributes> result = |
| 660 JSObject::GetPropertyAttributesWithInterceptor(it); | 660 JSObject::GetPropertyAttributesWithInterceptor(it); |
| 661 if (!result.IsJust()) return Nothing<bool>(); | 661 if (!result.IsJust()) return Nothing<bool>(); |
| 662 if (result.FromJust() != ABSENT) return Just(true); | 662 if (result.FromJust() != ABSENT) return Just(true); |
| 663 break; | 663 break; |
| 664 } | 664 } |
| 665 case LookupIterator::ACCESS_CHECK: { | 665 case LookupIterator::ACCESS_CHECK: { |
| 666 if (it->HasAccess()) break; | 666 if (it->HasAccess()) break; |
| 667 Maybe<PropertyAttributes> result = | 667 Maybe<PropertyAttributes> result = |
| (...skipping 3844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4512 } | 4512 } |
| 4513 | 4513 |
| 4514 | 4514 |
| 4515 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, | 4515 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, |
| 4516 ElementsKind to_kind) { | 4516 ElementsKind to_kind) { |
| 4517 Handle<Map> map(object->map()); | 4517 Handle<Map> map(object->map()); |
| 4518 return Map::TransitionElementsTo(map, to_kind); | 4518 return Map::TransitionElementsTo(map, to_kind); |
| 4519 } | 4519 } |
| 4520 | 4520 |
| 4521 | 4521 |
| 4522 Maybe<bool> JSProxy::HasPropertyWithHandler(Handle<JSProxy> proxy, | 4522 Maybe<bool> JSProxy::HasProperty(Isolate* isolate, Handle<JSProxy> proxy, |
| 4523 Handle<Name> name) { | 4523 Handle<Name> name) { |
| 4524 Isolate* isolate = proxy->GetIsolate(); | 4524 // 1. (Assert) |
| 4525 | 4525 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
| 4526 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 4526 Handle<Object> handler(proxy->handler(), isolate); |
| 4527 if (name->IsSymbol()) return Just(false); | 4527 // 3. If handler is null, throw a TypeError exception. |
| 4528 | 4528 if (JSProxy::IsRevoked(proxy)) { |
| 4529 Handle<Object> args[] = { name }; | 4529 isolate->Throw(*isolate->factory()->NewTypeError( |
| 4530 Handle<Object> result; | 4530 MessageTemplate::kProxyRevoked, isolate->factory()->has_string())); |
| 4531 return Nothing<bool>(); |
| 4532 } |
| 4533 // 4. Assert: Type(handler) is Object. |
| 4534 DCHECK(handler->IsJSReceiver()); |
| 4535 DCHECK(proxy->target()->IsJSReceiver()); |
| 4536 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. |
| 4537 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); |
| 4538 // 6. Let trap be ? GetMethod(handler, "has"). |
| 4539 Handle<Object> trap; |
| 4531 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 4540 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 4532 isolate, result, CallTrap(proxy, "has", isolate->derived_has_trap(), | 4541 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler), |
| 4533 arraysize(args), args), | 4542 isolate->factory()->has_string()), |
| 4534 Nothing<bool>()); | 4543 Nothing<bool>()); |
| 4535 | 4544 // 7. If trap is undefined, then |
| 4536 return Just(result->BooleanValue()); | 4545 if (trap->IsUndefined()) { |
| 4546 // 7a. Return target.[[HasProperty]](P). |
| 4547 return JSReceiver::HasProperty(target, name); |
| 4548 } |
| 4549 // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, «target, P»)). |
| 4550 Handle<Object> trap_result_obj; |
| 4551 Handle<Object> args[] = {target, name}; |
| 4552 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 4553 isolate, trap_result_obj, |
| 4554 Execution::Call(isolate, trap, handler, arraysize(args), args), |
| 4555 Nothing<bool>()); |
| 4556 bool boolean_trap_result = trap_result_obj->BooleanValue(); |
| 4557 // 9. If booleanTrapResult is false, then: |
| 4558 if (!boolean_trap_result) { |
| 4559 // 9a. Let targetDesc be ? target.[[GetOwnProperty]](P). |
| 4560 PropertyDescriptor target_desc; |
| 4561 bool target_found = JSReceiver::GetOwnPropertyDescriptor( |
| 4562 isolate, target, name, &target_desc); |
| 4563 // 9b. If targetDesc is not undefined, then: |
| 4564 if (target_found) { |
| 4565 // 9b i. If targetDesc.[[Configurable]] is false, throw a TypeError |
| 4566 // exception. |
| 4567 if (!target_desc.configurable()) { |
| 4568 isolate->Throw(*isolate->factory()->NewTypeError( |
| 4569 MessageTemplate::kProxyTargetPropNotConfigurable, name)); |
| 4570 return Nothing<bool>(); |
| 4571 } |
| 4572 // 9b ii. Let extensibleTarget be ? IsExtensible(target). |
| 4573 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); |
| 4574 if (maybe_extensible.IsNothing()) return maybe_extensible; |
| 4575 bool extensible_target = maybe_extensible.FromJust(); |
| 4576 // 9b iii. If extensibleTarget is false, throw a TypeError exception. |
| 4577 if (!extensible_target) { |
| 4578 isolate->Throw(*isolate->factory()->NewTypeError( |
| 4579 MessageTemplate::kProxyTargetNotExtensible)); |
| 4580 } |
| 4581 } |
| 4582 } |
| 4583 // 10. Return booleanTrapResult. |
| 4584 return Just(boolean_trap_result); |
| 4537 } | 4585 } |
| 4538 | 4586 |
| 4539 | 4587 |
| 4540 Maybe<bool> JSProxy::SetPropertyWithHandler(Handle<JSProxy> proxy, | 4588 Maybe<bool> JSProxy::SetPropertyWithHandler(Handle<JSProxy> proxy, |
| 4541 Handle<Object> receiver, | 4589 Handle<Object> receiver, |
| 4542 Handle<Name> name, | 4590 Handle<Name> name, |
| 4543 Handle<Object> value, | 4591 Handle<Object> value, |
| 4544 ShouldThrow should_throw) { | 4592 ShouldThrow should_throw) { |
| 4545 Isolate* isolate = proxy->GetIsolate(); | 4593 Isolate* isolate = proxy->GetIsolate(); |
| 4546 | 4594 |
| (...skipping 14321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18868 if (cell->value() != *new_value) { | 18916 if (cell->value() != *new_value) { |
| 18869 cell->set_value(*new_value); | 18917 cell->set_value(*new_value); |
| 18870 Isolate* isolate = cell->GetIsolate(); | 18918 Isolate* isolate = cell->GetIsolate(); |
| 18871 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18919 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 18872 isolate, DependentCode::kPropertyCellChangedGroup); | 18920 isolate, DependentCode::kPropertyCellChangedGroup); |
| 18873 } | 18921 } |
| 18874 } | 18922 } |
| 18875 | 18923 |
| 18876 } // namespace internal | 18924 } // namespace internal |
| 18877 } // namespace v8 | 18925 } // namespace v8 |
| OLD | NEW |