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

Side by Side Diff: src/objects.cc

Issue 536943002: Never skip access checks when looking up properties (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/lookup-inl.h ('k') | src/runtime.cc » ('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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 break; 138 break;
139 } 139 }
140 } 140 }
141 return it->factory()->undefined_value(); 141 return it->factory()->undefined_value();
142 } 142 }
143 143
144 144
145 Handle<Object> JSObject::GetDataProperty(Handle<JSObject> object, 145 Handle<Object> JSObject::GetDataProperty(Handle<JSObject> object,
146 Handle<Name> key) { 146 Handle<Name> key) {
147 LookupIterator it(object, key, LookupIterator::PROTOTYPE_CHAIN_PROPERTY); 147 LookupIterator it(object, key,
148 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
148 return GetDataProperty(&it); 149 return GetDataProperty(&it);
149 } 150 }
150 151
151 152
152 Handle<Object> JSObject::GetDataProperty(LookupIterator* it) { 153 Handle<Object> JSObject::GetDataProperty(LookupIterator* it) {
153 for (; it->IsFound(); it->Next()) { 154 for (; it->IsFound(); it->Next()) {
154 switch (it->state()) { 155 switch (it->state()) {
155 case LookupIterator::ACCESS_CHECK:
156 case LookupIterator::INTERCEPTOR: 156 case LookupIterator::INTERCEPTOR:
157 case LookupIterator::NOT_FOUND: 157 case LookupIterator::NOT_FOUND:
158 case LookupIterator::TRANSITION: 158 case LookupIterator::TRANSITION:
159 UNREACHABLE(); 159 UNREACHABLE();
160 case LookupIterator::ACCESS_CHECK:
161 if (it->HasAccess(v8::ACCESS_GET)) continue;
162 // Fall through.
160 case LookupIterator::JSPROXY: 163 case LookupIterator::JSPROXY:
161 it->NotFound(); 164 it->NotFound();
162 return it->isolate()->factory()->undefined_value(); 165 return it->isolate()->factory()->undefined_value();
163 case LookupIterator::PROPERTY: 166 case LookupIterator::PROPERTY:
164 if (!it->HasProperty()) continue; 167 if (!it->HasProperty()) continue;
165 switch (it->property_kind()) { 168 switch (it->property_kind()) {
166 case LookupIterator::DATA: 169 case LookupIterator::DATA:
167 return it->GetDataValue(); 170 return it->GetDataValue();
168 case LookupIterator::ACCESSOR: 171 case LookupIterator::ACCESSOR:
169 // TODO(verwaest): For now this doesn't call into 172 // TODO(verwaest): For now this doesn't call into
(...skipping 3610 matching lines...) Expand 10 before | Expand all | Expand 10 after
3780 box->set_value(value->Number()); 3783 box->set_value(value->Number());
3781 } else { 3784 } else {
3782 FastPropertyAtPut(index, value); 3785 FastPropertyAtPut(index, value);
3783 } 3786 }
3784 } 3787 }
3785 3788
3786 3789
3787 void JSObject::AddProperty(Handle<JSObject> object, Handle<Name> name, 3790 void JSObject::AddProperty(Handle<JSObject> object, Handle<Name> name,
3788 Handle<Object> value, 3791 Handle<Object> value,
3789 PropertyAttributes attributes) { 3792 PropertyAttributes attributes) {
3790 LookupIterator it(object, name, LookupIterator::OWN_PROPERTY); 3793 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR);
3794 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
3791 #ifdef DEBUG 3795 #ifdef DEBUG
3792 uint32_t index; 3796 uint32_t index;
3793 DCHECK(!object->IsJSProxy()); 3797 DCHECK(!object->IsJSProxy());
3794 DCHECK(!name->AsArrayIndex(&index)); 3798 DCHECK(!name->AsArrayIndex(&index));
3795 Maybe<PropertyAttributes> maybe = GetPropertyAttributes(&it); 3799 Maybe<PropertyAttributes> maybe = GetPropertyAttributes(&it);
3796 DCHECK(maybe.has_value); 3800 DCHECK(maybe.has_value);
3797 DCHECK(!it.IsFound()); 3801 DCHECK(!it.IsFound());
3798 DCHECK(object->map()->is_extensible() || 3802 DCHECK(object->map()->is_extensible() ||
3799 name.is_identical_to(it.isolate()->factory()->hidden_string())); 3803 name.is_identical_to(it.isolate()->factory()->hidden_string()));
3800 #endif 3804 #endif
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
4680 if (inline_value->IsUndefined() || inline_value->IsSmi()) return; 4684 if (inline_value->IsUndefined() || inline_value->IsSmi()) return;
4681 4685
4682 Handle<ObjectHashTable> hashtable(ObjectHashTable::cast(inline_value)); 4686 Handle<ObjectHashTable> hashtable(ObjectHashTable::cast(inline_value));
4683 bool was_present = false; 4687 bool was_present = false;
4684 ObjectHashTable::Remove(hashtable, key, &was_present); 4688 ObjectHashTable::Remove(hashtable, key, &was_present);
4685 } 4689 }
4686 4690
4687 4691
4688 bool JSObject::HasHiddenProperties(Handle<JSObject> object) { 4692 bool JSObject::HasHiddenProperties(Handle<JSObject> object) {
4689 Handle<Name> hidden = object->GetIsolate()->factory()->hidden_string(); 4693 Handle<Name> hidden = object->GetIsolate()->factory()->hidden_string();
4690 LookupIterator it(object, hidden, LookupIterator::OWN_PROPERTY); 4694 LookupIterator it(object, hidden, LookupIterator::OWN_SKIP_INTERCEPTOR);
4691 Maybe<PropertyAttributes> maybe = GetPropertyAttributes(&it); 4695 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
4692 // Cannot get an exception since the hidden_string isn't accessible to JS. 4696 return it.IsFound() && it.HasProperty();
4693 DCHECK(maybe.has_value);
4694 return maybe.value != ABSENT;
4695 } 4697 }
4696 4698
4697 4699
4698 Object* JSObject::GetHiddenPropertiesHashTable() { 4700 Object* JSObject::GetHiddenPropertiesHashTable() {
4699 DCHECK(!IsJSGlobalProxy()); 4701 DCHECK(!IsJSGlobalProxy());
4700 if (HasFastProperties()) { 4702 if (HasFastProperties()) {
4701 // If the object has fast properties, check whether the first slot 4703 // If the object has fast properties, check whether the first slot
4702 // in the descriptor array matches the hidden string. Since the 4704 // in the descriptor array matches the hidden string. Since the
4703 // hidden strings hash code is zero (and no other name has hash 4705 // hidden strings hash code is zero (and no other name has hash
4704 // code zero) it will always occupy the first entry if present. 4706 // code zero) it will always occupy the first entry if present.
(...skipping 10 matching lines...) Expand all
4715 return this->RawFastPropertyAt(index); 4717 return this->RawFastPropertyAt(index);
4716 } else { 4718 } else {
4717 return GetHeap()->undefined_value(); 4719 return GetHeap()->undefined_value();
4718 } 4720 }
4719 } else { 4721 } else {
4720 return GetHeap()->undefined_value(); 4722 return GetHeap()->undefined_value();
4721 } 4723 }
4722 } else { 4724 } else {
4723 Isolate* isolate = GetIsolate(); 4725 Isolate* isolate = GetIsolate();
4724 LookupIterator it(handle(this), isolate->factory()->hidden_string(), 4726 LookupIterator it(handle(this), isolate->factory()->hidden_string(),
4725 LookupIterator::OWN_PROPERTY); 4727 LookupIterator::OWN_SKIP_INTERCEPTOR);
4728 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
4726 if (it.IsFound() && it.HasProperty()) { 4729 if (it.IsFound() && it.HasProperty()) {
4727 DCHECK_EQ(LookupIterator::DATA, it.property_kind()); 4730 DCHECK_EQ(LookupIterator::DATA, it.property_kind());
4728 return *it.GetDataValue(); 4731 return *it.GetDataValue();
4729 } 4732 }
4730 return GetHeap()->undefined_value(); 4733 return GetHeap()->undefined_value();
4731 } 4734 }
4732 } 4735 }
4733 4736
4734 Handle<ObjectHashTable> JSObject::GetOrCreateHiddenPropertiesHashtable( 4737 Handle<ObjectHashTable> JSObject::GetOrCreateHiddenPropertiesHashtable(
4735 Handle<JSObject> object) { 4738 Handle<JSObject> object) {
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after
6156 6159
6157 if (is_element) { 6160 if (is_element) {
6158 DefineElementAccessor(object, index, getter, setter, attributes); 6161 DefineElementAccessor(object, index, getter, setter, attributes);
6159 } else { 6162 } else {
6160 DCHECK(getter->IsSpecFunction() || getter->IsUndefined() || 6163 DCHECK(getter->IsSpecFunction() || getter->IsUndefined() ||
6161 getter->IsNull()); 6164 getter->IsNull());
6162 DCHECK(setter->IsSpecFunction() || setter->IsUndefined() || 6165 DCHECK(setter->IsSpecFunction() || setter->IsUndefined() ||
6163 setter->IsNull()); 6166 setter->IsNull());
6164 // At least one of the accessors needs to be a new value. 6167 // At least one of the accessors needs to be a new value.
6165 DCHECK(!getter->IsNull() || !setter->IsNull()); 6168 DCHECK(!getter->IsNull() || !setter->IsNull());
6166 LookupIterator it(object, name, LookupIterator::OWN_PROPERTY); 6169 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR);
6170 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
6167 if (!getter->IsNull()) { 6171 if (!getter->IsNull()) {
6168 it.TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes); 6172 it.TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes);
6169 } 6173 }
6170 if (!setter->IsNull()) { 6174 if (!setter->IsNull()) {
6171 it.TransitionToAccessorProperty(ACCESSOR_SETTER, setter, attributes); 6175 it.TransitionToAccessorProperty(ACCESSOR_SETTER, setter, attributes);
6172 } 6176 }
6173 } 6177 }
6174 6178
6175 if (is_observed) { 6179 if (is_observed) {
6176 const char* type = preexists ? "reconfigure" : "add"; 6180 const char* type = preexists ? "reconfigure" : "add";
(...skipping 6659 matching lines...) Expand 10 before | Expand all | Expand 10 after
12836 return lookup.IsReadOnly(); 12840 return lookup.IsReadOnly();
12837 } 12841 }
12838 12842
12839 12843
12840 bool JSArray::WouldChangeReadOnlyLength(Handle<JSArray> array, 12844 bool JSArray::WouldChangeReadOnlyLength(Handle<JSArray> array,
12841 uint32_t index) { 12845 uint32_t index) {
12842 uint32_t length = 0; 12846 uint32_t length = 0;
12843 CHECK(array->length()->ToArrayIndex(&length)); 12847 CHECK(array->length()->ToArrayIndex(&length));
12844 if (length <= index) { 12848 if (length <= index) {
12845 LookupIterator it(array, array->GetIsolate()->factory()->length_string(), 12849 LookupIterator it(array, array->GetIsolate()->factory()->length_string(),
12846 LookupIterator::OWN_PROPERTY); 12850 LookupIterator::OWN_SKIP_INTERCEPTOR);
12851 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state());
12847 CHECK(it.IsFound()); 12852 CHECK(it.IsFound());
12848 CHECK(it.HasProperty()); 12853 CHECK(it.HasProperty());
12849 return it.IsReadOnly(); 12854 return it.IsReadOnly();
12850 } 12855 }
12851 return false; 12856 return false;
12852 } 12857 }
12853 12858
12854 12859
12855 MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) { 12860 MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) {
12856 Isolate* isolate = array->GetIsolate(); 12861 Isolate* isolate = array->GetIsolate();
(...skipping 3561 matching lines...) Expand 10 before | Expand all | Expand 10 after
16418 #define ERROR_MESSAGES_TEXTS(C, T) T, 16423 #define ERROR_MESSAGES_TEXTS(C, T) T,
16419 static const char* error_messages_[] = { 16424 static const char* error_messages_[] = {
16420 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16425 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16421 }; 16426 };
16422 #undef ERROR_MESSAGES_TEXTS 16427 #undef ERROR_MESSAGES_TEXTS
16423 return error_messages_[reason]; 16428 return error_messages_[reason];
16424 } 16429 }
16425 16430
16426 16431
16427 } } // namespace v8::internal 16432 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/lookup-inl.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698