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

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: do not create a HandleScope when passing LookuptIterator* 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
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 3337 matching lines...) Expand 10 before | Expand all | Expand 10 after
8499 8496
8500 8497
8501 // Helper function for JSReceiver::GetKeys() below. Can be called recursively. 8498 // Helper function for JSReceiver::GetKeys() below. Can be called recursively.
8502 // Returns |true| or |nothing|. 8499 // Returns |true| or |nothing|.
8503 static Maybe<bool> GetKeys_Internal(Isolate* isolate, 8500 static Maybe<bool> GetKeys_Internal(Isolate* isolate,
8504 Handle<JSReceiver> receiver, 8501 Handle<JSReceiver> receiver,
8505 Handle<JSReceiver> object, 8502 Handle<JSReceiver> object,
8506 KeyCollectionType type, 8503 KeyCollectionType type,
8507 PropertyFilter filter, 8504 PropertyFilter filter,
8508 KeyAccumulator* accumulator) { 8505 KeyAccumulator* accumulator) {
8506 // Proxies have no hidden prototype and we should not trigger the
8507 // [[GetPrototypeOf]] trap on the last iteration when using
8508 // AdvanceFollowingProxies.
8509 if (type == OWN_ONLY && object->IsJSProxy()) {
8510 MAYBE_RETURN(JSProxy::OwnPropertyKeys(isolate, receiver,
8511 Handle<JSProxy>::cast(object), filter,
8512 accumulator),
8513 Nothing<bool>());
8514 return Just(true);
8515 }
8516
8509 PrototypeIterator::WhereToEnd end = type == OWN_ONLY 8517 PrototypeIterator::WhereToEnd end = type == OWN_ONLY
8510 ? PrototypeIterator::END_AT_NON_HIDDEN 8518 ? PrototypeIterator::END_AT_NON_HIDDEN
8511 : PrototypeIterator::END_AT_NULL; 8519 : PrototypeIterator::END_AT_NULL;
8512 for (PrototypeIterator iter(isolate, object, 8520 for (PrototypeIterator iter(isolate, object,
8513 PrototypeIterator::START_AT_RECEIVER, end); 8521 PrototypeIterator::START_AT_RECEIVER, end);
8514 !iter.IsAtEnd(); iter.Advance()) { 8522 !iter.IsAtEnd();) {
8515 Handle<JSReceiver> current = 8523 Handle<JSReceiver> current =
8516 PrototypeIterator::GetCurrent<JSReceiver>(iter); 8524 PrototypeIterator::GetCurrent<JSReceiver>(iter);
8517 Maybe<bool> result = Just(false); // Dummy initialization. 8525 Maybe<bool> result = Just(false); // Dummy initialization.
8518 if (current->IsJSProxy()) { 8526 if (current->IsJSProxy()) {
8519 result = JSProxy::OwnPropertyKeys(isolate, receiver, 8527 result = JSProxy::OwnPropertyKeys(isolate, receiver,
8520 Handle<JSProxy>::cast(current), filter, 8528 Handle<JSProxy>::cast(current), filter,
8521 accumulator); 8529 accumulator);
8522 } else { 8530 } else {
8523 DCHECK(current->IsJSObject()); 8531 DCHECK(current->IsJSObject());
8524 result = GetKeysFromJSObject(isolate, receiver, 8532 result = GetKeysFromJSObject(isolate, receiver,
8525 Handle<JSObject>::cast(current), &filter, 8533 Handle<JSObject>::cast(current), &filter,
8526 type, accumulator); 8534 type, accumulator);
8527 } 8535 }
8528 MAYBE_RETURN(result, Nothing<bool>()); 8536 MAYBE_RETURN(result, Nothing<bool>());
8529 if (!result.FromJust()) break; // |false| means "stop iterating". 8537 if (!result.FromJust()) break; // |false| means "stop iterating".
8538 if (!iter.AdvanceFollowingProxiesIgnoringAccessChecks()) {
neis 2016/03/18 14:30:02 Can you explain the "IgnoringAccessChecks" part of
Camillo Bruni 2016/03/18 17:46:34 Will add a comment: Since we now have to walk up
8539 return Nothing<bool>();
8540 }
8530 } 8541 }
8531 return Just(true); 8542 return Just(true);
8532 } 8543 }
8533 8544
8534 8545
8535 // ES6 9.5.12 8546 // ES6 9.5.12
8536 // Returns |true| on success, |nothing| in case of exception. 8547 // Returns |true| on success, |nothing| in case of exception.
8537 // static 8548 // static
8538 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate, 8549 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate,
8539 Handle<JSReceiver> receiver, 8550 Handle<JSReceiver> receiver,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
8678 if (unchecked_result_keys_size != 0) { 8689 if (unchecked_result_keys_size != 0) {
8679 DCHECK_GT(unchecked_result_keys_size, 0); 8690 DCHECK_GT(unchecked_result_keys_size, 0);
8680 isolate->Throw(*isolate->factory()->NewTypeError( 8691 isolate->Throw(*isolate->factory()->NewTypeError(
8681 MessageTemplate::kProxyOwnKeysNonExtensible)); 8692 MessageTemplate::kProxyOwnKeysNonExtensible));
8682 return Nothing<bool>(); 8693 return Nothing<bool>();
8683 } 8694 }
8684 // 21. Return trapResult. 8695 // 21. Return trapResult.
8685 return accumulator->AddKeysFromProxy(proxy, trap_result); 8696 return accumulator->AddKeysFromProxy(proxy, trap_result);
8686 } 8697 }
8687 8698
8688
8689 MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object, 8699 MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
8690 KeyCollectionType type, 8700 KeyCollectionType type,
8691 PropertyFilter filter, 8701 PropertyFilter filter,
8692 GetKeysConversion keys_conversion) { 8702 GetKeysConversion keys_conversion,
8703 bool filter_proxy_keys) {
8693 USE(ContainsOnlyValidKeys); 8704 USE(ContainsOnlyValidKeys);
8694 Isolate* isolate = object->GetIsolate(); 8705 Isolate* isolate = object->GetIsolate();
8695 KeyAccumulator accumulator(isolate, type, filter); 8706 KeyAccumulator accumulator(isolate, type, filter);
8707 accumulator.set_filter_proxy_keys(filter_proxy_keys);
8696 MAYBE_RETURN( 8708 MAYBE_RETURN(
8697 GetKeys_Internal(isolate, object, object, type, filter, &accumulator), 8709 GetKeys_Internal(isolate, object, object, type, filter, &accumulator),
8698 MaybeHandle<FixedArray>()); 8710 MaybeHandle<FixedArray>());
8699 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion); 8711 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion);
8700 DCHECK(ContainsOnlyValidKeys(keys)); 8712 DCHECK(ContainsOnlyValidKeys(keys));
8701 return keys; 8713 return keys;
8702 } 8714 }
8703 8715
8704 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( 8716 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries(
8705 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries, 8717 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries,
(...skipping 11028 matching lines...) Expand 10 before | Expand all | Expand 10 after
19734 if (cell->value() != *new_value) { 19746 if (cell->value() != *new_value) {
19735 cell->set_value(*new_value); 19747 cell->set_value(*new_value);
19736 Isolate* isolate = cell->GetIsolate(); 19748 Isolate* isolate = cell->GetIsolate();
19737 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19749 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19738 isolate, DependentCode::kPropertyCellChangedGroup); 19750 isolate, DependentCode::kPropertyCellChangedGroup);
19739 } 19751 }
19740 } 19752 }
19741 19753
19742 } // namespace internal 19754 } // namespace internal
19743 } // namespace v8 19755 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698