| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "v8.h" | 8 #include "v8.h" |
| 9 | 9 |
| 10 #include "accessors.h" | 10 #include "accessors.h" |
| (...skipping 5157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5168 | 5168 |
| 5169 // Check access rights if needed. | 5169 // Check access rights if needed. |
| 5170 if (js_object->IsAccessCheckNeeded() && | 5170 if (js_object->IsAccessCheckNeeded() && |
| 5171 !isolate->MayNamedAccess(js_object, name, v8::ACCESS_SET)) { | 5171 !isolate->MayNamedAccess(js_object, name, v8::ACCESS_SET)) { |
| 5172 return isolate->heap()->undefined_value(); | 5172 return isolate->heap()->undefined_value(); |
| 5173 } | 5173 } |
| 5174 | 5174 |
| 5175 LookupResult lookup(isolate); | 5175 LookupResult lookup(isolate); |
| 5176 js_object->LookupOwnRealNamedProperty(name, &lookup); | 5176 js_object->LookupOwnRealNamedProperty(name, &lookup); |
| 5177 | 5177 |
| 5178 // Special case for callback properties. | |
| 5179 if (lookup.IsPropertyCallbacks()) { | |
| 5180 Handle<Object> callback(lookup.GetCallbackObject(), isolate); | |
| 5181 // Avoid redefining callback as data property, just use the stored | |
| 5182 // setter to update the value instead. | |
| 5183 // TODO(mstarzinger): So far this only works if property attributes don't | |
| 5184 // change, this should be fixed once we cleanup the underlying code. | |
| 5185 ASSERT(!callback->IsForeign()); | |
| 5186 if (callback->IsAccessorInfo() && | |
| 5187 lookup.GetAttributes() == attr) { | |
| 5188 Handle<Object> result_object; | |
| 5189 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 5190 isolate, result_object, | |
| 5191 JSObject::SetPropertyWithCallback(js_object, name, obj_value, | |
| 5192 handle(lookup.holder()), | |
| 5193 callback, STRICT)); | |
| 5194 return *result_object; | |
| 5195 } | |
| 5196 } | |
| 5197 | |
| 5198 // Take special care when attributes are different and there is already | 5178 // Take special care when attributes are different and there is already |
| 5199 // a property. For simplicity we normalize the property which enables us | 5179 // a property. For simplicity we normalize the property which enables us |
| 5200 // to not worry about changing the instance_descriptor and creating a new | 5180 // to not worry about changing the instance_descriptor and creating a new |
| 5201 // map. The current version of SetObjectProperty does not handle attributes | 5181 // map. The current version of SetObjectProperty does not handle attributes |
| 5202 // correctly in the case where a property is a field and is reset with | 5182 // correctly in the case where a property is a field and is reset with |
| 5203 // new attributes. | 5183 // new attributes. |
| 5204 if (lookup.IsFound() && | 5184 if (lookup.IsFound() && |
| 5205 (attr != lookup.GetAttributes() || lookup.IsPropertyCallbacks())) { | 5185 (attr != lookup.GetAttributes() || lookup.IsPropertyCallbacks())) { |
| 5206 // New attributes - normalize to avoid writing to instance descriptor | 5186 // New attributes - normalize to avoid writing to instance descriptor |
| 5207 if (js_object->IsJSGlobalProxy()) { | 5187 if (js_object->IsJSGlobalProxy()) { |
| 5208 // Since the result is a property, the prototype will exist so | 5188 // Since the result is a property, the prototype will exist so |
| 5209 // we don't have to check for null. | 5189 // we don't have to check for null. |
| 5210 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); | 5190 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); |
| 5211 } | 5191 } |
| 5212 JSObject::NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); | 5192 |
| 5193 if (attr != lookup.GetAttributes() || |
| 5194 (lookup.IsPropertyCallbacks() && |
| 5195 !lookup.GetCallbackObject()->IsAccessorInfo())) { |
| 5196 JSObject::NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); |
| 5197 } |
| 5198 |
| 5213 // Use IgnoreAttributes version since a readonly property may be | 5199 // Use IgnoreAttributes version since a readonly property may be |
| 5214 // overridden and SetProperty does not allow this. | 5200 // overridden and SetProperty does not allow this. |
| 5215 Handle<Object> result; | 5201 Handle<Object> result; |
| 5216 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 5202 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5217 isolate, result, | 5203 isolate, result, |
| 5218 JSObject::SetOwnPropertyIgnoreAttributes( | 5204 JSObject::SetOwnPropertyIgnoreAttributes( |
| 5219 js_object, name, obj_value, attr)); | 5205 js_object, name, obj_value, attr, |
| 5206 Object::OPTIMAL_REPRESENTATION, |
| 5207 ALLOW_AS_CONSTANT, |
| 5208 JSReceiver::PERFORM_EXTENSIBILITY_CHECK, |
| 5209 JSReceiver::MAY_BE_STORE_FROM_KEYED, |
| 5210 JSObject::DONT_FORCE_FIELD)); |
| 5220 return *result; | 5211 return *result; |
| 5221 } | 5212 } |
| 5222 | 5213 |
| 5223 Handle<Object> result; | 5214 Handle<Object> result; |
| 5224 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 5215 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5225 isolate, result, | 5216 isolate, result, |
| 5226 Runtime::ForceSetObjectProperty( | 5217 Runtime::ForceSetObjectProperty( |
| 5227 js_object, name, obj_value, attr, | 5218 js_object, name, obj_value, attr, |
| 5228 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED)); | 5219 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED)); |
| 5229 return *result; | 5220 return *result; |
| (...skipping 9937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15167 } | 15158 } |
| 15168 return NULL; | 15159 return NULL; |
| 15169 } | 15160 } |
| 15170 | 15161 |
| 15171 | 15162 |
| 15172 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15163 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 15173 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15164 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 15174 } | 15165 } |
| 15175 | 15166 |
| 15176 } } // namespace v8::internal | 15167 } } // namespace v8::internal |
| OLD | NEW |