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 | 10 |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 return ReadAbsentProperty(it, language_mode); | 716 return ReadAbsentProperty(it, language_mode); |
717 } | 717 } |
718 | 718 |
719 | 719 |
720 // static | 720 // static |
721 MaybeHandle<Object> JSProxy::GetProperty(Isolate* isolate, | 721 MaybeHandle<Object> JSProxy::GetProperty(Isolate* isolate, |
722 Handle<JSProxy> proxy, | 722 Handle<JSProxy> proxy, |
723 Handle<Name> name, | 723 Handle<Name> name, |
724 Handle<Object> receiver, | 724 Handle<Object> receiver, |
725 LanguageMode language_mode) { | 725 LanguageMode language_mode) { |
| 726 // Do not delegate to trap for internal slots |
| 727 if (name->IsPrivate()) return isolate->factory()->undefined_value(); |
| 728 |
726 Handle<Name> trap_name = isolate->factory()->get_string(); | 729 Handle<Name> trap_name = isolate->factory()->get_string(); |
727 // 1. Assert: IsPropertyKey(P) is true. | 730 // 1. Assert: IsPropertyKey(P) is true. |
728 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. | 731 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
729 Handle<Object> handler(proxy->handler(), isolate); | 732 Handle<Object> handler(proxy->handler(), isolate); |
730 // 3. If handler is null, throw a TypeError exception. | 733 // 3. If handler is null, throw a TypeError exception. |
731 if (proxy->IsRevoked()) { | 734 if (proxy->IsRevoked()) { |
732 THROW_NEW_ERROR(isolate, | 735 THROW_NEW_ERROR(isolate, |
733 NewTypeError(MessageTemplate::kProxyRevoked, trap_name), | 736 NewTypeError(MessageTemplate::kProxyRevoked, trap_name), |
734 Object); | 737 Object); |
735 } | 738 } |
| 739 |
736 // 4. Assert: Type(handler) is Object. | 740 // 4. Assert: Type(handler) is Object. |
737 DCHECK(handler->IsJSReceiver()); | 741 DCHECK(handler->IsJSReceiver()); |
738 DCHECK(proxy->target()->IsJSReceiver()); | 742 DCHECK(proxy->target()->IsJSReceiver()); |
739 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. | 743 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. |
740 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); | 744 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); |
741 // 6. Let trap be ? GetMethod(handler, "get"). | 745 // 6. Let trap be ? GetMethod(handler, "get"). |
742 Handle<Object> trap; | 746 Handle<Object> trap; |
743 ASSIGN_RETURN_ON_EXCEPTION( | 747 ASSIGN_RETURN_ON_EXCEPTION( |
744 isolate, trap, | 748 isolate, trap, |
745 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), Object); | 749 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), Object); |
(...skipping 3821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4567 | 4571 |
4568 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, | 4572 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, |
4569 ElementsKind to_kind) { | 4573 ElementsKind to_kind) { |
4570 Handle<Map> map(object->map()); | 4574 Handle<Map> map(object->map()); |
4571 return Map::TransitionElementsTo(map, to_kind); | 4575 return Map::TransitionElementsTo(map, to_kind); |
4572 } | 4576 } |
4573 | 4577 |
4574 | 4578 |
4575 Maybe<bool> JSProxy::HasProperty(Isolate* isolate, Handle<JSProxy> proxy, | 4579 Maybe<bool> JSProxy::HasProperty(Isolate* isolate, Handle<JSProxy> proxy, |
4576 Handle<Name> name) { | 4580 Handle<Name> name) { |
| 4581 // Do not delegate to trap for internal slots |
| 4582 if (name->IsPrivate()) return Just(false); |
| 4583 |
4577 // 1. (Assert) | 4584 // 1. (Assert) |
4578 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. | 4585 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
4579 Handle<Object> handler(proxy->handler(), isolate); | 4586 Handle<Object> handler(proxy->handler(), isolate); |
4580 // 3. If handler is null, throw a TypeError exception. | 4587 // 3. If handler is null, throw a TypeError exception. |
4581 if (proxy->IsRevoked()) { | 4588 if (proxy->IsRevoked()) { |
4582 isolate->Throw(*isolate->factory()->NewTypeError( | 4589 isolate->Throw(*isolate->factory()->NewTypeError( |
4583 MessageTemplate::kProxyRevoked, isolate->factory()->has_string())); | 4590 MessageTemplate::kProxyRevoked, isolate->factory()->has_string())); |
4584 return Nothing<bool>(); | 4591 return Nothing<bool>(); |
4585 } | 4592 } |
| 4593 |
4586 // 4. Assert: Type(handler) is Object. | 4594 // 4. Assert: Type(handler) is Object. |
4587 DCHECK(handler->IsJSReceiver()); | 4595 DCHECK(handler->IsJSReceiver()); |
4588 DCHECK(proxy->target()->IsJSReceiver()); | 4596 DCHECK(proxy->target()->IsJSReceiver()); |
4589 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. | 4597 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. |
4590 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); | 4598 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); |
4591 // 6. Let trap be ? GetMethod(handler, "has"). | 4599 // 6. Let trap be ? GetMethod(handler, "has"). |
4592 Handle<Object> trap; | 4600 Handle<Object> trap; |
4593 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 4601 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
4594 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler), | 4602 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler), |
4595 isolate->factory()->has_string()), | 4603 isolate->factory()->has_string()), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4634 } | 4642 } |
4635 } | 4643 } |
4636 // 10. Return booleanTrapResult. | 4644 // 10. Return booleanTrapResult. |
4637 return Just(boolean_trap_result); | 4645 return Just(boolean_trap_result); |
4638 } | 4646 } |
4639 | 4647 |
4640 | 4648 |
4641 Maybe<bool> JSProxy::SetProperty(Handle<JSProxy> proxy, Handle<Name> name, | 4649 Maybe<bool> JSProxy::SetProperty(Handle<JSProxy> proxy, Handle<Name> name, |
4642 Handle<Object> value, Handle<Object> receiver, | 4650 Handle<Object> value, Handle<Object> receiver, |
4643 LanguageMode language_mode) { | 4651 LanguageMode language_mode) { |
| 4652 // Do not delegate to trap for internal slots |
| 4653 if (name->IsPrivate()) return Just(false); |
| 4654 |
4644 Isolate* isolate = proxy->GetIsolate(); | 4655 Isolate* isolate = proxy->GetIsolate(); |
4645 Factory* factory = isolate->factory(); | 4656 Factory* factory = isolate->factory(); |
4646 Handle<String> trap_name = factory->set_string(); | 4657 Handle<String> trap_name = factory->set_string(); |
4647 ShouldThrow should_throw = | 4658 ShouldThrow should_throw = |
4648 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 4659 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
4649 | 4660 |
4650 if (proxy->IsRevoked()) { | 4661 if (proxy->IsRevoked()) { |
4651 isolate->Throw( | 4662 isolate->Throw( |
4652 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); | 4663 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); |
4653 return Nothing<bool>(); | 4664 return Nothing<bool>(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4696 return Nothing<bool>(); | 4707 return Nothing<bool>(); |
4697 } | 4708 } |
4698 } | 4709 } |
4699 return Just(true); | 4710 return Just(true); |
4700 } | 4711 } |
4701 | 4712 |
4702 | 4713 |
4703 Maybe<bool> JSProxy::DeletePropertyOrElement(Handle<JSProxy> proxy, | 4714 Maybe<bool> JSProxy::DeletePropertyOrElement(Handle<JSProxy> proxy, |
4704 Handle<Name> name, | 4715 Handle<Name> name, |
4705 LanguageMode language_mode) { | 4716 LanguageMode language_mode) { |
| 4717 // Do not delegate to trap for internal slots |
| 4718 if (name->IsPrivate()) return Just(true); |
| 4719 |
4706 ShouldThrow should_throw = | 4720 ShouldThrow should_throw = |
4707 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 4721 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
4708 Isolate* isolate = proxy->GetIsolate(); | 4722 Isolate* isolate = proxy->GetIsolate(); |
4709 Factory* factory = isolate->factory(); | 4723 Factory* factory = isolate->factory(); |
4710 Handle<String> trap_name = factory->deleteProperty_string(); | 4724 Handle<String> trap_name = factory->deleteProperty_string(); |
4711 | 4725 |
4712 if (proxy->IsRevoked()) { | 4726 if (proxy->IsRevoked()) { |
4713 isolate->Throw( | 4727 isolate->Throw( |
4714 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); | 4728 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); |
4715 return Nothing<bool>(); | 4729 return Nothing<bool>(); |
(...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6799 } | 6813 } |
6800 return success; | 6814 return success; |
6801 } | 6815 } |
6802 | 6816 |
6803 | 6817 |
6804 // ES6 9.5.6 | 6818 // ES6 9.5.6 |
6805 // static | 6819 // static |
6806 bool JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> proxy, | 6820 bool JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> proxy, |
6807 Handle<Object> key, PropertyDescriptor* desc, | 6821 Handle<Object> key, PropertyDescriptor* desc, |
6808 ShouldThrow should_throw) { | 6822 ShouldThrow should_throw) { |
| 6823 // Do not delegate to trap for internal slots |
| 6824 if (key->IsSymbol() && Symbol::cast(*key)->is_private()) return false; |
| 6825 |
6809 Handle<String> trap_name = isolate->factory()->defineProperty_string(); | 6826 Handle<String> trap_name = isolate->factory()->defineProperty_string(); |
6810 // 1. Assert: IsPropertyKey(P) is true. | 6827 // 1. Assert: IsPropertyKey(P) is true. |
6811 DCHECK(key->IsName() || key->IsNumber()); | 6828 DCHECK(key->IsName() || key->IsNumber()); |
6812 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. | 6829 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
6813 Handle<Object> handler(proxy->handler(), isolate); | 6830 Handle<Object> handler(proxy->handler(), isolate); |
6814 // 3. If handler is null, throw a TypeError exception. | 6831 // 3. If handler is null, throw a TypeError exception. |
6815 if (proxy->IsRevoked()) { | 6832 if (proxy->IsRevoked()) { |
6816 isolate->Throw(*isolate->factory()->NewTypeError( | 6833 isolate->Throw(*isolate->factory()->NewTypeError( |
6817 MessageTemplate::kProxyRevoked, trap_name)); | 6834 MessageTemplate::kProxyRevoked, trap_name)); |
6818 return false; | 6835 return false; |
6819 } | 6836 } |
| 6837 |
6820 // 4. Assert: Type(handler) is Object. | 6838 // 4. Assert: Type(handler) is Object. |
6821 DCHECK(handler->IsJSReceiver()); | 6839 DCHECK(handler->IsJSReceiver()); |
6822 // If the handler is not null, the target can't be null either. | 6840 // If the handler is not null, the target can't be null either. |
6823 DCHECK(proxy->target()->IsJSReceiver()); | 6841 DCHECK(proxy->target()->IsJSReceiver()); |
6824 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. | 6842 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. |
6825 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); | 6843 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); |
6826 // 6. Let trap be ? GetMethod(handler, "defineProperty"). | 6844 // 6. Let trap be ? GetMethod(handler, "defineProperty"). |
6827 Handle<Object> trap; | 6845 Handle<Object> trap; |
6828 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 6846 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
6829 isolate, trap, | 6847 isolate, trap, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6983 PropertyDescriptor::IsDataDescriptor(desc)); | 7001 PropertyDescriptor::IsDataDescriptor(desc)); |
6984 return true; | 7002 return true; |
6985 } | 7003 } |
6986 | 7004 |
6987 | 7005 |
6988 // ES6 9.5.5 | 7006 // ES6 9.5.5 |
6989 // static | 7007 // static |
6990 bool JSProxy::GetOwnPropertyDescriptor(Isolate* isolate, Handle<JSProxy> proxy, | 7008 bool JSProxy::GetOwnPropertyDescriptor(Isolate* isolate, Handle<JSProxy> proxy, |
6991 Handle<Name> name, | 7009 Handle<Name> name, |
6992 PropertyDescriptor* desc) { | 7010 PropertyDescriptor* desc) { |
| 7011 // Do not delegate to trap for internal slots |
| 7012 if (name->IsPrivate()) return false; |
| 7013 |
6993 Handle<String> trap_name = | 7014 Handle<String> trap_name = |
6994 isolate->factory()->getOwnPropertyDescriptor_string(); | 7015 isolate->factory()->getOwnPropertyDescriptor_string(); |
6995 // 1. (Assert) | 7016 // 1. (Assert) |
6996 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. | 7017 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
6997 Handle<Object> handler(proxy->handler(), isolate); | 7018 Handle<Object> handler(proxy->handler(), isolate); |
6998 // 3. If handler is null, throw a TypeError exception. | 7019 // 3. If handler is null, throw a TypeError exception. |
6999 if (proxy->IsRevoked()) { | 7020 if (proxy->IsRevoked()) { |
7000 isolate->Throw(*isolate->factory()->NewTypeError( | 7021 isolate->Throw(*isolate->factory()->NewTypeError( |
7001 MessageTemplate::kProxyRevoked, trap_name)); | 7022 MessageTemplate::kProxyRevoked, trap_name)); |
7002 return false; | 7023 return false; |
(...skipping 12052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19055 if (cell->value() != *new_value) { | 19076 if (cell->value() != *new_value) { |
19056 cell->set_value(*new_value); | 19077 cell->set_value(*new_value); |
19057 Isolate* isolate = cell->GetIsolate(); | 19078 Isolate* isolate = cell->GetIsolate(); |
19058 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19079 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19059 isolate, DependentCode::kPropertyCellChangedGroup); | 19080 isolate, DependentCode::kPropertyCellChangedGroup); |
19060 } | 19081 } |
19061 } | 19082 } |
19062 | 19083 |
19063 } // namespace internal | 19084 } // namespace internal |
19064 } // namespace v8 | 19085 } // namespace v8 |
OLD | NEW |