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

Side by Side Diff: src/objects.cc

Issue 1748923003: [proxies] use [[GetPrototypeOf]] trap in for-in (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge with master Created 4 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
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('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 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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 677
678 678
679 // static 679 // static
680 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) { 680 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) {
681 for (; it->IsFound(); it->Next()) { 681 for (; it->IsFound(); it->Next()) {
682 switch (it->state()) { 682 switch (it->state()) {
683 case LookupIterator::NOT_FOUND: 683 case LookupIterator::NOT_FOUND:
684 case LookupIterator::TRANSITION: 684 case LookupIterator::TRANSITION:
685 UNREACHABLE(); 685 UNREACHABLE();
686 case LookupIterator::JSPROXY: 686 case LookupIterator::JSPROXY:
687 // Call the "has" trap on proxies.
688 return JSProxy::HasProperty(it->isolate(), it->GetHolder<JSProxy>(), 687 return JSProxy::HasProperty(it->isolate(), it->GetHolder<JSProxy>(),
689 it->GetName()); 688 it->GetName());
690 case LookupIterator::INTERCEPTOR: { 689 case LookupIterator::INTERCEPTOR: {
691 Maybe<PropertyAttributes> result = 690 Maybe<PropertyAttributes> result =
692 JSObject::GetPropertyAttributesWithInterceptor(it); 691 JSObject::GetPropertyAttributesWithInterceptor(it);
693 if (!result.IsJust()) return Nothing<bool>(); 692 if (result.IsNothing()) return Nothing<bool>();
694 if (result.FromJust() != ABSENT) return Just(true); 693 if (result.FromJust() != ABSENT) return Just(true);
695 break; 694 break;
696 } 695 }
697 case LookupIterator::ACCESS_CHECK: { 696 case LookupIterator::ACCESS_CHECK: {
698 if (it->HasAccess()) break; 697 if (it->HasAccess()) break;
699 Maybe<PropertyAttributes> result = 698 Maybe<PropertyAttributes> result =
700 JSObject::GetPropertyAttributesWithFailedAccessCheck(it); 699 JSObject::GetPropertyAttributesWithFailedAccessCheck(it);
701 if (!result.IsJust()) return Nothing<bool>(); 700 if (result.IsNothing()) return Nothing<bool>();
702 return Just(result.FromJust() != ABSENT); 701 return Just(result.FromJust() != ABSENT);
703 } 702 }
704 case LookupIterator::INTEGER_INDEXED_EXOTIC: 703 case LookupIterator::INTEGER_INDEXED_EXOTIC:
705 // TypedArray out-of-bounds access. 704 // TypedArray out-of-bounds access.
706 return Just(false); 705 return Just(false);
707 case LookupIterator::ACCESSOR: 706 case LookupIterator::ACCESSOR:
708 case LookupIterator::DATA: 707 case LookupIterator::DATA:
709 return Just(true); 708 return Just(true);
710 } 709 }
711 } 710 }
(...skipping 4425 matching lines...) Expand 10 before | Expand all | Expand 10 after
5137 if (receiver->IsJSBoundFunction()) { 5136 if (receiver->IsJSBoundFunction()) {
5138 return JSBoundFunction::GetFunctionRealm( 5137 return JSBoundFunction::GetFunctionRealm(
5139 Handle<JSBoundFunction>::cast(receiver)); 5138 Handle<JSBoundFunction>::cast(receiver));
5140 } 5139 }
5141 5140
5142 return JSObject::GetFunctionRealm(Handle<JSObject>::cast(receiver)); 5141 return JSObject::GetFunctionRealm(Handle<JSObject>::cast(receiver));
5143 } 5142 }
5144 5143
5145 5144
5146 Maybe<PropertyAttributes> JSProxy::GetPropertyAttributes(LookupIterator* it) { 5145 Maybe<PropertyAttributes> JSProxy::GetPropertyAttributes(LookupIterator* it) {
5147 Isolate* isolate = it->isolate();
5148 HandleScope scope(isolate);
5149 PropertyDescriptor desc; 5146 PropertyDescriptor desc;
5150 Maybe<bool> found = JSProxy::GetOwnPropertyDescriptor( 5147 Maybe<bool> found = JSProxy::GetOwnPropertyDescriptor(
5151 isolate, it->GetHolder<JSProxy>(), it->GetName(), &desc); 5148 it->isolate(), it->GetHolder<JSProxy>(), it->GetName(), &desc);
5152 MAYBE_RETURN(found, Nothing<PropertyAttributes>()); 5149 MAYBE_RETURN(found, Nothing<PropertyAttributes>());
5153 if (!found.FromJust()) return Just(ABSENT); 5150 if (!found.FromJust()) return Just(ABSENT);
5154 return Just(desc.ToAttributes()); 5151 return Just(desc.ToAttributes());
5155 } 5152 }
5156 5153
5157 5154
5158 void JSObject::AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map) { 5155 void JSObject::AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map) {
5159 DCHECK(object->map()->GetInObjectProperties() == 5156 DCHECK(object->map()->GetInObjectProperties() ==
5160 map->GetInObjectProperties()); 5157 map->GetInObjectProperties());
5161 ElementsKind obj_kind = object->map()->elements_kind(); 5158 ElementsKind obj_kind = object->map()->elements_kind();
(...skipping 3346 matching lines...) Expand 10 before | Expand all | Expand 10 after
8508 8505
8509 8506
8510 // Helper function for JSReceiver::GetKeys() below. Can be called recursively. 8507 // Helper function for JSReceiver::GetKeys() below. Can be called recursively.
8511 // Returns |true| or |nothing|. 8508 // Returns |true| or |nothing|.
8512 static Maybe<bool> GetKeys_Internal(Isolate* isolate, 8509 static Maybe<bool> GetKeys_Internal(Isolate* isolate,
8513 Handle<JSReceiver> receiver, 8510 Handle<JSReceiver> receiver,
8514 Handle<JSReceiver> object, 8511 Handle<JSReceiver> object,
8515 KeyCollectionType type, 8512 KeyCollectionType type,
8516 PropertyFilter filter, 8513 PropertyFilter filter,
8517 KeyAccumulator* accumulator) { 8514 KeyAccumulator* accumulator) {
8515 // Proxies have no hidden prototype and we should not trigger the
8516 // [[GetPrototypeOf]] trap on the last iteration when using
8517 // AdvanceFollowingProxies.
8518 if (type == OWN_ONLY && object->IsJSProxy()) {
8519 MAYBE_RETURN(JSProxy::OwnPropertyKeys(isolate, receiver,
8520 Handle<JSProxy>::cast(object), filter,
8521 accumulator),
8522 Nothing<bool>());
8523 return Just(true);
8524 }
8525
8518 PrototypeIterator::WhereToEnd end = type == OWN_ONLY 8526 PrototypeIterator::WhereToEnd end = type == OWN_ONLY
8519 ? PrototypeIterator::END_AT_NON_HIDDEN 8527 ? PrototypeIterator::END_AT_NON_HIDDEN
8520 : PrototypeIterator::END_AT_NULL; 8528 : PrototypeIterator::END_AT_NULL;
8521 for (PrototypeIterator iter(isolate, object, 8529 for (PrototypeIterator iter(isolate, object,
8522 PrototypeIterator::START_AT_RECEIVER, end); 8530 PrototypeIterator::START_AT_RECEIVER, end);
8523 !iter.IsAtEnd(); iter.Advance()) { 8531 !iter.IsAtEnd();) {
8524 Handle<JSReceiver> current = 8532 Handle<JSReceiver> current =
8525 PrototypeIterator::GetCurrent<JSReceiver>(iter); 8533 PrototypeIterator::GetCurrent<JSReceiver>(iter);
8526 Maybe<bool> result = Just(false); // Dummy initialization. 8534 Maybe<bool> result = Just(false); // Dummy initialization.
8527 if (current->IsJSProxy()) { 8535 if (current->IsJSProxy()) {
8528 result = JSProxy::OwnPropertyKeys(isolate, receiver, 8536 result = JSProxy::OwnPropertyKeys(isolate, receiver,
8529 Handle<JSProxy>::cast(current), filter, 8537 Handle<JSProxy>::cast(current), filter,
8530 accumulator); 8538 accumulator);
8531 } else { 8539 } else {
8532 DCHECK(current->IsJSObject()); 8540 DCHECK(current->IsJSObject());
8533 result = GetKeysFromJSObject(isolate, receiver, 8541 result = GetKeysFromJSObject(isolate, receiver,
8534 Handle<JSObject>::cast(current), &filter, 8542 Handle<JSObject>::cast(current), &filter,
8535 type, accumulator); 8543 type, accumulator);
8536 } 8544 }
8537 MAYBE_RETURN(result, Nothing<bool>()); 8545 MAYBE_RETURN(result, Nothing<bool>());
8538 if (!result.FromJust()) break; // |false| means "stop iterating". 8546 if (!result.FromJust()) break; // |false| means "stop iterating".
8547 // Iterate through proxies but ignore access checks for the ALL_CAN_READ
8548 // case on API objects for OWN_ONLY keys handlede in GgetKeysFromJSObject.
8549 if (!iter.AdvanceFollowingProxiesIgnoringAccessChecks()) {
8550 return Nothing<bool>();
8551 }
8539 } 8552 }
8540 return Just(true); 8553 return Just(true);
8541 } 8554 }
8542 8555
8543 8556
8544 // ES6 9.5.12 8557 // ES6 9.5.12
8545 // Returns |true| on success, |nothing| in case of exception. 8558 // Returns |true| on success, |nothing| in case of exception.
8546 // static 8559 // static
8547 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate, 8560 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate,
8548 Handle<JSReceiver> receiver, 8561 Handle<JSReceiver> receiver,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
8687 if (unchecked_result_keys_size != 0) { 8700 if (unchecked_result_keys_size != 0) {
8688 DCHECK_GT(unchecked_result_keys_size, 0); 8701 DCHECK_GT(unchecked_result_keys_size, 0);
8689 isolate->Throw(*isolate->factory()->NewTypeError( 8702 isolate->Throw(*isolate->factory()->NewTypeError(
8690 MessageTemplate::kProxyOwnKeysNonExtensible)); 8703 MessageTemplate::kProxyOwnKeysNonExtensible));
8691 return Nothing<bool>(); 8704 return Nothing<bool>();
8692 } 8705 }
8693 // 21. Return trapResult. 8706 // 21. Return trapResult.
8694 return accumulator->AddKeysFromProxy(proxy, trap_result); 8707 return accumulator->AddKeysFromProxy(proxy, trap_result);
8695 } 8708 }
8696 8709
8697
8698 MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object, 8710 MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
8699 KeyCollectionType type, 8711 KeyCollectionType type,
8700 PropertyFilter filter, 8712 PropertyFilter filter,
8701 GetKeysConversion keys_conversion) { 8713 GetKeysConversion keys_conversion,
8714 bool filter_proxy_keys) {
8702 USE(ContainsOnlyValidKeys); 8715 USE(ContainsOnlyValidKeys);
8703 Isolate* isolate = object->GetIsolate(); 8716 Isolate* isolate = object->GetIsolate();
8704 KeyAccumulator accumulator(isolate, type, filter); 8717 KeyAccumulator accumulator(isolate, type, filter);
8718 accumulator.set_filter_proxy_keys(filter_proxy_keys);
8705 MAYBE_RETURN( 8719 MAYBE_RETURN(
8706 GetKeys_Internal(isolate, object, object, type, filter, &accumulator), 8720 GetKeys_Internal(isolate, object, object, type, filter, &accumulator),
8707 MaybeHandle<FixedArray>()); 8721 MaybeHandle<FixedArray>());
8708 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion); 8722 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion);
8709 DCHECK(ContainsOnlyValidKeys(keys)); 8723 DCHECK(ContainsOnlyValidKeys(keys));
8710 return keys; 8724 return keys;
8711 } 8725 }
8712 8726
8713 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( 8727 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries(
8714 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries, 8728 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries,
(...skipping 11031 matching lines...) Expand 10 before | Expand all | Expand 10 after
19746 if (cell->value() != *new_value) { 19760 if (cell->value() != *new_value) {
19747 cell->set_value(*new_value); 19761 cell->set_value(*new_value);
19748 Isolate* isolate = cell->GetIsolate(); 19762 Isolate* isolate = cell->GetIsolate();
19749 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19763 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19750 isolate, DependentCode::kPropertyCellChangedGroup); 19764 isolate, DependentCode::kPropertyCellChangedGroup);
19751 } 19765 }
19752 } 19766 }
19753 19767
19754 } // namespace internal 19768 } // namespace internal
19755 } // namespace v8 19769 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698