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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 MaybeHandle<Object> Runtime::GetPrototype(Isolate* isolate, | 178 MaybeHandle<Object> Runtime::GetPrototype(Isolate* isolate, |
179 Handle<Object> obj) { | 179 Handle<Object> obj) { |
180 // We don't expect access checks to be needed on JSProxy objects. | 180 // We don't expect access checks to be needed on JSProxy objects. |
181 DCHECK(!obj->IsAccessCheckNeeded() || obj->IsJSObject()); | 181 DCHECK(!obj->IsAccessCheckNeeded() || obj->IsJSObject()); |
182 PrototypeIterator iter(isolate, obj, PrototypeIterator::START_AT_RECEIVER); | 182 PrototypeIterator iter(isolate, obj, PrototypeIterator::START_AT_RECEIVER); |
183 do { | 183 do { |
184 if (PrototypeIterator::GetCurrent(iter)->IsAccessCheckNeeded() && | 184 if (PrototypeIterator::GetCurrent(iter)->IsAccessCheckNeeded() && |
185 !isolate->MayAccess( | 185 !isolate->MayAccess(PrototypeIterator::GetCurrent<JSObject>(iter))) { |
186 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)))) { | |
187 return isolate->factory()->null_value(); | 186 return isolate->factory()->null_value(); |
188 } | 187 } |
189 iter.AdvanceIgnoringProxies(); | 188 iter.AdvanceIgnoringProxies(); |
190 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { | 189 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { |
191 return PrototypeIterator::GetCurrent(iter); | 190 return PrototypeIterator::GetCurrent(iter); |
192 } | 191 } |
193 } while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)); | 192 } while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)); |
194 return PrototypeIterator::GetCurrent(iter); | 193 return PrototypeIterator::GetCurrent(iter); |
195 } | 194 } |
196 | 195 |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 Handle<JSObject> object, | 686 Handle<JSObject> object, |
688 Handle<Name> key) { | 687 Handle<Name> key) { |
689 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key); | 688 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key); |
690 if (!maybe.IsJust()) return isolate->heap()->exception(); | 689 if (!maybe.IsJust()) return isolate->heap()->exception(); |
691 if (maybe.FromJust()) return isolate->heap()->true_value(); | 690 if (maybe.FromJust()) return isolate->heap()->true_value(); |
692 // Handle hidden prototypes. If there's a hidden prototype above this thing | 691 // Handle hidden prototypes. If there's a hidden prototype above this thing |
693 // then we have to check it for properties, because they are supposed to | 692 // then we have to check it for properties, because they are supposed to |
694 // look like they are on this object. | 693 // look like they are on this object. |
695 PrototypeIterator iter(isolate, object); | 694 PrototypeIterator iter(isolate, object); |
696 if (!iter.IsAtEnd() && | 695 if (!iter.IsAtEnd() && |
697 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)) | 696 PrototypeIterator::GetCurrent<JSObject>(iter) |
698 ->map() | 697 ->map() |
699 ->is_hidden_prototype()) { | 698 ->is_hidden_prototype()) { |
700 // TODO(verwaest): The recursion is not necessary for keys that are array | 699 // TODO(verwaest): The recursion is not necessary for keys that are array |
701 // indices. Removing this. | 700 // indices. Removing this. |
702 return HasOwnPropertyImplementation( | 701 return HasOwnPropertyImplementation( |
703 isolate, Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), | 702 isolate, PrototypeIterator::GetCurrent<JSObject>(iter), key); |
704 key); | |
705 } | 703 } |
706 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); | 704 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); |
707 return isolate->heap()->false_value(); | 705 return isolate->heap()->false_value(); |
708 } | 706 } |
709 | 707 |
710 | 708 |
711 RUNTIME_FUNCTION(Runtime_HasOwnProperty) { | 709 RUNTIME_FUNCTION(Runtime_HasOwnProperty) { |
712 HandleScope scope(isolate); | 710 HandleScope scope(isolate); |
713 DCHECK(args.length() == 2); | 711 DCHECK(args.length() == 2); |
714 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0) | 712 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0) |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 } | 830 } |
833 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 831 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
834 CONVERT_SMI_ARG_CHECKED(filter_value, 1); | 832 CONVERT_SMI_ARG_CHECKED(filter_value, 1); |
835 PropertyAttributes filter = static_cast<PropertyAttributes>(filter_value); | 833 PropertyAttributes filter = static_cast<PropertyAttributes>(filter_value); |
836 | 834 |
837 // Find the number of own properties for each of the objects. | 835 // Find the number of own properties for each of the objects. |
838 int total_property_count = 0; | 836 int total_property_count = 0; |
839 for (PrototypeIterator iter(isolate, object, | 837 for (PrototypeIterator iter(isolate, object, |
840 PrototypeIterator::START_AT_RECEIVER); | 838 PrototypeIterator::START_AT_RECEIVER); |
841 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) { | 839 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) { |
842 Handle<JSObject> jsproto = | 840 Handle<JSObject> jsproto = PrototypeIterator::GetCurrent<JSObject>(iter); |
843 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)); | |
844 total_property_count += jsproto->NumberOfOwnProperties(filter); | 841 total_property_count += jsproto->NumberOfOwnProperties(filter); |
845 } | 842 } |
846 | 843 |
847 // Allocate an array with storage for all the property names. | 844 // Allocate an array with storage for all the property names. |
848 Handle<FixedArray> names = | 845 Handle<FixedArray> names = |
849 isolate->factory()->NewFixedArray(total_property_count); | 846 isolate->factory()->NewFixedArray(total_property_count); |
850 | 847 |
851 // Get the property names. | 848 // Get the property names. |
852 int next_copy_index = 0; | 849 int next_copy_index = 0; |
853 int hidden_strings = 0; | 850 int hidden_strings = 0; |
854 Handle<Object> hidden_string = isolate->factory()->hidden_string(); | 851 Handle<Object> hidden_string = isolate->factory()->hidden_string(); |
855 for (PrototypeIterator iter(isolate, object, | 852 for (PrototypeIterator iter(isolate, object, |
856 PrototypeIterator::START_AT_RECEIVER); | 853 PrototypeIterator::START_AT_RECEIVER); |
857 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) { | 854 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) { |
858 Handle<JSObject> jsproto = | 855 Handle<JSObject> jsproto = PrototypeIterator::GetCurrent<JSObject>(iter); |
859 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)); | |
860 int own = jsproto->GetOwnPropertyNames(*names, next_copy_index, filter); | 856 int own = jsproto->GetOwnPropertyNames(*names, next_copy_index, filter); |
861 // Names from hidden prototypes may already have been added | 857 // Names from hidden prototypes may already have been added |
862 // for inherited function template instances. Count the duplicates | 858 // for inherited function template instances. Count the duplicates |
863 // and stub them out; the final copy pass at the end ignores holes. | 859 // and stub them out; the final copy pass at the end ignores holes. |
864 for (int j = next_copy_index; j < next_copy_index + own; j++) { | 860 for (int j = next_copy_index; j < next_copy_index + own; j++) { |
865 Object* name_from_hidden_proto = names->get(j); | 861 Object* name_from_hidden_proto = names->get(j); |
866 if (isolate->IsInternallyUsedPropertyName(name_from_hidden_proto)) { | 862 if (isolate->IsInternallyUsedPropertyName(name_from_hidden_proto)) { |
867 hidden_strings++; | 863 hidden_strings++; |
868 } else { | 864 } else { |
869 for (int k = 0; k < next_copy_index; k++) { | 865 for (int k = 0; k < next_copy_index; k++) { |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 RUNTIME_FUNCTION(Runtime_CreateIterResultObject) { | 1559 RUNTIME_FUNCTION(Runtime_CreateIterResultObject) { |
1564 HandleScope scope(isolate); | 1560 HandleScope scope(isolate); |
1565 DCHECK_EQ(2, args.length()); | 1561 DCHECK_EQ(2, args.length()); |
1566 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); | 1562 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); |
1567 CONVERT_ARG_HANDLE_CHECKED(Object, done, 1); | 1563 CONVERT_ARG_HANDLE_CHECKED(Object, done, 1); |
1568 return *isolate->factory()->NewJSIteratorResult(value, done); | 1564 return *isolate->factory()->NewJSIteratorResult(value, done); |
1569 } | 1565 } |
1570 | 1566 |
1571 } // namespace internal | 1567 } // namespace internal |
1572 } // namespace v8 | 1568 } // namespace v8 |
OLD | NEW |