OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 HandleScope scope(isolate); | 263 HandleScope scope(isolate); |
264 DCHECK(args.length() == 2); | 264 DCHECK(args.length() == 2); |
265 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0); | 265 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, obj, 0); |
266 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); | 266 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); |
267 MAYBE_RETURN( | 267 MAYBE_RETURN( |
268 JSReceiver::SetPrototype(obj, prototype, true, Object::THROW_ON_ERROR), | 268 JSReceiver::SetPrototype(obj, prototype, true, Object::THROW_ON_ERROR), |
269 isolate->heap()->exception()); | 269 isolate->heap()->exception()); |
270 return *obj; | 270 return *obj; |
271 } | 271 } |
272 | 272 |
| 273 |
| 274 // Enumerator used as indices into the array returned from GetOwnProperty |
| 275 enum PropertyDescriptorIndices { |
| 276 IS_ACCESSOR_INDEX, |
| 277 VALUE_INDEX, |
| 278 GETTER_INDEX, |
| 279 SETTER_INDEX, |
| 280 WRITABLE_INDEX, |
| 281 ENUMERABLE_INDEX, |
| 282 CONFIGURABLE_INDEX, |
| 283 DESCRIPTOR_SIZE |
| 284 }; |
| 285 |
| 286 |
| 287 MUST_USE_RESULT static MaybeHandle<Object> GetOwnProperty(Isolate* isolate, |
| 288 Handle<JSObject> obj, |
| 289 Handle<Name> name) { |
| 290 Heap* heap = isolate->heap(); |
| 291 Factory* factory = isolate->factory(); |
| 292 |
| 293 // Get attributes. |
| 294 LookupIterator it = LookupIterator::PropertyOrElement(isolate, obj, name, obj, |
| 295 LookupIterator::HIDDEN); |
| 296 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); |
| 297 |
| 298 if (!maybe.IsJust()) return MaybeHandle<Object>(); |
| 299 PropertyAttributes attrs = maybe.FromJust(); |
| 300 if (attrs == ABSENT) return factory->undefined_value(); |
| 301 |
| 302 DCHECK(!isolate->has_pending_exception()); |
| 303 Handle<FixedArray> elms = factory->NewFixedArray(DESCRIPTOR_SIZE); |
| 304 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); |
| 305 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0)); |
| 306 |
| 307 bool is_accessor_pair = it.state() == LookupIterator::ACCESSOR && |
| 308 it.GetAccessors()->IsAccessorPair(); |
| 309 elms->set(IS_ACCESSOR_INDEX, heap->ToBoolean(is_accessor_pair)); |
| 310 |
| 311 if (is_accessor_pair) { |
| 312 Handle<AccessorPair> accessors = |
| 313 Handle<AccessorPair>::cast(it.GetAccessors()); |
| 314 Handle<Object> getter = |
| 315 AccessorPair::GetComponent(accessors, ACCESSOR_GETTER); |
| 316 Handle<Object> setter = |
| 317 AccessorPair::GetComponent(accessors, ACCESSOR_SETTER); |
| 318 elms->set(GETTER_INDEX, *getter); |
| 319 elms->set(SETTER_INDEX, *setter); |
| 320 } else { |
| 321 Handle<Object> value; |
| 322 ASSIGN_RETURN_ON_EXCEPTION(isolate, value, Object::GetProperty(&it), |
| 323 Object); |
| 324 elms->set(WRITABLE_INDEX, heap->ToBoolean((attrs & READ_ONLY) == 0)); |
| 325 elms->set(VALUE_INDEX, *value); |
| 326 } |
| 327 |
| 328 return factory->NewJSArrayWithElements(elms); |
| 329 } |
| 330 |
| 331 |
| 332 // Returns an array with the property description: |
| 333 // if args[1] is not a property on args[0] |
| 334 // returns undefined |
| 335 // if args[1] is a data property on args[0] |
| 336 // [false, value, Writeable, Enumerable, Configurable] |
| 337 // if args[1] is an accessor on args[0] |
| 338 // [true, GetFunction, SetFunction, Enumerable, Configurable] |
| 339 // TODO(jkummerow): Deprecated. Remove all callers and delete. |
| 340 RUNTIME_FUNCTION(Runtime_GetOwnProperty_Legacy) { |
| 341 HandleScope scope(isolate); |
| 342 DCHECK(args.length() == 2); |
| 343 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
| 344 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 345 Handle<Object> result; |
| 346 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
| 347 GetOwnProperty(isolate, obj, name)); |
| 348 return *result; |
| 349 } |
| 350 |
| 351 |
273 RUNTIME_FUNCTION(Runtime_OptimizeObjectForAddingMultipleProperties) { | 352 RUNTIME_FUNCTION(Runtime_OptimizeObjectForAddingMultipleProperties) { |
274 HandleScope scope(isolate); | 353 HandleScope scope(isolate); |
275 DCHECK(args.length() == 2); | 354 DCHECK(args.length() == 2); |
276 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 355 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
277 CONVERT_SMI_ARG_CHECKED(properties, 1); | 356 CONVERT_SMI_ARG_CHECKED(properties, 1); |
278 // Conservative upper limit to prevent fuzz tests from going OOM. | 357 // Conservative upper limit to prevent fuzz tests from going OOM. |
279 RUNTIME_ASSERT(properties <= 100000); | 358 RUNTIME_ASSERT(properties <= 100000); |
280 if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { | 359 if (object->HasFastProperties() && !object->IsJSGlobalProxy()) { |
281 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties, | 360 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties, |
282 "OptimizeForAdding"); | 361 "OptimizeForAdding"); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 HandleScope scope(isolate); | 729 HandleScope scope(isolate); |
651 DCHECK(args.length() == 1); | 730 DCHECK(args.length() == 1); |
652 | 731 |
653 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0); | 732 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0); |
654 initial_map->CompleteInobjectSlackTracking(); | 733 initial_map->CompleteInobjectSlackTracking(); |
655 | 734 |
656 return isolate->heap()->undefined_value(); | 735 return isolate->heap()->undefined_value(); |
657 } | 736 } |
658 | 737 |
659 | 738 |
| 739 RUNTIME_FUNCTION(Runtime_GlobalProxy) { |
| 740 SealHandleScope shs(isolate); |
| 741 DCHECK(args.length() == 1); |
| 742 CONVERT_ARG_CHECKED(JSFunction, function, 0); |
| 743 return function->context()->global_proxy(); |
| 744 } |
| 745 |
| 746 |
| 747 RUNTIME_FUNCTION(Runtime_LookupAccessor) { |
| 748 HandleScope scope(isolate); |
| 749 DCHECK(args.length() == 3); |
| 750 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); |
| 751 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 752 CONVERT_SMI_ARG_CHECKED(flag, 2); |
| 753 AccessorComponent component = flag == 0 ? ACCESSOR_GETTER : ACCESSOR_SETTER; |
| 754 if (!receiver->IsJSObject()) return isolate->heap()->undefined_value(); |
| 755 Handle<Object> result; |
| 756 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 757 isolate, result, |
| 758 JSObject::GetAccessor(Handle<JSObject>::cast(receiver), name, component)); |
| 759 return *result; |
| 760 } |
| 761 |
| 762 |
660 RUNTIME_FUNCTION(Runtime_LoadMutableDouble) { | 763 RUNTIME_FUNCTION(Runtime_LoadMutableDouble) { |
661 HandleScope scope(isolate); | 764 HandleScope scope(isolate); |
662 DCHECK(args.length() == 2); | 765 DCHECK(args.length() == 2); |
663 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 766 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
664 CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1); | 767 CONVERT_ARG_HANDLE_CHECKED(Smi, index, 1); |
665 RUNTIME_ASSERT((index->value() & 1) == 1); | 768 RUNTIME_ASSERT((index->value() & 1) == 1); |
666 FieldIndex field_index = | 769 FieldIndex field_index = |
667 FieldIndex::ForLoadByFieldIndex(object->map(), index->value()); | 770 FieldIndex::ForLoadByFieldIndex(object->map(), index->value()); |
668 if (field_index.is_inobject()) { | 771 if (field_index.is_inobject()) { |
669 RUNTIME_ASSERT(field_index.property_index() < | 772 RUNTIME_ASSERT(field_index.property_index() < |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 isolate, o, key, &success, LookupIterator::HIDDEN); | 1222 isolate, o, key, &success, LookupIterator::HIDDEN); |
1120 if (!success) return isolate->heap()->exception(); | 1223 if (!success) return isolate->heap()->exception(); |
1121 MAYBE_RETURN( | 1224 MAYBE_RETURN( |
1122 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 1225 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
1123 isolate->heap()->exception()); | 1226 isolate->heap()->exception()); |
1124 return *value; | 1227 return *value; |
1125 } | 1228 } |
1126 | 1229 |
1127 } // namespace internal | 1230 } // namespace internal |
1128 } // namespace v8 | 1231 } // namespace v8 |
OLD | NEW |