OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 8652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8663 PrototypeIterator::WhereToEnd end = type == OWN_ONLY | 8663 PrototypeIterator::WhereToEnd end = type == OWN_ONLY |
8664 ? PrototypeIterator::END_AT_NON_HIDDEN | 8664 ? PrototypeIterator::END_AT_NON_HIDDEN |
8665 : PrototypeIterator::END_AT_NULL; | 8665 : PrototypeIterator::END_AT_NULL; |
8666 for (PrototypeIterator iter(isolate, object, | 8666 for (PrototypeIterator iter(isolate, object, |
8667 PrototypeIterator::START_AT_RECEIVER, end); | 8667 PrototypeIterator::START_AT_RECEIVER, end); |
8668 !iter.IsAtEnd(); iter.Advance()) { | 8668 !iter.IsAtEnd(); iter.Advance()) { |
8669 Handle<JSReceiver> current = | 8669 Handle<JSReceiver> current = |
8670 PrototypeIterator::GetCurrent<JSReceiver>(iter); | 8670 PrototypeIterator::GetCurrent<JSReceiver>(iter); |
8671 Maybe<bool> result = Just(false); // Dummy initialization. | 8671 Maybe<bool> result = Just(false); // Dummy initialization. |
8672 if (current->IsJSProxy()) { | 8672 if (current->IsJSProxy()) { |
8673 if (type == OWN_ONLY) { | 8673 result = JSProxy::OwnPropertyKeys(isolate, receiver, |
8674 result = JSProxy::OwnPropertyKeys(isolate, receiver, | 8674 Handle<JSProxy>::cast(current), filter, |
8675 Handle<JSProxy>::cast(current), | 8675 accumulator); |
8676 filter, accumulator); | |
8677 } else { | |
8678 DCHECK(type == INCLUDE_PROTOS); | |
8679 result = JSProxy::Enumerate( | |
8680 isolate, receiver, Handle<JSProxy>::cast(current), accumulator); | |
8681 } | |
8682 } else { | 8676 } else { |
8683 DCHECK(current->IsJSObject()); | 8677 DCHECK(current->IsJSObject()); |
8684 result = GetKeysFromJSObject(isolate, receiver, | 8678 result = GetKeysFromJSObject(isolate, receiver, |
8685 Handle<JSObject>::cast(current), &filter, | 8679 Handle<JSObject>::cast(current), &filter, |
8686 type, accumulator); | 8680 type, accumulator); |
8687 } | 8681 } |
8688 MAYBE_RETURN(result, Nothing<bool>()); | 8682 MAYBE_RETURN(result, Nothing<bool>()); |
8689 if (!result.FromJust()) break; // |false| means "stop iterating". | 8683 if (!result.FromJust()) break; // |false| means "stop iterating". |
8690 } | 8684 } |
8691 return Just(true); | 8685 return Just(true); |
8692 } | 8686 } |
8693 | 8687 |
8694 | 8688 |
8695 // ES6 9.5.11 | |
8696 // Returns false in case of exception. | |
8697 // static | |
8698 Maybe<bool> JSProxy::Enumerate(Isolate* isolate, Handle<JSReceiver> receiver, | |
8699 Handle<JSProxy> proxy, | |
8700 KeyAccumulator* accumulator) { | |
8701 STACK_CHECK(Nothing<bool>()); | |
8702 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. | |
8703 Handle<Object> handler(proxy->handler(), isolate); | |
8704 // 2. If handler is null, throw a TypeError exception. | |
8705 // 3. Assert: Type(handler) is Object. | |
8706 if (proxy->IsRevoked()) { | |
8707 isolate->Throw(*isolate->factory()->NewTypeError( | |
8708 MessageTemplate::kProxyRevoked, | |
8709 isolate->factory()->enumerate_string())); | |
8710 return Nothing<bool>(); | |
8711 } | |
8712 // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. | |
8713 Handle<JSReceiver> target(proxy->target(), isolate); | |
8714 // 5. Let trap be ? GetMethod(handler, "enumerate"). | |
8715 Handle<Object> trap; | |
8716 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
8717 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler), | |
8718 isolate->factory()->enumerate_string()), | |
8719 Nothing<bool>()); | |
8720 // 6. If trap is undefined, then | |
8721 if (trap->IsUndefined()) { | |
8722 // 6a. Return target.[[Enumerate]](). | |
8723 return GetKeys_Internal(isolate, receiver, target, INCLUDE_PROTOS, | |
8724 ENUMERABLE_STRINGS, accumulator); | |
8725 } | |
8726 // The "proxy_enumerate" helper calls the trap (steps 7 - 9), which returns | |
8727 // a generator; it then iterates over that generator until it's exhausted | |
8728 // and returns an array containing the generated values. | |
8729 Handle<Object> trap_result_array; | |
8730 Handle<Object> args[] = {trap, handler, target}; | |
8731 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
8732 isolate, trap_result_array, | |
8733 Execution::Call(isolate, isolate->proxy_enumerate(), | |
8734 isolate->factory()->undefined_value(), arraysize(args), | |
8735 args), | |
8736 Nothing<bool>()); | |
8737 accumulator->NextPrototype(); | |
8738 accumulator->AddKeysFromProxy(Handle<JSObject>::cast(trap_result_array)); | |
8739 return Just(true); | |
8740 } | |
8741 | |
8742 | |
8743 // ES6 9.5.12 | 8689 // ES6 9.5.12 |
8744 // Returns |true| on success, |nothing| in case of exception. | 8690 // Returns |true| on success, |nothing| in case of exception. |
8745 // static | 8691 // static |
8746 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate, | 8692 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate, |
8747 Handle<JSReceiver> receiver, | 8693 Handle<JSReceiver> receiver, |
8748 Handle<JSProxy> proxy, | 8694 Handle<JSProxy> proxy, |
8749 PropertyFilter filter, | 8695 PropertyFilter filter, |
8750 KeyAccumulator* accumulator) { | 8696 KeyAccumulator* accumulator) { |
8751 STACK_CHECK(Nothing<bool>()); | 8697 STACK_CHECK(Nothing<bool>()); |
8752 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. | 8698 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
(...skipping 11136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19889 if (cell->value() != *new_value) { | 19835 if (cell->value() != *new_value) { |
19890 cell->set_value(*new_value); | 19836 cell->set_value(*new_value); |
19891 Isolate* isolate = cell->GetIsolate(); | 19837 Isolate* isolate = cell->GetIsolate(); |
19892 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19838 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19893 isolate, DependentCode::kPropertyCellChangedGroup); | 19839 isolate, DependentCode::kPropertyCellChangedGroup); |
19894 } | 19840 } |
19895 } | 19841 } |
19896 | 19842 |
19897 } // namespace internal | 19843 } // namespace internal |
19898 } // namespace v8 | 19844 } // namespace v8 |
OLD | NEW |