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 4121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4132 StoreFromKeyed store_mode, | 4132 StoreFromKeyed store_mode, |
4133 bool* found) { | 4133 bool* found) { |
4134 it->UpdateProtector(); | 4134 it->UpdateProtector(); |
4135 ShouldThrow should_throw = | 4135 ShouldThrow should_throw = |
4136 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 4136 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
4137 | 4137 |
4138 // Make sure that the top context does not change when doing callbacks or | 4138 // Make sure that the top context does not change when doing callbacks or |
4139 // interceptor calls. | 4139 // interceptor calls. |
4140 AssertNoContextChange ncc(it->isolate()); | 4140 AssertNoContextChange ncc(it->isolate()); |
4141 | 4141 |
4142 *found = true; | |
4143 | |
4144 bool done = false; | |
4145 for (; it->IsFound(); it->Next()) { | 4142 for (; it->IsFound(); it->Next()) { |
4146 switch (it->state()) { | 4143 switch (it->state()) { |
4147 case LookupIterator::NOT_FOUND: | 4144 case LookupIterator::NOT_FOUND: |
4148 UNREACHABLE(); | 4145 UNREACHABLE(); |
4149 | 4146 |
4150 case LookupIterator::ACCESS_CHECK: | 4147 case LookupIterator::ACCESS_CHECK: |
4151 if (it->HasAccess()) break; | 4148 if (it->HasAccess()) break; |
4152 // Check whether it makes sense to reuse the lookup iterator. Here it | 4149 // Check whether it makes sense to reuse the lookup iterator. Here it |
4153 // might still call into setters up the prototype chain. | 4150 // might still call into setters up the prototype chain. |
4154 return JSObject::SetPropertyWithFailedAccessCheck(it, value, | 4151 return JSObject::SetPropertyWithFailedAccessCheck(it, value, |
4155 should_throw); | 4152 should_throw); |
4156 | 4153 |
4157 case LookupIterator::JSPROXY: | 4154 case LookupIterator::JSPROXY: |
4158 return JSProxy::SetProperty(it->GetHolder<JSProxy>(), it->GetName(), | 4155 return JSProxy::SetProperty(it->GetHolder<JSProxy>(), it->GetName(), |
4159 value, it->GetReceiver(), language_mode); | 4156 value, it->GetReceiver(), language_mode); |
4160 | 4157 |
4161 case LookupIterator::INTERCEPTOR: | 4158 case LookupIterator::INTERCEPTOR: |
4162 if (it->HolderIsReceiverOrHiddenPrototype()) { | 4159 if (it->HolderIsReceiverOrHiddenPrototype()) { |
4163 Maybe<bool> result = | 4160 Maybe<bool> result = |
4164 JSObject::SetPropertyWithInterceptor(it, should_throw, value); | 4161 JSObject::SetPropertyWithInterceptor(it, should_throw, value); |
4165 if (result.IsNothing() || result.FromJust()) return result; | 4162 if (result.IsNothing() || result.FromJust()) return result; |
4166 } else { | 4163 } else { |
4167 Maybe<PropertyAttributes> maybe_attributes = | 4164 Maybe<PropertyAttributes> maybe_attributes = |
4168 JSObject::GetPropertyAttributesWithInterceptor(it); | 4165 JSObject::GetPropertyAttributesWithInterceptor(it); |
4169 if (!maybe_attributes.IsJust()) return Nothing<bool>(); | 4166 if (!maybe_attributes.IsJust()) return Nothing<bool>(); |
4170 done = maybe_attributes.FromJust() != ABSENT; | 4167 if (maybe_attributes.FromJust() == ABSENT) break; |
4171 if (done && (maybe_attributes.FromJust() & READ_ONLY) != 0) { | 4168 if ((maybe_attributes.FromJust() & READ_ONLY) != 0) { |
4172 return WriteToReadOnlyProperty(it, value, should_throw); | 4169 return WriteToReadOnlyProperty(it, value, should_throw); |
4173 } | 4170 } |
| 4171 *found = false; |
| 4172 return Nothing<bool>(); |
4174 } | 4173 } |
4175 break; | 4174 break; |
4176 | 4175 |
4177 case LookupIterator::ACCESSOR: { | 4176 case LookupIterator::ACCESSOR: { |
4178 if (it->IsReadOnly()) { | 4177 if (it->IsReadOnly()) { |
4179 return WriteToReadOnlyProperty(it, value, should_throw); | 4178 return WriteToReadOnlyProperty(it, value, should_throw); |
4180 } | 4179 } |
4181 Handle<Object> accessors = it->GetAccessors(); | 4180 Handle<Object> accessors = it->GetAccessors(); |
4182 if (accessors->IsAccessorInfo() && | 4181 if (accessors->IsAccessorInfo() && |
4183 !it->HolderIsReceiverOrHiddenPrototype() && | 4182 !it->HolderIsReceiverOrHiddenPrototype() && |
4184 AccessorInfo::cast(*accessors)->is_special_data_property()) { | 4183 AccessorInfo::cast(*accessors)->is_special_data_property()) { |
4185 done = true; | 4184 *found = false; |
4186 break; | 4185 return Nothing<bool>(); |
4187 } | 4186 } |
4188 return SetPropertyWithAccessor(it, value, should_throw); | 4187 return SetPropertyWithAccessor(it, value, should_throw); |
4189 } | 4188 } |
4190 case LookupIterator::INTEGER_INDEXED_EXOTIC: | 4189 case LookupIterator::INTEGER_INDEXED_EXOTIC: |
4191 // TODO(verwaest): We should throw an exception. | 4190 // TODO(verwaest): We should throw an exception if holder is receiver. |
4192 return Just(true); | 4191 return Just(true); |
4193 | 4192 |
4194 case LookupIterator::DATA: | 4193 case LookupIterator::DATA: |
4195 if (it->IsReadOnly()) { | 4194 if (it->IsReadOnly()) { |
4196 return WriteToReadOnlyProperty(it, value, should_throw); | 4195 return WriteToReadOnlyProperty(it, value, should_throw); |
4197 } | 4196 } |
4198 if (it->HolderIsReceiverOrHiddenPrototype()) { | 4197 if (it->HolderIsReceiverOrHiddenPrototype()) { |
4199 return SetDataProperty(it, value); | 4198 return SetDataProperty(it, value); |
4200 } | 4199 } |
4201 done = true; | 4200 // Fall through. |
4202 break; | |
4203 | |
4204 case LookupIterator::TRANSITION: | 4201 case LookupIterator::TRANSITION: |
4205 done = true; | 4202 *found = false; |
4206 break; | 4203 return Nothing<bool>(); |
4207 } | 4204 } |
4208 | |
4209 if (done) break; | |
4210 } | 4205 } |
4211 | 4206 |
4212 *found = false; | 4207 *found = false; |
4213 return Nothing<bool>(); | 4208 return Nothing<bool>(); |
4214 } | 4209 } |
4215 | 4210 |
4216 | 4211 |
4217 Maybe<bool> Object::SetProperty(LookupIterator* it, Handle<Object> value, | 4212 Maybe<bool> Object::SetProperty(LookupIterator* it, Handle<Object> value, |
4218 LanguageMode language_mode, | 4213 LanguageMode language_mode, |
4219 StoreFromKeyed store_mode) { | 4214 StoreFromKeyed store_mode) { |
4220 bool found = false; | 4215 bool found = true; |
4221 Maybe<bool> result = | 4216 Maybe<bool> result = |
4222 SetPropertyInternal(it, value, language_mode, store_mode, &found); | 4217 SetPropertyInternal(it, value, language_mode, store_mode, &found); |
4223 if (found) return result; | 4218 if (found) return result; |
4224 | 4219 |
4225 // If the receiver is the JSGlobalObject, the store was contextual. In case | 4220 // If the receiver is the JSGlobalObject, the store was contextual. In case |
4226 // the property did not exist yet on the global object itself, we have to | 4221 // the property did not exist yet on the global object itself, we have to |
4227 // throw a reference error in strict mode. In sloppy mode, we continue. | 4222 // throw a reference error in strict mode. In sloppy mode, we continue. |
4228 if (is_strict(language_mode) && it->GetReceiver()->IsJSGlobalObject()) { | 4223 if (is_strict(language_mode) && it->GetReceiver()->IsJSGlobalObject()) { |
4229 it->isolate()->Throw(*it->isolate()->factory()->NewReferenceError( | 4224 it->isolate()->Throw(*it->isolate()->factory()->NewReferenceError( |
4230 MessageTemplate::kNotDefined, it->name())); | 4225 MessageTemplate::kNotDefined, it->name())); |
4231 return Nothing<bool>(); | 4226 return Nothing<bool>(); |
4232 } | 4227 } |
4233 | 4228 |
4234 ShouldThrow should_throw = | 4229 ShouldThrow should_throw = |
4235 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 4230 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
4236 return AddDataProperty(it, value, NONE, should_throw, store_mode); | 4231 return AddDataProperty(it, value, NONE, should_throw, store_mode); |
4237 } | 4232 } |
4238 | 4233 |
4239 | 4234 |
4240 Maybe<bool> Object::SetSuperProperty(LookupIterator* it, Handle<Object> value, | 4235 Maybe<bool> Object::SetSuperProperty(LookupIterator* it, Handle<Object> value, |
4241 LanguageMode language_mode, | 4236 LanguageMode language_mode, |
4242 StoreFromKeyed store_mode) { | 4237 StoreFromKeyed store_mode) { |
4243 Isolate* isolate = it->isolate(); | 4238 Isolate* isolate = it->isolate(); |
4244 | 4239 |
4245 bool found = false; | 4240 bool found = true; |
4246 Maybe<bool> result = | 4241 Maybe<bool> result = |
4247 SetPropertyInternal(it, value, language_mode, store_mode, &found); | 4242 SetPropertyInternal(it, value, language_mode, store_mode, &found); |
4248 if (found) return result; | 4243 if (found) return result; |
4249 | 4244 |
4250 // The property either doesn't exist on the holder or exists there as a data | 4245 // The property either doesn't exist on the holder or exists there as a data |
4251 // property. | 4246 // property. |
4252 | 4247 |
4253 ShouldThrow should_throw = | 4248 ShouldThrow should_throw = |
4254 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 4249 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
4255 | 4250 |
(...skipping 15514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19770 if (cell->value() != *new_value) { | 19765 if (cell->value() != *new_value) { |
19771 cell->set_value(*new_value); | 19766 cell->set_value(*new_value); |
19772 Isolate* isolate = cell->GetIsolate(); | 19767 Isolate* isolate = cell->GetIsolate(); |
19773 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19768 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19774 isolate, DependentCode::kPropertyCellChangedGroup); | 19769 isolate, DependentCode::kPropertyCellChangedGroup); |
19775 } | 19770 } |
19776 } | 19771 } |
19777 | 19772 |
19778 } // namespace internal | 19773 } // namespace internal |
19779 } // namespace v8 | 19774 } // namespace v8 |
OLD | NEW |