| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 DESCRIPTOR_SIZE | 207 DESCRIPTOR_SIZE |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 | 210 |
| 211 MUST_USE_RESULT static MaybeHandle<Object> GetOwnProperty(Isolate* isolate, | 211 MUST_USE_RESULT static MaybeHandle<Object> GetOwnProperty(Isolate* isolate, |
| 212 Handle<JSObject> obj, | 212 Handle<JSObject> obj, |
| 213 Handle<Name> name) { | 213 Handle<Name> name) { |
| 214 Heap* heap = isolate->heap(); | 214 Heap* heap = isolate->heap(); |
| 215 Factory* factory = isolate->factory(); | 215 Factory* factory = isolate->factory(); |
| 216 | 216 |
| 217 PropertyAttributes attrs; | |
| 218 // Get attributes. | 217 // Get attributes. |
| 219 LookupIterator it = LookupIterator::PropertyOrElement(isolate, obj, name, | 218 LookupIterator it = LookupIterator::PropertyOrElement(isolate, obj, name, |
| 220 LookupIterator::HIDDEN); | 219 LookupIterator::HIDDEN); |
| 221 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); | 220 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); |
| 222 | 221 |
| 223 if (!maybe.IsJust()) return MaybeHandle<Object>(); | 222 if (!maybe.IsJust()) return MaybeHandle<Object>(); |
| 224 attrs = maybe.FromJust(); | 223 PropertyAttributes attrs = maybe.FromJust(); |
| 225 if (attrs == ABSENT) return factory->undefined_value(); | 224 if (attrs == ABSENT) return factory->undefined_value(); |
| 226 | 225 |
| 227 DCHECK(!isolate->has_pending_exception()); | 226 DCHECK(!isolate->has_pending_exception()); |
| 228 Handle<FixedArray> elms = factory->NewFixedArray(DESCRIPTOR_SIZE); | 227 Handle<FixedArray> elms = factory->NewFixedArray(DESCRIPTOR_SIZE); |
| 229 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); | 228 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); |
| 230 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0)); | 229 elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0)); |
| 231 | 230 |
| 232 bool is_accessor_pair = it.state() == LookupIterator::ACCESSOR && | 231 bool is_accessor_pair = it.state() == LookupIterator::ACCESSOR && |
| 233 it.GetAccessors()->IsAccessorPair(); | 232 it.GetAccessors()->IsAccessorPair(); |
| 234 elms->set(IS_ACCESSOR_INDEX, heap->ToBoolean(is_accessor_pair)); | 233 elms->set(IS_ACCESSOR_INDEX, heap->ToBoolean(is_accessor_pair)); |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 DCHECK(args.length() == 1); | 779 DCHECK(args.length() == 1); |
| 781 | 780 |
| 782 CONVERT_ARG_CHECKED(JSReceiver, raw_object, 0); | 781 CONVERT_ARG_CHECKED(JSReceiver, raw_object, 0); |
| 783 | 782 |
| 784 if (raw_object->IsSimpleEnum()) return raw_object->map(); | 783 if (raw_object->IsSimpleEnum()) return raw_object->map(); |
| 785 | 784 |
| 786 HandleScope scope(isolate); | 785 HandleScope scope(isolate); |
| 787 Handle<JSReceiver> object(raw_object); | 786 Handle<JSReceiver> object(raw_object); |
| 788 Handle<FixedArray> content; | 787 Handle<FixedArray> content; |
| 789 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 788 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 790 isolate, content, | 789 isolate, content, JSReceiver::GetKeys(object, JSReceiver::INCLUDE_PROTOS, |
| 791 JSReceiver::GetKeys(object, JSReceiver::INCLUDE_PROTOS)); | 790 ENUMERABLE_STRINGS)); |
| 792 | 791 |
| 793 // Test again, since cache may have been built by preceding call. | 792 // Test again, since cache may have been built by preceding call. |
| 794 if (object->IsSimpleEnum()) return object->map(); | 793 if (object->IsSimpleEnum()) return object->map(); |
| 795 | 794 |
| 796 return *content; | 795 return *content; |
| 797 } | 796 } |
| 798 | 797 |
| 799 | 798 |
| 800 // Return the names of the own named properties. | 799 // Return the names of the own named properties. |
| 801 // args[0]: object | 800 // args[0]: object |
| 802 // args[1]: PropertyAttributes as int | 801 // args[1]: PropertyAttributes as int |
| 803 // TODO(cbruni/jkummerow): Use JSReceiver::GetKeys() internally, merge with | 802 // TODO(cbruni/jkummerow): Use JSReceiver::GetKeys() internally, merge with |
| 804 // Runtime_GetOwnElementNames. | 803 // Runtime_GetOwnElementNames. |
| 805 RUNTIME_FUNCTION(Runtime_GetOwnPropertyNames) { | 804 RUNTIME_FUNCTION(Runtime_GetOwnPropertyNames) { |
| 806 HandleScope scope(isolate); | 805 HandleScope scope(isolate); |
| 807 DCHECK(args.length() == 2); | 806 DCHECK(args.length() == 2); |
| 808 if (!args[0]->IsJSObject()) { | 807 if (!args[0]->IsJSObject()) { |
| 809 return isolate->heap()->undefined_value(); | 808 return isolate->heap()->undefined_value(); |
| 810 } | 809 } |
| 811 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 810 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 812 CONVERT_SMI_ARG_CHECKED(filter_value, 1); | 811 CONVERT_SMI_ARG_CHECKED(filter_value, 1); |
| 813 PropertyAttributes filter = static_cast<PropertyAttributes>(filter_value); | 812 |
| 813 // TODO(jkummerow): Temporary compatibility measure. Refactor callers. |
| 814 // Values of filter_value are defined in macros.py. |
| 815 PropertyFilter filter = ALL_PROPERTIES; |
| 816 if (filter_value & 2) { |
| 817 filter = static_cast<PropertyFilter>(filter | ONLY_ENUMERABLE); |
| 818 } |
| 819 if (filter_value & 8) { |
| 820 filter = static_cast<PropertyFilter>(filter | SKIP_STRINGS); |
| 821 } |
| 822 if (filter_value & 16) { |
| 823 filter = static_cast<PropertyFilter>(filter | SKIP_SYMBOLS); |
| 824 } |
| 825 DCHECK(filter_value & 32); |
| 814 | 826 |
| 815 // Find the number of own properties for each of the objects. | 827 // Find the number of own properties for each of the objects. |
| 816 int total_property_count = 0; | 828 int total_property_count = 0; |
| 817 for (PrototypeIterator iter(isolate, object, | 829 for (PrototypeIterator iter(isolate, object, |
| 818 PrototypeIterator::START_AT_RECEIVER); | 830 PrototypeIterator::START_AT_RECEIVER); |
| 819 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) { | 831 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) { |
| 820 // Casting to JSObject is fine because |object| is guaranteed to be one, | 832 // Casting to JSObject is fine because |object| is guaranteed to be one, |
| 821 // and we'll only look at hidden prototypes which are never JSProxies. | 833 // and we'll only look at hidden prototypes which are never JSProxies. |
| 822 Handle<JSObject> jsproto = PrototypeIterator::GetCurrent<JSObject>(iter); | 834 Handle<JSObject> jsproto = PrototypeIterator::GetCurrent<JSObject>(iter); |
| 823 total_property_count += jsproto->NumberOfOwnProperties(filter); | 835 total_property_count += jsproto->NumberOfOwnProperties(filter); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 PrototypeIterator iter(isolate, object, | 930 PrototypeIterator iter(isolate, object, |
| 919 PrototypeIterator::START_AT_PROTOTYPE); | 931 PrototypeIterator::START_AT_PROTOTYPE); |
| 920 if (iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)) { | 932 if (iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)) { |
| 921 return *isolate->factory()->NewJSArray(0); | 933 return *isolate->factory()->NewJSArray(0); |
| 922 } | 934 } |
| 923 // Casting to JSObject is fine because |object| is guaranteed to be one, | 935 // Casting to JSObject is fine because |object| is guaranteed to be one, |
| 924 // and we'll only look at hidden prototypes which are never JSProxies. | 936 // and we'll only look at hidden prototypes which are never JSProxies. |
| 925 object = PrototypeIterator::GetCurrent<JSObject>(iter); | 937 object = PrototypeIterator::GetCurrent<JSObject>(iter); |
| 926 } | 938 } |
| 927 | 939 |
| 928 int n = object->NumberOfOwnElements(NONE); | 940 int n = object->NumberOfOwnElements(ALL_PROPERTIES); |
| 929 Handle<FixedArray> names = isolate->factory()->NewFixedArray(n); | 941 Handle<FixedArray> names = isolate->factory()->NewFixedArray(n); |
| 930 object->GetOwnElementKeys(*names, NONE); | 942 object->GetOwnElementKeys(*names, ALL_PROPERTIES); |
| 931 return *isolate->factory()->NewJSArrayWithElements(names); | 943 return *isolate->factory()->NewJSArrayWithElements(names); |
| 932 } | 944 } |
| 933 | 945 |
| 934 | 946 |
| 935 // Return information on whether an object has a named or indexed interceptor. | 947 // Return information on whether an object has a named or indexed interceptor. |
| 936 // args[0]: object | 948 // args[0]: object |
| 937 RUNTIME_FUNCTION(Runtime_GetInterceptorInfo) { | 949 RUNTIME_FUNCTION(Runtime_GetInterceptorInfo) { |
| 938 HandleScope scope(isolate); | 950 HandleScope scope(isolate); |
| 939 DCHECK(args.length() == 1); | 951 DCHECK(args.length() == 1); |
| 940 if (!args[0]->IsJSObject()) { | 952 if (!args[0]->IsJSObject()) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 } | 996 } |
| 985 | 997 |
| 986 | 998 |
| 987 RUNTIME_FUNCTION(Runtime_OwnKeys) { | 999 RUNTIME_FUNCTION(Runtime_OwnKeys) { |
| 988 HandleScope scope(isolate); | 1000 HandleScope scope(isolate); |
| 989 DCHECK(args.length() == 1); | 1001 DCHECK(args.length() == 1); |
| 990 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); | 1002 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); |
| 991 | 1003 |
| 992 Handle<FixedArray> contents; | 1004 Handle<FixedArray> contents; |
| 993 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1005 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 994 isolate, contents, JSReceiver::GetKeys(object, JSReceiver::OWN_ONLY, | 1006 isolate, contents, |
| 995 SKIP_SYMBOLS, CONVERT_TO_STRING)); | 1007 JSReceiver::GetKeys(object, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS, |
| 1008 CONVERT_TO_STRING)); |
| 996 return *isolate->factory()->NewJSArrayWithElements(contents); | 1009 return *isolate->factory()->NewJSArrayWithElements(contents); |
| 997 } | 1010 } |
| 998 | 1011 |
| 999 | 1012 |
| 1000 RUNTIME_FUNCTION(Runtime_ToFastProperties) { | 1013 RUNTIME_FUNCTION(Runtime_ToFastProperties) { |
| 1001 HandleScope scope(isolate); | 1014 HandleScope scope(isolate); |
| 1002 DCHECK(args.length() == 1); | 1015 DCHECK(args.length() == 1); |
| 1003 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 1016 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 1004 if (object->IsJSObject() && !object->IsJSGlobalObject()) { | 1017 if (object->IsJSObject() && !object->IsJSGlobalObject()) { |
| 1005 JSObject::MigrateSlowToFast(Handle<JSObject>::cast(object), 0, | 1018 JSObject::MigrateSlowToFast(Handle<JSObject>::cast(object), 0, |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 | 1596 |
| 1584 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { | 1597 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { |
| 1585 HandleScope scope(isolate); | 1598 HandleScope scope(isolate); |
| 1586 DCHECK(args.length() == 2); | 1599 DCHECK(args.length() == 2); |
| 1587 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); | 1600 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); |
| 1588 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); | 1601 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); |
| 1589 return JSReceiver::DefineProperties(isolate, o, properties); | 1602 return JSReceiver::DefineProperties(isolate, o, properties); |
| 1590 } | 1603 } |
| 1591 } // namespace internal | 1604 } // namespace internal |
| 1592 } // namespace v8 | 1605 } // namespace v8 |
| OLD | NEW |