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

Side by Side Diff: src/objects.cc

Issue 1479143002: [proxies] [[HasProperty]]: fix trap call. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 5 years 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
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/harmony/proxies-enumerate.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 10
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 647
648 // static 648 // static
649 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) { 649 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) {
650 for (; it->IsFound(); it->Next()) { 650 for (; it->IsFound(); it->Next()) {
651 switch (it->state()) { 651 switch (it->state()) {
652 case LookupIterator::NOT_FOUND: 652 case LookupIterator::NOT_FOUND:
653 case LookupIterator::TRANSITION: 653 case LookupIterator::TRANSITION:
654 UNREACHABLE(); 654 UNREACHABLE();
655 case LookupIterator::JSPROXY: 655 case LookupIterator::JSPROXY:
656 // Call the "has" trap on proxies. 656 // Call the "has" trap on proxies.
657 return JSProxy::HasPropertyWithHandler(it->GetHolder<JSProxy>(), 657 return JSProxy::HasProperty(it->isolate(), it->GetHolder<JSProxy>(),
658 it->GetName()); 658 it->GetName());
659 case LookupIterator::INTERCEPTOR: { 659 case LookupIterator::INTERCEPTOR: {
660 Maybe<PropertyAttributes> result = 660 Maybe<PropertyAttributes> result =
661 JSObject::GetPropertyAttributesWithInterceptor(it); 661 JSObject::GetPropertyAttributesWithInterceptor(it);
662 if (!result.IsJust()) return Nothing<bool>(); 662 if (!result.IsJust()) return Nothing<bool>();
663 if (result.FromJust() != ABSENT) return Just(true); 663 if (result.FromJust() != ABSENT) return Just(true);
664 break; 664 break;
665 } 665 }
666 case LookupIterator::ACCESS_CHECK: { 666 case LookupIterator::ACCESS_CHECK: {
667 if (it->HasAccess()) break; 667 if (it->HasAccess()) break;
668 Maybe<PropertyAttributes> result = 668 Maybe<PropertyAttributes> result =
(...skipping 3847 matching lines...) Expand 10 before | Expand all | Expand 10 after
4516 } 4516 }
4517 4517
4518 4518
4519 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, 4519 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object,
4520 ElementsKind to_kind) { 4520 ElementsKind to_kind) {
4521 Handle<Map> map(object->map()); 4521 Handle<Map> map(object->map());
4522 return Map::TransitionElementsTo(map, to_kind); 4522 return Map::TransitionElementsTo(map, to_kind);
4523 } 4523 }
4524 4524
4525 4525
4526 Maybe<bool> JSProxy::HasPropertyWithHandler(Handle<JSProxy> proxy, 4526 Maybe<bool> JSProxy::HasProperty(Isolate* isolate, Handle<JSProxy> proxy,
4527 Handle<Name> name) { 4527 Handle<Name> name) {
4528 Isolate* isolate = proxy->GetIsolate(); 4528 // 1. (Assert)
4529 4529 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
4530 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 4530 Handle<Object> handler(proxy->handler(), isolate);
4531 if (name->IsSymbol()) return Just(false); 4531 // 3. If handler is null, throw a TypeError exception.
4532 4532 if (JSProxy::IsRevoked(proxy)) {
4533 Handle<Object> args[] = { name }; 4533 isolate->Throw(*isolate->factory()->NewTypeError(
4534 Handle<Object> result; 4534 MessageTemplate::kProxyRevoked, isolate->factory()->has_string()));
4535 return Nothing<bool>();
4536 }
4537 // 4. Assert: Type(handler) is Object.
4538 DCHECK(handler->IsJSReceiver());
4539 DCHECK(proxy->target()->IsJSReceiver());
4540 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
4541 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
4542 // 6. Let trap be ? GetMethod(handler, "has").
4543 Handle<Object> trap;
4535 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 4544 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
4536 isolate, result, CallTrap(proxy, "has", isolate->derived_has_trap(), 4545 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler),
4537 arraysize(args), args), 4546 isolate->factory()->has_string()),
4538 Nothing<bool>()); 4547 Nothing<bool>());
4539 4548 // 7. If trap is undefined, then
4540 return Just(result->BooleanValue()); 4549 if (trap->IsUndefined()) {
4550 // 7a. Return target.[[HasProperty]](P).
4551 return JSReceiver::HasProperty(target, name);
4552 }
4553 // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, «target, P»)).
4554 Handle<Object> trap_result_obj;
4555 Handle<Object> args[] = {target, name};
4556 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
4557 isolate, trap_result_obj,
4558 Execution::Call(isolate, trap, handler, arraysize(args), args),
4559 Nothing<bool>());
4560 bool boolean_trap_result = trap_result_obj->BooleanValue();
4561 // 9. If booleanTrapResult is false, then:
4562 if (!boolean_trap_result) {
4563 // 9a. Let targetDesc be ? target.[[GetOwnProperty]](P).
4564 PropertyDescriptor target_desc;
4565 bool target_found = JSReceiver::GetOwnPropertyDescriptor(
4566 isolate, target, name, &target_desc);
4567 // 9b. If targetDesc is not undefined, then:
4568 if (target_found) {
4569 // 9b i. If targetDesc.[[Configurable]] is false, throw a TypeError
4570 // exception.
4571 if (!target_desc.configurable()) {
4572 isolate->Throw(*isolate->factory()->NewTypeError(
4573 MessageTemplate::kProxyTargetPropNotConfigurable, name));
4574 return Nothing<bool>();
4575 }
4576 // 9b ii. Let extensibleTarget be ? IsExtensible(target).
4577 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target);
4578 if (maybe_extensible.IsNothing()) return maybe_extensible;
4579 bool extensible_target = maybe_extensible.FromJust();
4580 // 9b iii. If extensibleTarget is false, throw a TypeError exception.
4581 if (!extensible_target) {
4582 isolate->Throw(*isolate->factory()->NewTypeError(
4583 MessageTemplate::kProxyTargetNotExtensible));
4584 }
4585 }
4586 }
4587 // 10. Return booleanTrapResult.
4588 return Just(boolean_trap_result);
4541 } 4589 }
4542 4590
4543 4591
4544 Maybe<bool> JSProxy::SetPropertyWithHandler(Handle<JSProxy> proxy, 4592 Maybe<bool> JSProxy::SetPropertyWithHandler(Handle<JSProxy> proxy,
4545 Handle<Object> receiver, 4593 Handle<Object> receiver,
4546 Handle<Name> name, 4594 Handle<Name> name,
4547 Handle<Object> value, 4595 Handle<Object> value,
4548 ShouldThrow should_throw) { 4596 ShouldThrow should_throw) {
4549 Isolate* isolate = proxy->GetIsolate(); 4597 Isolate* isolate = proxy->GetIsolate();
4550 4598
(...skipping 14392 matching lines...) Expand 10 before | Expand all | Expand 10 after
18943 if (cell->value() != *new_value) { 18991 if (cell->value() != *new_value) {
18944 cell->set_value(*new_value); 18992 cell->set_value(*new_value);
18945 Isolate* isolate = cell->GetIsolate(); 18993 Isolate* isolate = cell->GetIsolate();
18946 cell->dependent_code()->DeoptimizeDependentCodeGroup( 18994 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18947 isolate, DependentCode::kPropertyCellChangedGroup); 18995 isolate, DependentCode::kPropertyCellChangedGroup);
18948 } 18996 }
18949 } 18997 }
18950 18998
18951 } // namespace internal 18999 } // namespace internal
18952 } // namespace v8 19000 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/harmony/proxies-enumerate.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698