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/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 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 PropertyCell::SetValueInferType(cell, value); | 1866 PropertyCell::SetValueInferType(cell, value); |
1867 value = cell; | 1867 value = cell; |
1868 } | 1868 } |
1869 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0); | 1869 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0); |
1870 Handle<NameDictionary> result = | 1870 Handle<NameDictionary> result = |
1871 NameDictionary::Add(dict, name, value, details); | 1871 NameDictionary::Add(dict, name, value, details); |
1872 if (*dict != *result) object->set_properties(*result); | 1872 if (*dict != *result) object->set_properties(*result); |
1873 } | 1873 } |
1874 | 1874 |
1875 | 1875 |
1876 MaybeHandle<Object> JSObject::AddProperty( | 1876 MaybeHandle<Object> JSObject::AddPropertyInternal( |
1877 Handle<JSObject> object, | 1877 Handle<JSObject> object, |
1878 Handle<Name> name, | 1878 Handle<Name> name, |
1879 Handle<Object> value, | 1879 Handle<Object> value, |
1880 PropertyAttributes attributes, | 1880 PropertyAttributes attributes, |
1881 StrictMode strict_mode, | 1881 StrictMode strict_mode, |
1882 JSReceiver::StoreFromKeyed store_mode, | 1882 JSReceiver::StoreFromKeyed store_mode, |
1883 ExtensibilityCheck extensibility_check, | 1883 ExtensibilityCheck extensibility_check, |
1884 ValueType value_type, | 1884 ValueType value_type, |
1885 StoreMode mode, | 1885 StoreMode mode, |
1886 TransitionFlag transition_flag) { | 1886 TransitionFlag transition_flag) { |
(...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3919 Handle<Name> name, | 3919 Handle<Name> name, |
3920 Handle<Object> value, | 3920 Handle<Object> value, |
3921 PropertyAttributes attributes) { | 3921 PropertyAttributes attributes) { |
3922 Handle<Map> transition_map(lookup->GetTransitionTarget()); | 3922 Handle<Map> transition_map(lookup->GetTransitionTarget()); |
3923 int descriptor = transition_map->LastAdded(); | 3923 int descriptor = transition_map->LastAdded(); |
3924 | 3924 |
3925 Handle<DescriptorArray> descriptors(transition_map->instance_descriptors()); | 3925 Handle<DescriptorArray> descriptors(transition_map->instance_descriptors()); |
3926 PropertyDetails details = descriptors->GetDetails(descriptor); | 3926 PropertyDetails details = descriptors->GetDetails(descriptor); |
3927 | 3927 |
3928 if (details.type() == CALLBACKS || attributes != details.attributes()) { | 3928 if (details.type() == CALLBACKS || attributes != details.attributes()) { |
3929 // AddProperty will either normalize the object, or create a new fast copy | 3929 // AddPropertyInternal will either normalize the object, or create a new |
3930 // of the map. If we get a fast copy of the map, all field representations | 3930 // fast copy of the map. If we get a fast copy of the map, all field |
3931 // will be tagged since the transition is omitted. | 3931 // representations will be tagged since the transition is omitted. |
3932 return JSObject::AddProperty( | 3932 return JSObject::AddPropertyInternal( |
3933 object, name, value, attributes, SLOPPY, | 3933 object, name, value, attributes, SLOPPY, |
3934 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED, | 3934 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED, |
3935 JSReceiver::OMIT_EXTENSIBILITY_CHECK, | 3935 JSReceiver::OMIT_EXTENSIBILITY_CHECK, |
3936 JSObject::FORCE_TAGGED, FORCE_FIELD, OMIT_TRANSITION); | 3936 JSObject::FORCE_TAGGED, FORCE_FIELD, OMIT_TRANSITION); |
3937 } | 3937 } |
3938 | 3938 |
3939 // Keep the target CONSTANT if the same value is stored. | 3939 // Keep the target CONSTANT if the same value is stored. |
3940 // TODO(verwaest): Also support keeping the placeholder | 3940 // TODO(verwaest): Also support keeping the placeholder |
3941 // (value->IsUninitialized) as constant. | 3941 // (value->IsUninitialized) as constant. |
3942 if (!lookup->CanHoldValue(value)) { | 3942 if (!lookup->CanHoldValue(value)) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4086 ASSIGN_RETURN_ON_EXCEPTION( | 4086 ASSIGN_RETURN_ON_EXCEPTION( |
4087 isolate, result_object, | 4087 isolate, result_object, |
4088 SetPropertyViaPrototypes( | 4088 SetPropertyViaPrototypes( |
4089 object, name, value, attributes, strict_mode, &done), | 4089 object, name, value, attributes, strict_mode, &done), |
4090 Object); | 4090 Object); |
4091 if (done) return result_object; | 4091 if (done) return result_object; |
4092 } | 4092 } |
4093 | 4093 |
4094 if (!lookup->IsFound()) { | 4094 if (!lookup->IsFound()) { |
4095 // Neither properties nor transitions found. | 4095 // Neither properties nor transitions found. |
4096 return AddProperty( | 4096 return AddPropertyInternal( |
4097 object, name, value, attributes, strict_mode, store_mode); | 4097 object, name, value, attributes, strict_mode, store_mode); |
4098 } | 4098 } |
4099 | 4099 |
4100 if (lookup->IsProperty() && lookup->IsReadOnly()) { | 4100 if (lookup->IsProperty() && lookup->IsReadOnly()) { |
4101 if (strict_mode == STRICT) { | 4101 if (strict_mode == STRICT) { |
4102 Handle<Object> args[] = { name, object }; | 4102 Handle<Object> args[] = { name, object }; |
4103 Handle<Object> error = isolate->factory()->NewTypeError( | 4103 Handle<Object> error = isolate->factory()->NewTypeError( |
4104 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args))); | 4104 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args))); |
4105 return isolate->Throw<Object>(error); | 4105 return isolate->Throw<Object>(error); |
4106 } else { | 4106 } else { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4166 EnqueueChangeRecord(object, "update", name, old_value); | 4166 EnqueueChangeRecord(object, "update", name, old_value); |
4167 } | 4167 } |
4168 } | 4168 } |
4169 } | 4169 } |
4170 } | 4170 } |
4171 | 4171 |
4172 return result; | 4172 return result; |
4173 } | 4173 } |
4174 | 4174 |
4175 | 4175 |
| 4176 void JSObject::AddProperty( |
| 4177 Handle<JSObject> object, |
| 4178 Handle<Name> name, |
| 4179 Handle<Object> value, |
| 4180 PropertyAttributes attributes, |
| 4181 ValueType value_type, |
| 4182 StoreMode store_mode) { |
| 4183 #ifdef DEBUG |
| 4184 uint32_t index; |
| 4185 ASSERT(!object->IsJSProxy()); |
| 4186 ASSERT(!name->AsArrayIndex(&index)); |
| 4187 LookupIterator it(object, name, LookupIterator::CHECK_OWN_REAL); |
| 4188 GetPropertyAttributes(&it); |
| 4189 ASSERT(!it.IsFound()); |
| 4190 ASSERT(object->map()->is_extensible()); |
| 4191 #endif |
| 4192 SetOwnPropertyIgnoreAttributes( |
| 4193 object, name, value, attributes, value_type, store_mode, |
| 4194 OMIT_EXTENSIBILITY_CHECK).Check(); |
| 4195 } |
| 4196 |
| 4197 |
4176 // Set a real own property, even if it is READ_ONLY. If the property is not | 4198 // Set a real own property, even if it is READ_ONLY. If the property is not |
4177 // present, add it with attributes NONE. This code is an exact clone of | 4199 // present, add it with attributes NONE. This code is an exact clone of |
4178 // SetProperty, with the check for IsReadOnly and the check for a | 4200 // SetProperty, with the check for IsReadOnly and the check for a |
4179 // callback setter removed. The two lines looking up the LookupResult | 4201 // callback setter removed. The two lines looking up the LookupResult |
4180 // result are also added. If one of the functions is changed, the other | 4202 // result are also added. If one of the functions is changed, the other |
4181 // should be. | 4203 // should be. |
4182 MaybeHandle<Object> JSObject::SetOwnPropertyIgnoreAttributes( | 4204 MaybeHandle<Object> JSObject::SetOwnPropertyIgnoreAttributes( |
4183 Handle<JSObject> object, | 4205 Handle<JSObject> object, |
4184 Handle<Name> name, | 4206 Handle<Name> name, |
4185 Handle<Object> value, | 4207 Handle<Object> value, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4221 (lookup.IsDescriptorOrDictionary() && lookup.type() == CALLBACKS)) { | 4243 (lookup.IsDescriptorOrDictionary() && lookup.type() == CALLBACKS)) { |
4222 object->LookupOwnRealNamedProperty(name, &lookup); | 4244 object->LookupOwnRealNamedProperty(name, &lookup); |
4223 } | 4245 } |
4224 | 4246 |
4225 // Check for accessor in prototype chain removed here in clone. | 4247 // Check for accessor in prototype chain removed here in clone. |
4226 if (!lookup.IsFound()) { | 4248 if (!lookup.IsFound()) { |
4227 object->map()->LookupTransition(*object, *name, &lookup); | 4249 object->map()->LookupTransition(*object, *name, &lookup); |
4228 TransitionFlag flag = lookup.IsFound() | 4250 TransitionFlag flag = lookup.IsFound() |
4229 ? OMIT_TRANSITION : INSERT_TRANSITION; | 4251 ? OMIT_TRANSITION : INSERT_TRANSITION; |
4230 // Neither properties nor transitions found. | 4252 // Neither properties nor transitions found. |
4231 return AddProperty(object, name, value, attributes, SLOPPY, | 4253 return AddPropertyInternal(object, name, value, attributes, SLOPPY, |
4232 store_from_keyed, extensibility_check, value_type, mode, flag); | 4254 store_from_keyed, extensibility_check, value_type, mode, flag); |
4233 } | 4255 } |
4234 | 4256 |
4235 Handle<Object> old_value = isolate->factory()->the_hole_value(); | 4257 Handle<Object> old_value = isolate->factory()->the_hole_value(); |
4236 PropertyAttributes old_attributes = ABSENT; | 4258 PropertyAttributes old_attributes = ABSENT; |
4237 bool is_observed = object->map()->is_observed() && | 4259 bool is_observed = object->map()->is_observed() && |
4238 *name != isolate->heap()->hidden_string(); | 4260 *name != isolate->heap()->hidden_string(); |
4239 if (is_observed && lookup.IsProperty()) { | 4261 if (is_observed && lookup.IsProperty()) { |
4240 if (lookup.IsDataProperty()) { | 4262 if (lookup.IsDataProperty()) { |
4241 old_value = Object::GetPropertyOrElement(object, name).ToHandleChecked(); | 4263 old_value = Object::GetPropertyOrElement(object, name).ToHandleChecked(); |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5147 | 5169 |
5148 if (inline_value->IsSmi()) { | 5170 if (inline_value->IsSmi()) { |
5149 // We were storing the identity hash inline and now allocated an actual | 5171 // We were storing the identity hash inline and now allocated an actual |
5150 // dictionary. Put the identity hash into the new dictionary. | 5172 // dictionary. Put the identity hash into the new dictionary. |
5151 hashtable = ObjectHashTable::Put(hashtable, | 5173 hashtable = ObjectHashTable::Put(hashtable, |
5152 isolate->factory()->identity_hash_string(), | 5174 isolate->factory()->identity_hash_string(), |
5153 inline_value); | 5175 inline_value); |
5154 } | 5176 } |
5155 | 5177 |
5156 JSObject::SetOwnPropertyIgnoreAttributes( | 5178 JSObject::SetOwnPropertyIgnoreAttributes( |
5157 object, | 5179 object, isolate->factory()->hidden_string(), |
5158 isolate->factory()->hidden_string(), | 5180 hashtable, DONT_ENUM).Assert(); |
5159 hashtable, | |
5160 DONT_ENUM, | |
5161 OPTIMAL_REPRESENTATION, | |
5162 ALLOW_AS_CONSTANT, | |
5163 OMIT_EXTENSIBILITY_CHECK).Assert(); | |
5164 | 5181 |
5165 return hashtable; | 5182 return hashtable; |
5166 } | 5183 } |
5167 | 5184 |
5168 | 5185 |
5169 Handle<Object> JSObject::SetHiddenPropertiesHashTable(Handle<JSObject> object, | 5186 Handle<Object> JSObject::SetHiddenPropertiesHashTable(Handle<JSObject> object, |
5170 Handle<Object> value) { | 5187 Handle<Object> value) { |
5171 ASSERT(!object->IsJSGlobalProxy()); | 5188 ASSERT(!object->IsJSGlobalProxy()); |
5172 | 5189 |
5173 Isolate* isolate = object->GetIsolate(); | 5190 Isolate* isolate = object->GetIsolate(); |
(...skipping 11766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16940 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16957 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16941 static const char* error_messages_[] = { | 16958 static const char* error_messages_[] = { |
16942 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16959 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16943 }; | 16960 }; |
16944 #undef ERROR_MESSAGES_TEXTS | 16961 #undef ERROR_MESSAGES_TEXTS |
16945 return error_messages_[reason]; | 16962 return error_messages_[reason]; |
16946 } | 16963 } |
16947 | 16964 |
16948 | 16965 |
16949 } } // namespace v8::internal | 16966 } } // namespace v8::internal |
OLD | NEW |