| 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 4113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4124 MAYBE_RETURN_NULL(SetProperty(&it, value, language_mode, store_mode)); | 4124 MAYBE_RETURN_NULL(SetProperty(&it, value, language_mode, store_mode)); |
| 4125 return value; | 4125 return value; |
| 4126 } | 4126 } |
| 4127 | 4127 |
| 4128 | 4128 |
| 4129 Maybe<bool> Object::SetPropertyInternal(LookupIterator* it, | 4129 Maybe<bool> Object::SetPropertyInternal(LookupIterator* it, |
| 4130 Handle<Object> value, | 4130 Handle<Object> value, |
| 4131 LanguageMode language_mode, | 4131 LanguageMode language_mode, |
| 4132 StoreFromKeyed store_mode, | 4132 StoreFromKeyed store_mode, |
| 4133 bool* found) { | 4133 bool* found) { |
| 4134 DCHECK(it->IsFound()); | 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 do { | 4142 for (; it->IsFound(); it->Next()) { |
| 4143 switch (it->state()) { | 4143 switch (it->state()) { |
| 4144 case LookupIterator::NOT_FOUND: | 4144 case LookupIterator::NOT_FOUND: |
| 4145 UNREACHABLE(); | 4145 UNREACHABLE(); |
| 4146 | 4146 |
| 4147 case LookupIterator::ACCESS_CHECK: | 4147 case LookupIterator::ACCESS_CHECK: |
| 4148 if (it->HasAccess()) break; | 4148 if (it->HasAccess()) break; |
| 4149 // 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 |
| 4150 // might still call into setters up the prototype chain. | 4150 // might still call into setters up the prototype chain. |
| 4151 return JSObject::SetPropertyWithFailedAccessCheck(it, value, | 4151 return JSObject::SetPropertyWithFailedAccessCheck(it, value, |
| 4152 should_throw); | 4152 should_throw); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4195 return WriteToReadOnlyProperty(it, value, should_throw); | 4195 return WriteToReadOnlyProperty(it, value, should_throw); |
| 4196 } | 4196 } |
| 4197 if (it->HolderIsReceiverOrHiddenPrototype()) { | 4197 if (it->HolderIsReceiverOrHiddenPrototype()) { |
| 4198 return SetDataProperty(it, value); | 4198 return SetDataProperty(it, value); |
| 4199 } | 4199 } |
| 4200 // Fall through. | 4200 // Fall through. |
| 4201 case LookupIterator::TRANSITION: | 4201 case LookupIterator::TRANSITION: |
| 4202 *found = false; | 4202 *found = false; |
| 4203 return Nothing<bool>(); | 4203 return Nothing<bool>(); |
| 4204 } | 4204 } |
| 4205 it->Next(); | 4205 } |
| 4206 } while (it->IsFound()); | |
| 4207 | 4206 |
| 4208 *found = false; | 4207 *found = false; |
| 4209 return Nothing<bool>(); | 4208 return Nothing<bool>(); |
| 4210 } | 4209 } |
| 4211 | 4210 |
| 4212 | 4211 |
| 4213 Maybe<bool> Object::SetProperty(LookupIterator* it, Handle<Object> value, | 4212 Maybe<bool> Object::SetProperty(LookupIterator* it, Handle<Object> value, |
| 4214 LanguageMode language_mode, | 4213 LanguageMode language_mode, |
| 4215 StoreFromKeyed store_mode) { | 4214 StoreFromKeyed store_mode) { |
| 4216 it->UpdateProtector(); | 4215 bool found = true; |
| 4217 if (it->IsFound()) { | 4216 Maybe<bool> result = |
| 4218 bool found = true; | 4217 SetPropertyInternal(it, value, language_mode, store_mode, &found); |
| 4219 Maybe<bool> result = | 4218 if (found) return result; |
| 4220 SetPropertyInternal(it, value, language_mode, store_mode, &found); | |
| 4221 if (found) return result; | |
| 4222 } | |
| 4223 | 4219 |
| 4224 // 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 |
| 4225 // 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 |
| 4226 // 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. |
| 4227 if (is_strict(language_mode) && it->GetReceiver()->IsJSGlobalObject()) { | 4223 if (is_strict(language_mode) && it->GetReceiver()->IsJSGlobalObject()) { |
| 4228 it->isolate()->Throw(*it->isolate()->factory()->NewReferenceError( | 4224 it->isolate()->Throw(*it->isolate()->factory()->NewReferenceError( |
| 4229 MessageTemplate::kNotDefined, it->name())); | 4225 MessageTemplate::kNotDefined, it->name())); |
| 4230 return Nothing<bool>(); | 4226 return Nothing<bool>(); |
| 4231 } | 4227 } |
| 4232 | 4228 |
| 4233 ShouldThrow should_throw = | 4229 ShouldThrow should_throw = |
| 4234 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 4230 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
| 4235 return AddDataProperty(it, value, NONE, should_throw, store_mode); | 4231 return AddDataProperty(it, value, NONE, should_throw, store_mode); |
| 4236 } | 4232 } |
| 4237 | 4233 |
| 4238 | 4234 |
| 4239 Maybe<bool> Object::SetSuperProperty(LookupIterator* it, Handle<Object> value, | 4235 Maybe<bool> Object::SetSuperProperty(LookupIterator* it, Handle<Object> value, |
| 4240 LanguageMode language_mode, | 4236 LanguageMode language_mode, |
| 4241 StoreFromKeyed store_mode) { | 4237 StoreFromKeyed store_mode) { |
| 4242 Isolate* isolate = it->isolate(); | 4238 Isolate* isolate = it->isolate(); |
| 4243 | 4239 |
| 4244 it->UpdateProtector(); | 4240 bool found = true; |
| 4245 if (it->IsFound()) { | 4241 Maybe<bool> result = |
| 4246 bool found = true; | 4242 SetPropertyInternal(it, value, language_mode, store_mode, &found); |
| 4247 Maybe<bool> result = | 4243 if (found) return result; |
| 4248 SetPropertyInternal(it, value, language_mode, store_mode, &found); | |
| 4249 if (found) return result; | |
| 4250 } | |
| 4251 | 4244 |
| 4252 // 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 |
| 4253 // property. | 4246 // property. |
| 4254 | 4247 |
| 4255 ShouldThrow should_throw = | 4248 ShouldThrow should_throw = |
| 4256 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 4249 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
| 4257 | 4250 |
| 4258 if (!it->GetReceiver()->IsJSReceiver()) { | 4251 if (!it->GetReceiver()->IsJSReceiver()) { |
| 4259 return WriteToReadOnlyProperty(it, value, should_throw); | 4252 return WriteToReadOnlyProperty(it, value, should_throw); |
| 4260 } | 4253 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4315 return JSReceiver::DefineOwnProperty(isolate, receiver, it->GetName(), | 4308 return JSReceiver::DefineOwnProperty(isolate, receiver, it->GetName(), |
| 4316 &value_desc, should_throw); | 4309 &value_desc, should_throw); |
| 4317 } | 4310 } |
| 4318 | 4311 |
| 4319 case LookupIterator::NOT_FOUND: | 4312 case LookupIterator::NOT_FOUND: |
| 4320 case LookupIterator::TRANSITION: | 4313 case LookupIterator::TRANSITION: |
| 4321 UNREACHABLE(); | 4314 UNREACHABLE(); |
| 4322 } | 4315 } |
| 4323 } | 4316 } |
| 4324 | 4317 |
| 4325 return AddDataProperty(&own_lookup, value, NONE, should_throw, store_mode); | 4318 return JSObject::AddDataProperty(&own_lookup, value, NONE, should_throw, |
| 4319 store_mode); |
| 4326 } | 4320 } |
| 4327 | 4321 |
| 4328 MaybeHandle<Object> Object::ReadAbsentProperty(LookupIterator* it) { | 4322 MaybeHandle<Object> Object::ReadAbsentProperty(LookupIterator* it) { |
| 4329 return it->isolate()->factory()->undefined_value(); | 4323 return it->isolate()->factory()->undefined_value(); |
| 4330 } | 4324 } |
| 4331 | 4325 |
| 4332 MaybeHandle<Object> Object::ReadAbsentProperty(Isolate* isolate, | 4326 MaybeHandle<Object> Object::ReadAbsentProperty(Isolate* isolate, |
| 4333 Handle<Object> receiver, | 4327 Handle<Object> receiver, |
| 4334 Handle<Object> name) { | 4328 Handle<Object> name) { |
| 4335 return isolate->factory()->undefined_value(); | 4329 return isolate->factory()->undefined_value(); |
| (...skipping 4038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8374 Handle<FixedArray> array, int length) { | 8368 Handle<FixedArray> array, int length) { |
| 8375 DCHECK_LE(length, array->length()); | 8369 DCHECK_LE(length, array->length()); |
| 8376 if (array->length() == length) return array; | 8370 if (array->length() == length) return array; |
| 8377 return array->GetIsolate()->factory()->CopyFixedArrayUpTo(array, length); | 8371 return array->GetIsolate()->factory()->CopyFixedArrayUpTo(array, length); |
| 8378 } | 8372 } |
| 8379 | 8373 |
| 8380 bool Map::OnlyHasSimpleProperties() { | 8374 bool Map::OnlyHasSimpleProperties() { |
| 8381 // Wrapped string elements aren't explicitly stored in the elements backing | 8375 // Wrapped string elements aren't explicitly stored in the elements backing |
| 8382 // store, but are loaded indirectly from the underlying string. | 8376 // store, but are loaded indirectly from the underlying string. |
| 8383 return !IsStringWrapperElementsKind(elements_kind()) && | 8377 return !IsStringWrapperElementsKind(elements_kind()) && |
| 8384 instance_type() > LAST_SPECIAL_RECEIVER_TYPE && | 8378 !is_access_check_needed() && !has_named_interceptor() && |
| 8385 !has_hidden_prototype() && !is_dictionary_map(); | 8379 !has_indexed_interceptor() && !has_hidden_prototype() && |
| 8380 !is_dictionary_map(); |
| 8386 } | 8381 } |
| 8387 | 8382 |
| 8388 namespace { | 8383 namespace { |
| 8389 | 8384 |
| 8390 Handle<FixedArray> GetFastEnumPropertyKeys(Isolate* isolate, | 8385 Handle<FixedArray> GetFastEnumPropertyKeys(Isolate* isolate, |
| 8391 Handle<JSObject> object) { | 8386 Handle<JSObject> object) { |
| 8392 Handle<Map> map(object->map()); | 8387 Handle<Map> map(object->map()); |
| 8393 bool cache_enum_length = map->OnlyHasSimpleProperties(); | 8388 bool cache_enum_length = map->OnlyHasSimpleProperties(); |
| 8394 | 8389 |
| 8395 Handle<DescriptorArray> descs = | 8390 Handle<DescriptorArray> descs = |
| (...skipping 11375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19771 if (cell->value() != *new_value) { | 19766 if (cell->value() != *new_value) { |
| 19772 cell->set_value(*new_value); | 19767 cell->set_value(*new_value); |
| 19773 Isolate* isolate = cell->GetIsolate(); | 19768 Isolate* isolate = cell->GetIsolate(); |
| 19774 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19769 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 19775 isolate, DependentCode::kPropertyCellChangedGroup); | 19770 isolate, DependentCode::kPropertyCellChangedGroup); |
| 19776 } | 19771 } |
| 19777 } | 19772 } |
| 19778 | 19773 |
| 19779 } // namespace internal | 19774 } // namespace internal |
| 19780 } // namespace v8 | 19775 } // namespace v8 |
| OLD | NEW |