| 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 5221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5232 | 5232 |
| 5233 // Check access rights if needed. | 5233 // Check access rights if needed. |
| 5234 if (js_object->IsAccessCheckNeeded() && | 5234 if (js_object->IsAccessCheckNeeded() && |
| 5235 !isolate->MayNamedAccess(js_object, name, v8::ACCESS_SET)) { | 5235 !isolate->MayNamedAccess(js_object, name, v8::ACCESS_SET)) { |
| 5236 return isolate->heap()->undefined_value(); | 5236 return isolate->heap()->undefined_value(); |
| 5237 } | 5237 } |
| 5238 | 5238 |
| 5239 LookupResult lookup(isolate); | 5239 LookupResult lookup(isolate); |
| 5240 js_object->LocalLookupRealNamedProperty(name, &lookup); | 5240 js_object->LocalLookupRealNamedProperty(name, &lookup); |
| 5241 | 5241 |
| 5242 // Special case for callback properties. | |
| 5243 if (lookup.IsPropertyCallbacks()) { | |
| 5244 Handle<Object> callback(lookup.GetCallbackObject(), isolate); | |
| 5245 // Avoid redefining callback as data property, just use the stored | |
| 5246 // setter to update the value instead. | |
| 5247 // TODO(mstarzinger): So far this only works if property attributes don't | |
| 5248 // change, this should be fixed once we cleanup the underlying code. | |
| 5249 ASSERT(!callback->IsForeign()); | |
| 5250 if (callback->IsAccessorInfo() && | |
| 5251 lookup.GetAttributes() == attr) { | |
| 5252 Handle<Object> result_object; | |
| 5253 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 5254 isolate, result_object, | |
| 5255 JSObject::SetPropertyWithCallback(js_object, | |
| 5256 callback, | |
| 5257 name, | |
| 5258 obj_value, | |
| 5259 handle(lookup.holder()), | |
| 5260 STRICT)); | |
| 5261 return *result_object; | |
| 5262 } | |
| 5263 } | |
| 5264 | |
| 5265 // Take special care when attributes are different and there is already | 5242 // Take special care when attributes are different and there is already |
| 5266 // a property. For simplicity we normalize the property which enables us | 5243 // a property. For simplicity we normalize the property which enables us |
| 5267 // to not worry about changing the instance_descriptor and creating a new | 5244 // to not worry about changing the instance_descriptor and creating a new |
| 5268 // map. The current version of SetObjectProperty does not handle attributes | 5245 // map. The current version of SetObjectProperty does not handle attributes |
| 5269 // correctly in the case where a property is a field and is reset with | 5246 // correctly in the case where a property is a field and is reset with |
| 5270 // new attributes. | 5247 // new attributes. |
| 5271 if (lookup.IsFound() && | 5248 if (lookup.IsFound() && |
| 5272 (attr != lookup.GetAttributes() || lookup.IsPropertyCallbacks())) { | 5249 (attr != lookup.GetAttributes() || lookup.IsPropertyCallbacks())) { |
| 5273 // New attributes - normalize to avoid writing to instance descriptor | 5250 // New attributes - normalize to avoid writing to instance descriptor |
| 5274 if (js_object->IsJSGlobalProxy()) { | 5251 if (js_object->IsJSGlobalProxy()) { |
| 5275 // Since the result is a property, the prototype will exist so | 5252 // Since the result is a property, the prototype will exist so |
| 5276 // we don't have to check for null. | 5253 // we don't have to check for null. |
| 5277 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); | 5254 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); |
| 5278 } | 5255 } |
| 5279 JSObject::NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); | 5256 |
| 5257 if (attr != lookup.GetAttributes() || |
| 5258 (lookup.IsPropertyCallbacks() && |
| 5259 !lookup.GetCallbackObject()->IsAccessorInfo())) { |
| 5260 JSObject::NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); |
| 5261 } |
| 5262 |
| 5280 // Use IgnoreAttributes version since a readonly property may be | 5263 // Use IgnoreAttributes version since a readonly property may be |
| 5281 // overridden and SetProperty does not allow this. | 5264 // overridden and SetProperty does not allow this. |
| 5282 Handle<Object> result; | 5265 Handle<Object> result; |
| 5283 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 5266 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5284 isolate, result, | 5267 isolate, result, |
| 5285 JSObject::SetLocalPropertyIgnoreAttributes( | 5268 JSObject::SetLocalPropertyIgnoreAttributes( |
| 5286 js_object, name, obj_value, attr)); | 5269 js_object, name, obj_value, attr, |
| 5270 Object::OPTIMAL_REPRESENTATION, |
| 5271 ALLOW_AS_CONSTANT, |
| 5272 JSReceiver::PERFORM_EXTENSIBILITY_CHECK, |
| 5273 JSReceiver::MAY_BE_STORE_FROM_KEYED, |
| 5274 JSObject::DONT_FORCE_FIELD)); |
| 5287 return *result; | 5275 return *result; |
| 5288 } | 5276 } |
| 5289 | 5277 |
| 5290 Handle<Object> result; | 5278 Handle<Object> result; |
| 5291 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 5279 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 5292 isolate, result, | 5280 isolate, result, |
| 5293 Runtime::ForceSetObjectProperty( | 5281 Runtime::ForceSetObjectProperty( |
| 5294 js_object, name, obj_value, attr, | 5282 js_object, name, obj_value, attr, |
| 5295 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED)); | 5283 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED)); |
| 5296 return *result; | 5284 return *result; |
| (...skipping 9943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15240 } | 15228 } |
| 15241 return NULL; | 15229 return NULL; |
| 15242 } | 15230 } |
| 15243 | 15231 |
| 15244 | 15232 |
| 15245 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15233 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 15246 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15234 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 15247 } | 15235 } |
| 15248 | 15236 |
| 15249 } } // namespace v8::internal | 15237 } } // namespace v8::internal |
| OLD | NEW |