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 <iomanip> | 5 #include <iomanip> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 6242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6253 } | 6253 } |
6254 | 6254 |
6255 | 6255 |
6256 MaybeHandle<Object> JSObject::DefineAccessor(Handle<JSObject> object, | 6256 MaybeHandle<Object> JSObject::DefineAccessor(Handle<JSObject> object, |
6257 Handle<Name> name, | 6257 Handle<Name> name, |
6258 Handle<Object> getter, | 6258 Handle<Object> getter, |
6259 Handle<Object> setter, | 6259 Handle<Object> setter, |
6260 PropertyAttributes attributes) { | 6260 PropertyAttributes attributes) { |
6261 Isolate* isolate = object->GetIsolate(); | 6261 Isolate* isolate = object->GetIsolate(); |
6262 | 6262 |
6263 // Make sure that the top context does not change when doing callbacks or | |
6264 // interceptor calls. | |
6265 AssertNoContextChange ncc(isolate); | |
6266 | |
6267 // Try to flatten before operating on the string. | |
6268 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); | |
6269 | |
6270 LookupIterator it = LookupIterator::PropertyOrElement( | 6263 LookupIterator it = LookupIterator::PropertyOrElement( |
6271 isolate, object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 6264 isolate, object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); |
6272 | 6265 |
6273 if (it.state() == LookupIterator::ACCESS_CHECK) { | 6266 if (it.state() == LookupIterator::ACCESS_CHECK) { |
6274 if (!it.HasAccess()) { | 6267 if (!it.HasAccess()) { |
6275 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); | 6268 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); |
6276 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 6269 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
6277 return isolate->factory()->undefined_value(); | 6270 return isolate->factory()->undefined_value(); |
6278 } | 6271 } |
6279 it.Next(); | 6272 it.Next(); |
(...skipping 23 matching lines...) Expand all Loading... |
6303 // At least one of the accessors needs to be a new value. | 6296 // At least one of the accessors needs to be a new value. |
6304 DCHECK(!getter->IsNull() || !setter->IsNull()); | 6297 DCHECK(!getter->IsNull() || !setter->IsNull()); |
6305 if (!getter->IsNull()) { | 6298 if (!getter->IsNull()) { |
6306 it.TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes); | 6299 it.TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes); |
6307 } | 6300 } |
6308 if (!setter->IsNull()) { | 6301 if (!setter->IsNull()) { |
6309 it.TransitionToAccessorProperty(ACCESSOR_SETTER, setter, attributes); | 6302 it.TransitionToAccessorProperty(ACCESSOR_SETTER, setter, attributes); |
6310 } | 6303 } |
6311 | 6304 |
6312 if (is_observed) { | 6305 if (is_observed) { |
| 6306 // Make sure the top context isn't changed. |
| 6307 AssertNoContextChange ncc(isolate); |
6313 const char* type = preexists ? "reconfigure" : "add"; | 6308 const char* type = preexists ? "reconfigure" : "add"; |
6314 RETURN_ON_EXCEPTION( | 6309 RETURN_ON_EXCEPTION( |
6315 isolate, EnqueueChangeRecord(object, type, name, old_value), Object); | 6310 isolate, EnqueueChangeRecord(object, type, name, old_value), Object); |
6316 } | 6311 } |
6317 | 6312 |
6318 return isolate->factory()->undefined_value(); | 6313 return isolate->factory()->undefined_value(); |
6319 } | 6314 } |
6320 | 6315 |
6321 | 6316 |
6322 MaybeHandle<Object> JSObject::SetAccessor(Handle<JSObject> object, | 6317 MaybeHandle<Object> JSObject::SetAccessor(Handle<JSObject> object, |
6323 Handle<AccessorInfo> info) { | 6318 Handle<AccessorInfo> info) { |
6324 Isolate* isolate = object->GetIsolate(); | 6319 Isolate* isolate = object->GetIsolate(); |
6325 | 6320 Handle<Name> name(Name::cast(info->name()), isolate); |
6326 // Make sure that the top context does not change when doing callbacks or | |
6327 // interceptor calls. | |
6328 AssertNoContextChange ncc(isolate); | |
6329 | |
6330 // Try to flatten before operating on the string. | |
6331 Handle<Name> name(Name::cast(info->name())); | |
6332 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); | |
6333 | 6321 |
6334 LookupIterator it = LookupIterator::PropertyOrElement( | 6322 LookupIterator it = LookupIterator::PropertyOrElement( |
6335 isolate, object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 6323 isolate, object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); |
6336 | 6324 |
6337 // Duplicate ACCESS_CHECK outside of GetPropertyAttributes for the case that | 6325 // Duplicate ACCESS_CHECK outside of GetPropertyAttributes for the case that |
6338 // the FailedAccessCheckCallbackFunction doesn't throw an exception. | 6326 // the FailedAccessCheckCallbackFunction doesn't throw an exception. |
6339 // | 6327 // |
6340 // TODO(verwaest): Force throw an exception if the callback doesn't, so we can | 6328 // TODO(verwaest): Force throw an exception if the callback doesn't, so we can |
6341 // remove reliance on default return values. | 6329 // remove reliance on default return values. |
6342 if (it.state() == LookupIterator::ACCESS_CHECK) { | 6330 if (it.state() == LookupIterator::ACCESS_CHECK) { |
6343 if (!it.HasAccess()) { | 6331 if (!it.HasAccess()) { |
6344 isolate->ReportFailedAccessCheck(object); | 6332 isolate->ReportFailedAccessCheck(object); |
6345 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 6333 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
6346 return it.factory()->undefined_value(); | 6334 return it.factory()->undefined_value(); |
6347 } | 6335 } |
6348 it.Next(); | 6336 it.Next(); |
6349 } | 6337 } |
6350 | 6338 |
| 6339 // Ignore accessors on typed arrays. |
| 6340 if (it.IsElement() && (object->HasFixedTypedArrayElements() || |
| 6341 object->HasExternalArrayElements())) { |
| 6342 return it.factory()->undefined_value(); |
| 6343 } |
| 6344 |
6351 CHECK(GetPropertyAttributes(&it).IsJust()); | 6345 CHECK(GetPropertyAttributes(&it).IsJust()); |
6352 | 6346 |
6353 // ES5 forbids turning a property into an accessor if it's not | 6347 // ES5 forbids turning a property into an accessor if it's not |
6354 // configurable. See 8.6.1 (Table 5). | 6348 // configurable. See 8.6.1 (Table 5). |
6355 if (it.IsFound() && (it.IsReadOnly() || !it.IsConfigurable())) { | 6349 if (it.IsFound() && (it.IsReadOnly() || !it.IsConfigurable())) { |
6356 return it.factory()->undefined_value(); | 6350 return it.factory()->undefined_value(); |
6357 } | 6351 } |
6358 | 6352 |
6359 // Ignore accessors on typed arrays. | |
6360 if (it.IsElement() && (object->HasFixedTypedArrayElements() || | |
6361 object->HasExternalArrayElements())) { | |
6362 return it.factory()->undefined_value(); | |
6363 } | |
6364 | |
6365 it.TransitionToAccessorPair(info, info->property_attributes()); | 6353 it.TransitionToAccessorPair(info, info->property_attributes()); |
6366 | 6354 |
6367 return object; | 6355 return object; |
6368 } | 6356 } |
6369 | 6357 |
6370 | 6358 |
6371 MaybeHandle<Object> JSObject::GetAccessor(Handle<JSObject> object, | 6359 MaybeHandle<Object> JSObject::GetAccessor(Handle<JSObject> object, |
6372 Handle<Name> name, | 6360 Handle<Name> name, |
6373 AccessorComponent component) { | 6361 AccessorComponent component) { |
6374 Isolate* isolate = object->GetIsolate(); | 6362 Isolate* isolate = object->GetIsolate(); |
(...skipping 9575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15950 Handle<Object> new_value) { | 15938 Handle<Object> new_value) { |
15951 if (cell->value() != *new_value) { | 15939 if (cell->value() != *new_value) { |
15952 cell->set_value(*new_value); | 15940 cell->set_value(*new_value); |
15953 Isolate* isolate = cell->GetIsolate(); | 15941 Isolate* isolate = cell->GetIsolate(); |
15954 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 15942 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
15955 isolate, DependentCode::kPropertyCellChangedGroup); | 15943 isolate, DependentCode::kPropertyCellChangedGroup); |
15956 } | 15944 } |
15957 } | 15945 } |
15958 } // namespace internal | 15946 } // namespace internal |
15959 } // namespace v8 | 15947 } // namespace v8 |
OLD | NEW |