Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1422033002: [Interpreter] Add support for for..in. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update comments. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 3799 matching lines...) Expand 10 before | Expand all | Expand 10 after
3810 }; 3810 };
3811 3811
3812 for (size_t i = 0; i < arraysize(snippets); i++) { 3812 for (size_t i = 0; i < arraysize(snippets); i++) {
3813 Handle<BytecodeArray> bytecode_array = 3813 Handle<BytecodeArray> bytecode_array =
3814 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 3814 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3815 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3815 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3816 } 3816 }
3817 } 3817 }
3818 3818
3819 3819
3820 TEST(ForIn) {
3821 InitializedHandleScope handle_scope;
3822 BytecodeGeneratorHelper helper;
3823 Zone zone;
3824
3825 int simple_flags =
3826 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
3827 int deep_elements_flags =
3828 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
3829
3830 FeedbackVectorSpec feedback_spec(&zone);
3831 feedback_spec.AddStoreICSlot();
3832 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
3833 FeedbackVectorSlot slot3 = feedback_spec.AddStoreICSlot();
3834 FeedbackVectorSlot slot4 = feedback_spec.AddStoreICSlot();
3835 Handle<i::TypeFeedbackVector> vector =
3836 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
3837
3838 ExpectedSnippet<InstanceType> snippets[] = {
3839 {"for (var p in null) {}",
3840 2 * kPointerSize,
3841 1,
3842 2,
3843 {B(LdaUndefined), B(Return)},
3844 0},
3845 {"for (var p in undefined) {}",
3846 2 * kPointerSize,
3847 1,
3848 2,
3849 {B(LdaUndefined), B(Return)},
3850 0},
3851 {"var x = 'potatoes';\n"
3852 "for (var p in x) { return p; }",
3853 5 * kPointerSize,
3854 1,
3855 56,
3856 {
3857 B(LdaConstant), U8(0), //
3858 B(Star), R(1), //
3859 B(Ldar), R(1), //
3860 B(JumpIfUndefined), U8(48), //
3861 B(JumpIfNull), U8(46), //
3862 B(ToObject), //
3863 B(Star), R(3), //
3864 B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(3), U8(1), //
3865 B(ForInPrepare), R(3), //
3866 B(Star), R(4), //
3867 B(LdaUndefined), //
3868 B(TestEqualStrict), R(4), //
3869 B(JumpIfTrue), U8(29), //
3870 B(LdaZero), //
3871 B(Star), R(3), //
3872 B(ForInDone), R(4), //
3873 B(JumpIfTrue), U8(22), //
3874 B(Ldar), R(3), //
3875 B(ForInNext), R(4), //
3876 B(JumpIfUndefined), U8(11), //
3877 B(Star), R(0), //
3878 B(Ldar), R(0), //
3879 B(Star), R(2), //
3880 B(Ldar), R(2), //
3881 B(Return), //
3882 B(Ldar), R(3), //
3883 B(Inc), //
3884 B(Jump), U8(-24), //
3885 B(LdaUndefined), //
3886 B(Return), //
3887 },
3888 1,
3889 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
3890 {"var x = 0;\n"
3891 "for (var p in [1,2,3]) { x += p; }",
3892 5 * kPointerSize,
3893 1,
3894 61,
3895 {
3896 B(LdaZero), //
3897 B(Star), R(1), //
3898 B(LdaConstant), U8(0), //
3899 B(CreateArrayLiteral), U8(0), U8(simple_flags), //
3900 B(JumpIfUndefined), U8(51), //
3901 B(JumpIfNull), U8(49), //
3902 B(ToObject), //
3903 B(Star), R(3), //
3904 B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(3), U8(1), //
3905 B(ForInPrepare), R(3), //
3906 B(Star), R(4), //
3907 B(LdaUndefined), //
3908 B(TestEqualStrict), R(4), //
3909 B(JumpIfTrue), U8(32), //
3910 B(LdaZero), //
3911 B(Star), R(3), //
3912 B(ForInDone), R(4), //
3913 B(JumpIfTrue), U8(25), //
3914 B(Ldar), R(3), //
3915 B(ForInNext), R(4), //
3916 B(JumpIfUndefined), U8(14), //
3917 B(Star), R(0), //
3918 B(Ldar), R(0), //
3919 B(Star), R(2), //
3920 B(Ldar), R(2), //
3921 B(Add), R(1), //
3922 B(Star), R(1), //
3923 B(Ldar), R(3), //
3924 B(Inc), //
3925 B(Jump), U8(-27), //
3926 B(LdaUndefined), //
3927 B(Return), //
3928 },
3929 1,
3930 {InstanceType::FIXED_ARRAY_TYPE}},
3931 {"var x = { 'a': 1, 'b': 2 };\n"
3932 "for (x['a'] in [10, 20, 30]) {\n"
3933 " if (x['a'] == 10) continue;\n"
3934 " if (x['a'] == 20) break;\n"
3935 "}",
3936 4 * kPointerSize,
3937 1,
3938 87,
3939 {
3940 B(LdaConstant), U8(0), //
3941 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
3942 B(Star), R(0), //
3943 B(LdaConstant), U8(1), //
3944 B(CreateArrayLiteral), U8(1), U8(simple_flags), //
3945 B(JumpIfUndefined), U8(73), //
3946 B(JumpIfNull), U8(71), //
3947 B(ToObject), //
3948 B(Star), R(1), //
3949 B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(1), U8(1), //
3950 B(ForInPrepare), R(1), //
3951 B(Star), R(2), //
3952 B(LdaUndefined), //
3953 B(TestEqualStrict), R(2), //
3954 B(JumpIfTrue), U8(54), //
3955 B(LdaZero), //
3956 B(Star), R(1), //
3957 B(ForInDone), R(2), //
3958 B(JumpIfTrue), U8(47), //
3959 B(Ldar), R(1), //
3960 B(ForInNext), R(2), //
3961 B(JumpIfUndefined), U8(36), //
3962 B(Star), R(3), //
3963 B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot4)), //
3964 B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot2)), //
3965 B(Star), R(3), //
3966 B(LdaSmi8), U8(10), //
3967 B(TestEqual), R(3), //
3968 B(JumpIfFalse), U8(4), //
3969 B(Jump), U8(16), //
3970 B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot3)), //
3971 B(Star), R(3), //
3972 B(LdaSmi8), U8(20), //
3973 B(TestEqual), R(3), //
3974 B(JumpIfFalse), U8(4), //
3975 B(Jump), U8(7), //
3976 B(Ldar), R(1), //
3977 B(Inc), //
3978 B(Jump), U8(-49), //
3979 B(LdaUndefined), //
3980 B(Return), //
3981 },
3982 3,
3983 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
3984 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
3985 {"var x = [ 10, 11, 12 ] ;\n"
3986 "for (x[0] in [1,2,3]) { return x[3]; }",
3987 5 * kPointerSize,
3988 1,
3989 70,
3990 {
3991 B(LdaConstant), U8(0), //
3992 B(CreateArrayLiteral), U8(0), U8(simple_flags), //
3993 B(Star), R(0), //
3994 B(LdaConstant), U8(1), //
3995 B(CreateArrayLiteral), U8(1), U8(simple_flags), //
3996 B(JumpIfUndefined), U8(56), //
3997 B(JumpIfNull), U8(54), //
3998 B(ToObject), //
3999 B(Star), R(1), //
4000 B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(1), U8(1), //
4001 B(ForInPrepare), R(1), //
4002 B(Star), R(2), //
4003 B(LdaUndefined), //
4004 B(TestEqualStrict), R(2), //
4005 B(JumpIfTrue), U8(37), //
4006 B(LdaZero), //
4007 B(Star), R(1), //
4008 B(ForInDone), R(2), //
4009 B(JumpIfTrue), U8(30), //
4010 B(Ldar), R(1), //
4011 B(ForInNext), R(2), //
4012 B(JumpIfUndefined), U8(19), //
4013 B(Star), R(3), //
4014 B(LdaZero), //
4015 B(Star), R(4), //
4016 B(Ldar), R(3), //
4017 B(KeyedStoreICSloppy), R(0), R(4), U8(vector->GetIndex(slot3)), //
4018 B(LdaSmi8), U8(3), //
4019 B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot2)), //
4020 B(Return), //
4021 B(Ldar), R(1), //
4022 B(Inc), //
4023 B(Jump), U8(-32), //
4024 B(LdaUndefined), //
4025 B(Return), //
4026 },
4027 2,
4028 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}},
4029 };
4030
4031 for (size_t i = 0; i < arraysize(snippets); i++) {
4032 Handle<BytecodeArray> bytecode_array =
4033 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
4034 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
4035 }
4036 }
4037
4038
3820 TEST(Conditional) { 4039 TEST(Conditional) {
3821 InitializedHandleScope handle_scope; 4040 InitializedHandleScope handle_scope;
3822 BytecodeGeneratorHelper helper; 4041 BytecodeGeneratorHelper helper;
3823 4042
3824 ExpectedSnippet<int> snippets[] = { 4043 ExpectedSnippet<int> snippets[] = {
3825 {"return 1 ? 2 : 3;", 4044 {"return 1 ? 2 : 3;",
3826 0, 4045 0,
3827 1, 4046 1,
3828 12, 4047 12,
3829 { 4048 {
(...skipping 28 matching lines...) Expand all
3858 for (size_t i = 0; i < arraysize(snippets); i++) { 4077 for (size_t i = 0; i < arraysize(snippets); i++) {
3859 Handle<BytecodeArray> bytecode_array = 4078 Handle<BytecodeArray> bytecode_array =
3860 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 4079 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3861 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 4080 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3862 } 4081 }
3863 } 4082 }
3864 4083
3865 } // namespace interpreter 4084 } // namespace interpreter
3866 } // namespace internal 4085 } // namespace internal
3867 } // namespace v8 4086 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698