OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 | 873 |
874 | 874 |
875 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { | 875 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
876 Comment cmnt(masm_, "[ ForInStatement"); | 876 Comment cmnt(masm_, "[ ForInStatement"); |
877 SetStatementPosition(stmt); | 877 SetStatementPosition(stmt); |
878 | 878 |
879 Label loop, exit; | 879 Label loop, exit; |
880 ForIn loop_statement(this, stmt); | 880 ForIn loop_statement(this, stmt); |
881 increment_loop_depth(); | 881 increment_loop_depth(); |
882 | 882 |
| 883 // Load null value as it is used several times below. |
| 884 Register null_value = r5; |
| 885 __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 886 |
883 // Get the object to enumerate over. Both SpiderMonkey and JSC | 887 // Get the object to enumerate over. Both SpiderMonkey and JSC |
884 // ignore null and undefined in contrast to the specification; see | 888 // ignore null and undefined in contrast to the specification; see |
885 // ECMA-262 section 12.6.4. | 889 // ECMA-262 section 12.6.4. |
886 VisitForAccumulatorValue(stmt->enumerable()); | 890 VisitForAccumulatorValue(stmt->enumerable()); |
887 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); | 891 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
888 __ cmp(r0, ip); | 892 __ cmp(r0, ip); |
889 __ b(eq, &exit); | 893 __ b(eq, &exit); |
890 __ LoadRoot(ip, Heap::kNullValueRootIndex); | 894 __ cmp(r0, null_value); |
891 __ cmp(r0, ip); | |
892 __ b(eq, &exit); | 895 __ b(eq, &exit); |
893 | 896 |
894 // Convert the object to a JS object. | 897 // Convert the object to a JS object. |
895 Label convert, done_convert; | 898 Label convert, done_convert; |
896 __ JumpIfSmi(r0, &convert); | 899 __ JumpIfSmi(r0, &convert); |
897 __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); | 900 __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
898 __ b(hs, &done_convert); | 901 __ b(hs, &done_convert); |
899 __ bind(&convert); | 902 __ bind(&convert); |
900 __ push(r0); | 903 __ push(r0); |
901 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS); | 904 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS); |
902 __ bind(&done_convert); | 905 __ bind(&done_convert); |
903 __ push(r0); | 906 __ push(r0); |
904 | 907 |
905 // BUG(867): Check cache validity in generated code. This is a fast | 908 // Check cache validity in generated code. This is a fast case for |
906 // case for the JSObject::IsSimpleEnum cache validity checks. If we | 909 // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
907 // cannot guarantee cache validity, call the runtime system to check | 910 // guarantee cache validity, call the runtime system to check cache |
908 // cache validity or get the property names in a fixed array. | 911 // validity or get the property names in a fixed array. |
| 912 Label next, call_runtime; |
| 913 // Preload a couple of values used in the loop. |
| 914 Register empty_fixed_array_value = r6; |
| 915 __ LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex); |
| 916 Register empty_descriptor_array_value = r7; |
| 917 __ LoadRoot(empty_descriptor_array_value, |
| 918 Heap::kEmptyDescriptorArrayRootIndex); |
| 919 __ mov(r1, r0); |
| 920 __ bind(&next); |
| 921 |
| 922 // Check that there are no elements. Register r1 contains the |
| 923 // current JS object we've reached through the prototype chain. |
| 924 __ ldr(r2, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 925 __ cmp(r2, empty_fixed_array_value); |
| 926 __ b(ne, &call_runtime); |
| 927 |
| 928 // Check that instance descriptors are not empty so that we can |
| 929 // check for an enum cache. Leave the map in r2 for the subsequent |
| 930 // prototype load. |
| 931 __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 932 __ ldr(r3, FieldMemOperand(r2, Map::kInstanceDescriptorsOffset)); |
| 933 __ cmp(r3, empty_descriptor_array_value); |
| 934 __ b(eq, &call_runtime); |
| 935 |
| 936 // Check that there is an enum cache in the non-empty instance |
| 937 // descriptors (r3). This is the case if the next enumeration |
| 938 // index field does not contain a smi. |
| 939 __ ldr(r3, FieldMemOperand(r3, DescriptorArray::kEnumerationIndexOffset)); |
| 940 __ JumpIfSmi(r3, &call_runtime); |
| 941 |
| 942 // For all objects but the receiver, check that the cache is empty. |
| 943 Label check_prototype; |
| 944 __ cmp(r1, r0); |
| 945 __ b(eq, &check_prototype); |
| 946 __ ldr(r3, FieldMemOperand(r3, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 947 __ cmp(r3, empty_fixed_array_value); |
| 948 __ b(ne, &call_runtime); |
| 949 |
| 950 // Load the prototype from the map and loop if non-null. |
| 951 __ bind(&check_prototype); |
| 952 __ ldr(r1, FieldMemOperand(r2, Map::kPrototypeOffset)); |
| 953 __ cmp(r1, null_value); |
| 954 __ b(ne, &next); |
| 955 |
| 956 // The enum cache is valid. Load the map of the object being |
| 957 // iterated over and use the cache for the iteration. |
| 958 Label use_cache; |
| 959 __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 960 __ b(&use_cache); |
909 | 961 |
910 // Get the set of properties to enumerate. | 962 // Get the set of properties to enumerate. |
| 963 __ bind(&call_runtime); |
911 __ push(r0); // Duplicate the enumerable object on the stack. | 964 __ push(r0); // Duplicate the enumerable object on the stack. |
912 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); | 965 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
913 | 966 |
914 // If we got a map from the runtime call, we can do a fast | 967 // If we got a map from the runtime call, we can do a fast |
915 // modification check. Otherwise, we got a fixed array, and we have | 968 // modification check. Otherwise, we got a fixed array, and we have |
916 // to do a slow check. | 969 // to do a slow check. |
917 Label fixed_array; | 970 Label fixed_array; |
918 __ mov(r2, r0); | 971 __ mov(r2, r0); |
919 __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); | 972 __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
920 __ LoadRoot(ip, Heap::kMetaMapRootIndex); | 973 __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
921 __ cmp(r1, ip); | 974 __ cmp(r1, ip); |
922 __ b(ne, &fixed_array); | 975 __ b(ne, &fixed_array); |
923 | 976 |
924 // We got a map in register r0. Get the enumeration cache from it. | 977 // We got a map in register r0. Get the enumeration cache from it. |
| 978 __ bind(&use_cache); |
925 __ ldr(r1, FieldMemOperand(r0, Map::kInstanceDescriptorsOffset)); | 979 __ ldr(r1, FieldMemOperand(r0, Map::kInstanceDescriptorsOffset)); |
926 __ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset)); | 980 __ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset)); |
927 __ ldr(r2, FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset)); | 981 __ ldr(r2, FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
928 | 982 |
929 // Setup the four remaining stack slots. | 983 // Setup the four remaining stack slots. |
930 __ push(r0); // Map. | 984 __ push(r0); // Map. |
931 __ ldr(r1, FieldMemOperand(r2, FixedArray::kLengthOffset)); | 985 __ ldr(r1, FieldMemOperand(r2, FixedArray::kLengthOffset)); |
932 __ mov(r0, Operand(Smi::FromInt(0))); | 986 __ mov(r0, Operand(Smi::FromInt(0))); |
933 // Push enumeration cache, enumeration cache length (as smi) and zero. | 987 // Push enumeration cache, enumeration cache length (as smi) and zero. |
934 __ Push(r2, r1, r0); | 988 __ Push(r2, r1, r0); |
(...skipping 3114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4049 __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value. | 4103 __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value. |
4050 __ add(pc, r1, Operand(masm_->CodeObject())); | 4104 __ add(pc, r1, Operand(masm_->CodeObject())); |
4051 } | 4105 } |
4052 | 4106 |
4053 | 4107 |
4054 #undef __ | 4108 #undef __ |
4055 | 4109 |
4056 } } // namespace v8::internal | 4110 } } // namespace v8::internal |
4057 | 4111 |
4058 #endif // V8_TARGET_ARCH_ARM | 4112 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |