OLD | NEW |
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/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 6035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6046 ShouldThrow should_throw) { | 6046 ShouldThrow should_throw) { |
6047 Isolate* isolate = it->isolate(); | 6047 Isolate* isolate = it->isolate(); |
6048 // == OrdinaryDefineOwnProperty (O, P, Desc) == | 6048 // == OrdinaryDefineOwnProperty (O, P, Desc) == |
6049 // 1. Let current be O.[[GetOwnProperty]](P). | 6049 // 1. Let current be O.[[GetOwnProperty]](P). |
6050 // 2. ReturnIfAbrupt(current). | 6050 // 2. ReturnIfAbrupt(current). |
6051 PropertyDescriptor current; | 6051 PropertyDescriptor current; |
6052 if (!GetOwnPropertyDescriptor(it, ¤t) && | 6052 if (!GetOwnPropertyDescriptor(it, ¤t) && |
6053 isolate->has_pending_exception()) { | 6053 isolate->has_pending_exception()) { |
6054 return false; | 6054 return false; |
6055 } | 6055 } |
| 6056 // TODO(jkummerow/verwaest): It would be nice if we didn't have to reset |
| 6057 // the iterator every time. Currently, the reasons why we need it are: |
| 6058 // - handle interceptors correctly |
| 6059 // - handle accessors correctly (which might change the holder's map) |
| 6060 it->Restart(); |
6056 // 3. Let extensible be the value of the [[Extensible]] internal slot of O. | 6061 // 3. Let extensible be the value of the [[Extensible]] internal slot of O. |
6057 Handle<JSObject> object = Handle<JSObject>::cast(it->GetReceiver()); | 6062 Handle<JSObject> object = Handle<JSObject>::cast(it->GetReceiver()); |
6058 bool extensible = JSObject::IsExtensible(object); | 6063 bool extensible = JSObject::IsExtensible(object); |
6059 | 6064 |
6060 bool desc_is_data_descriptor = PropertyDescriptor::IsDataDescriptor(desc); | 6065 bool desc_is_data_descriptor = PropertyDescriptor::IsDataDescriptor(desc); |
6061 bool desc_is_accessor_descriptor = | 6066 bool desc_is_accessor_descriptor = |
6062 PropertyDescriptor::IsAccessorDescriptor(desc); | 6067 PropertyDescriptor::IsAccessorDescriptor(desc); |
6063 bool desc_is_generic_descriptor = | 6068 bool desc_is_generic_descriptor = |
6064 PropertyDescriptor::IsGenericDescriptor(desc); | 6069 PropertyDescriptor::IsGenericDescriptor(desc); |
6065 | 6070 |
6066 // == ValidateAndApplyPropertyDescriptor (O, P, extensible, Desc, current) == | 6071 // == ValidateAndApplyPropertyDescriptor (O, P, extensible, Desc, current) == |
6067 // 2. If current is undefined, then | 6072 // 2. If current is undefined, then |
6068 if (current.is_empty()) { | 6073 if (current.is_empty()) { |
6069 // 2a. If extensible is false, return false. | 6074 // 2a. If extensible is false, return false. |
6070 if (!extensible) { | 6075 if (!extensible) { |
6071 if (should_throw == THROW_ON_ERROR) { | 6076 if (should_throw == THROW_ON_ERROR) { |
6072 isolate->Throw(*isolate->factory()->NewTypeError( | 6077 isolate->Throw(*isolate->factory()->NewTypeError( |
6073 MessageTemplate::kDefineDisallowed, it->GetName())); | 6078 MessageTemplate::kDefineDisallowed, it->GetName())); |
6074 } | 6079 } |
6075 return false; | 6080 return false; |
6076 } | 6081 } |
6077 // We have to reset the LookupIterator to handle interceptors properly. | |
6078 Map* map = Handle<HeapObject>::cast(object)->map(); | |
6079 if ((it->IsElement() && map->has_indexed_interceptor()) || | |
6080 (!it->IsElement() && map->has_named_interceptor())) { | |
6081 it->Restart(); | |
6082 } | |
6083 | |
6084 // 2c. If IsGenericDescriptor(Desc) or IsDataDescriptor(Desc) is true, then: | 6082 // 2c. If IsGenericDescriptor(Desc) or IsDataDescriptor(Desc) is true, then: |
6085 // (This is equivalent to !IsAccessorDescriptor(desc).) | 6083 // (This is equivalent to !IsAccessorDescriptor(desc).) |
6086 DCHECK((desc_is_generic_descriptor || desc_is_data_descriptor) == | 6084 DCHECK((desc_is_generic_descriptor || desc_is_data_descriptor) == |
6087 !desc_is_accessor_descriptor); | 6085 !desc_is_accessor_descriptor); |
6088 if (!desc_is_accessor_descriptor) { | 6086 if (!desc_is_accessor_descriptor) { |
6089 // 2c i. If O is not undefined, create an own data property named P of | 6087 // 2c i. If O is not undefined, create an own data property named P of |
6090 // object O whose [[Value]], [[Writable]], [[Enumerable]] and | 6088 // object O whose [[Value]], [[Writable]], [[Enumerable]] and |
6091 // [[Configurable]] attribute values are described by Desc. If the value | 6089 // [[Configurable]] attribute values are described by Desc. If the value |
6092 // of an attribute field of Desc is absent, the attribute of the newly | 6090 // of an attribute field of Desc is absent, the attribute of the newly |
6093 // created property is set to its default value. | 6091 // created property is set to its default value. |
(...skipping 11738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17832 if (cell->value() != *new_value) { | 17830 if (cell->value() != *new_value) { |
17833 cell->set_value(*new_value); | 17831 cell->set_value(*new_value); |
17834 Isolate* isolate = cell->GetIsolate(); | 17832 Isolate* isolate = cell->GetIsolate(); |
17835 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17833 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
17836 isolate, DependentCode::kPropertyCellChangedGroup); | 17834 isolate, DependentCode::kPropertyCellChangedGroup); |
17837 } | 17835 } |
17838 } | 17836 } |
17839 | 17837 |
17840 } // namespace internal | 17838 } // namespace internal |
17841 } // namespace v8 | 17839 } // namespace v8 |
OLD | NEW |