OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 5723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5734 Object* proto = obj->GetPrototype(); | 5734 Object* proto = obj->GetPrototype(); |
5735 while (proto->IsJSObject() && | 5735 while (proto->IsJSObject() && |
5736 JSObject::cast(proto)->map()->is_hidden_prototype()) { | 5736 JSObject::cast(proto)->map()->is_hidden_prototype()) { |
5737 count++; | 5737 count++; |
5738 proto = JSObject::cast(proto)->GetPrototype(); | 5738 proto = JSObject::cast(proto)->GetPrototype(); |
5739 } | 5739 } |
5740 return count; | 5740 return count; |
5741 } | 5741 } |
5742 | 5742 |
5743 | 5743 |
5744 static Handle<FixedArray> FilterPublicSymbols( | |
5745 Isolate* isolate, Handle<FixedArray> names) { | |
5746 int length = names->length(); | |
5747 int symbol_count = 0; | |
5748 for (int i = 0; i < length; i++) { | |
5749 Object* name = names->get(i); | |
5750 if (name->IsSymbol() && !static_cast<Symbol*>(name)->is_private()) { | |
rossberg
2013/12/12 15:37:59
Use Symbol::cast(name) here (and below).
But I ha
arv (Not doing code reviews)
2013/12/16 21:51:21
Done.
| |
5751 symbol_count++; | |
5752 } | |
5753 } | |
5754 | |
5755 Handle<FixedArray> symbols = isolate->factory()->NewFixedArray(symbol_count); | |
5756 | |
5757 if (symbol_count) { | |
5758 int dest_pos = 0; | |
5759 for (int i = 0; i < length; i++) { | |
5760 Object* name = names->get(i); | |
5761 if (name->IsSymbol() && !static_cast<Symbol*>(name)->is_private()) { | |
5762 symbols->set(dest_pos++, name); | |
5763 } | |
5764 } | |
5765 } | |
5766 | |
5767 return symbols; | |
5768 } | |
5769 | |
5770 | |
5744 // Return the names of the local named properties. | 5771 // Return the names of the local named properties. |
5745 // args[0]: object | 5772 // args[0]: object |
5773 // args[1]: int | |
5746 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLocalPropertyNames) { | 5774 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLocalPropertyNames) { |
5747 HandleScope scope(isolate); | 5775 HandleScope scope(isolate); |
5748 ASSERT(args.length() == 2); | 5776 ASSERT(args.length() == 2); |
5749 if (!args[0]->IsJSObject()) { | 5777 if (!args[0]->IsJSObject()) { |
5750 return isolate->heap()->undefined_value(); | 5778 return isolate->heap()->undefined_value(); |
5751 } | 5779 } |
5780 | |
5752 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 5781 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
5753 CONVERT_BOOLEAN_ARG_CHECKED(include_symbols, 1); | 5782 CONVERT_SMI_ARG_CHECKED(key_type, 1); |
5754 PropertyAttributes filter = include_symbols ? NONE : SYMBOLIC; | 5783 PropertyAttributes filter = |
5784 (key_type & Runtime::PROPERTY_KEY_SYMBOL) ? NONE : SYMBOLIC; | |
5755 | 5785 |
5756 // Skip the global proxy as it has no properties and always delegates to the | 5786 // Skip the global proxy as it has no properties and always delegates to the |
5757 // real global object. | 5787 // real global object. |
5758 if (obj->IsJSGlobalProxy()) { | 5788 if (obj->IsJSGlobalProxy()) { |
5759 // Only collect names if access is permitted. | 5789 // Only collect names if access is permitted. |
5760 if (obj->IsAccessCheckNeeded() && | 5790 if (obj->IsAccessCheckNeeded() && |
5761 !isolate->MayNamedAccess(*obj, | 5791 !isolate->MayNamedAccess(*obj, |
5762 isolate->heap()->undefined_value(), | 5792 isolate->heap()->undefined_value(), |
5763 v8::ACCESS_KEYS)) { | 5793 v8::ACCESS_KEYS)) { |
5764 isolate->ReportFailedAccessCheck(*obj, v8::ACCESS_KEYS); | 5794 isolate->ReportFailedAccessCheck(*obj, v8::ACCESS_KEYS); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5821 int dest_pos = 0; | 5851 int dest_pos = 0; |
5822 for (int i = 0; i < total_property_count; i++) { | 5852 for (int i = 0; i < total_property_count; i++) { |
5823 Object* name = old_names->get(i); | 5853 Object* name = old_names->get(i); |
5824 if (name == isolate->heap()->hidden_string()) { | 5854 if (name == isolate->heap()->hidden_string()) { |
5825 continue; | 5855 continue; |
5826 } | 5856 } |
5827 names->set(dest_pos++, name); | 5857 names->set(dest_pos++, name); |
5828 } | 5858 } |
5829 } | 5859 } |
5830 | 5860 |
5861 if ((key_type & Runtime::PROPERTY_KEY_SYMBOL) && | |
rossberg
2013/12/12 15:37:59
How about splitting PropertyAttributes SYMBOLIC fi
arv (Not doing code reviews)
2013/12/12 16:06:16
I considered going down this route to handle strin
| |
5862 !(key_type & Runtime::PROPERTY_KEY_STRING)) { | |
5863 names = FilterPublicSymbols(isolate, names); | |
5864 } | |
5865 | |
5831 return *isolate->factory()->NewJSArrayWithElements(names); | 5866 return *isolate->factory()->NewJSArrayWithElements(names); |
5832 } | 5867 } |
5833 | 5868 |
5834 | 5869 |
5835 // Return the names of the local indexed properties. | 5870 // Return the names of the local indexed properties. |
5836 // args[0]: object | 5871 // args[0]: object |
5837 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLocalElementNames) { | 5872 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLocalElementNames) { |
5838 HandleScope scope(isolate); | 5873 HandleScope scope(isolate); |
5839 ASSERT(args.length() == 1); | 5874 ASSERT(args.length() == 1); |
5840 if (!args[0]->IsJSObject()) { | 5875 if (!args[0]->IsJSObject()) { |
(...skipping 21 matching lines...) Expand all Loading... | |
5862 int result = 0; | 5897 int result = 0; |
5863 if (obj->HasNamedInterceptor()) result |= 2; | 5898 if (obj->HasNamedInterceptor()) result |= 2; |
5864 if (obj->HasIndexedInterceptor()) result |= 1; | 5899 if (obj->HasIndexedInterceptor()) result |= 1; |
5865 | 5900 |
5866 return Smi::FromInt(result); | 5901 return Smi::FromInt(result); |
5867 } | 5902 } |
5868 | 5903 |
5869 | 5904 |
5870 // Return property names from named interceptor. | 5905 // Return property names from named interceptor. |
5871 // args[0]: object | 5906 // args[0]: object |
5907 // args[1]: int | |
5872 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetNamedInterceptorPropertyNames) { | 5908 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetNamedInterceptorPropertyNames) { |
5873 HandleScope scope(isolate); | 5909 HandleScope scope(isolate); |
5874 ASSERT(args.length() == 1); | 5910 ASSERT(args.length() == 1); |
5875 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); | 5911 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); |
5912 CONVERT_SMI_ARG_CHECKED(key_type, 1); | |
5876 | 5913 |
5877 if (obj->HasNamedInterceptor()) { | 5914 if (obj->HasNamedInterceptor()) { |
5878 v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj); | 5915 v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj); |
5879 if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result); | 5916 if (!result.IsEmpty()) { |
5917 if ((key_type & Runtime::PROPERTY_KEY_SYMBOL) && | |
rossberg
2013/12/12 15:37:59
I'm not sure I understand this. If somebody passed
| |
5918 !(key_type & Runtime::PROPERTY_KEY_STRING)) { | |
5919 Handle<FixedArray> res = isolate->factory()->NewFixedArray(result->Lengt h()); | |
rossberg
2013/12/12 15:37:59
Nit: line length
| |
5920 for (int i = 0; i < res->length(); i++) { | |
arv (Not doing code reviews)
2013/12/11 23:51:12
This is ugly. What is the correct way to do this?
rossberg
2013/12/12 15:37:59
You mean the copying? Only if you allow the Filter
| |
5921 res->set(i, *v8::Utils::OpenHandle(*result->Get(i))); | |
5922 } | |
5923 return *isolate->factory()->NewJSArrayWithElements( | |
5924 FilterPublicSymbols(isolate, res)); | |
5925 } | |
5926 return *v8::Utils::OpenHandle(*result); | |
5927 } | |
5880 } | 5928 } |
5881 return isolate->heap()->undefined_value(); | 5929 return isolate->heap()->undefined_value(); |
5882 } | 5930 } |
5883 | 5931 |
5884 | 5932 |
5885 // Return element names from indexed interceptor. | 5933 // Return element names from indexed interceptor. |
5886 // args[0]: object | 5934 // args[0]: object |
5887 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetIndexedInterceptorElementNames) { | 5935 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetIndexedInterceptorElementNames) { |
5888 HandleScope scope(isolate); | 5936 HandleScope scope(isolate); |
5889 ASSERT(args.length() == 1); | 5937 ASSERT(args.length() == 1); |
(...skipping 9003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14893 // Handle last resort GC and make sure to allow future allocations | 14941 // Handle last resort GC and make sure to allow future allocations |
14894 // to grow the heap without causing GCs (if possible). | 14942 // to grow the heap without causing GCs (if possible). |
14895 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14943 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14896 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14944 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14897 "Runtime::PerformGC"); | 14945 "Runtime::PerformGC"); |
14898 } | 14946 } |
14899 } | 14947 } |
14900 | 14948 |
14901 | 14949 |
14902 } } // namespace v8::internal | 14950 } } // namespace v8::internal |
OLD | NEW |