| OLD | NEW | 
|---|
| 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  Loading... | 
| 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        52, | 
|  | 3856        { | 
|  | 3857            B(LdaConstant), U8(0),                                             // | 
|  | 3858            B(Star), R(1),                                                     // | 
|  | 3859            B(Ldar), R(1),                                                     // | 
|  | 3860            B(JumpIfUndefined), U8(44),                                        // | 
|  | 3861            B(JumpIfNull), U8(42),                                             // | 
|  | 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(JumpIfUndefined), U8(30),                                        // | 
|  | 3867            B(Star), R(4),                                                     // | 
|  | 3868            B(LdaZero),                                                        // | 
|  | 3869            B(Star), R(3),                                                     // | 
|  | 3870            B(ForInDone), R(4),                                                // | 
|  | 3871            B(JumpIfTrue), U8(21),                                             // | 
|  | 3872            B(ForInNext), R(4), R(3),                                          // | 
|  | 3873            B(JumpIfUndefined), U8(11),                                        // | 
|  | 3874            B(Star), R(0),                                                     // | 
|  | 3875            B(Ldar), R(0),                                                     // | 
|  | 3876            B(Star), R(2),                                                     // | 
|  | 3877            B(Ldar), R(2),                                                     // | 
|  | 3878            B(Return),                                                         // | 
|  | 3879            B(Ldar), R(3),                                                     // | 
|  | 3880            B(Inc),                                                            // | 
|  | 3881            B(Jump), U8(-23),                                                  // | 
|  | 3882            B(LdaUndefined),                                                   // | 
|  | 3883            B(Return),                                                         // | 
|  | 3884        }, | 
|  | 3885        1, | 
|  | 3886        {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 
|  | 3887       {"var x = 0;\n" | 
|  | 3888        "for (var p in [1,2,3]) { x += p; }", | 
|  | 3889        5 * kPointerSize, | 
|  | 3890        1, | 
|  | 3891        57, | 
|  | 3892        { | 
|  | 3893            B(LdaZero),                                                        // | 
|  | 3894            B(Star), R(1),                                                     // | 
|  | 3895            B(LdaConstant), U8(0),                                             // | 
|  | 3896            B(CreateArrayLiteral), U8(0), U8(simple_flags),                    // | 
|  | 3897            B(JumpIfUndefined), U8(47),                                        // | 
|  | 3898            B(JumpIfNull), U8(45),                                             // | 
|  | 3899            B(ToObject),                                                       // | 
|  | 3900            B(Star), R(3),                                                     // | 
|  | 3901            B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(3), U8(1),  // | 
|  | 3902            B(ForInPrepare), R(3),                                             // | 
|  | 3903            B(JumpIfUndefined), U8(33),                                        // | 
|  | 3904            B(Star), R(4),                                                     // | 
|  | 3905            B(LdaZero),                                                        // | 
|  | 3906            B(Star), R(3),                                                     // | 
|  | 3907            B(ForInDone), R(4),                                                // | 
|  | 3908            B(JumpIfTrue), U8(24),                                             // | 
|  | 3909            B(ForInNext), R(4), R(3),                                          // | 
|  | 3910            B(JumpIfUndefined), U8(14),                                        // | 
|  | 3911            B(Star), R(0),                                                     // | 
|  | 3912            B(Ldar), R(0),                                                     // | 
|  | 3913            B(Star), R(2),                                                     // | 
|  | 3914            B(Ldar), R(2),                                                     // | 
|  | 3915            B(Add), R(1),                                                      // | 
|  | 3916            B(Star), R(1),                                                     // | 
|  | 3917            B(Ldar), R(3),                                                     // | 
|  | 3918            B(Inc),                                                            // | 
|  | 3919            B(Jump), U8(-26),                                                  // | 
|  | 3920            B(LdaUndefined),                                                   // | 
|  | 3921            B(Return),                                                         // | 
|  | 3922        }, | 
|  | 3923        1, | 
|  | 3924        {InstanceType::FIXED_ARRAY_TYPE}}, | 
|  | 3925       {"var x = { 'a': 1, 'b': 2 };\n" | 
|  | 3926        "for (x['a'] in [10, 20, 30]) {\n" | 
|  | 3927        "  if (x['a'] == 10) continue;\n" | 
|  | 3928        "  if (x['a'] == 20) break;\n" | 
|  | 3929        "}", | 
|  | 3930        4 * kPointerSize, | 
|  | 3931        1, | 
|  | 3932        83, | 
|  | 3933        { | 
|  | 3934            B(LdaConstant), U8(0),                                             // | 
|  | 3935            B(CreateObjectLiteral), U8(0), U8(deep_elements_flags),            // | 
|  | 3936            B(Star), R(0),                                                     // | 
|  | 3937            B(LdaConstant), U8(1),                                             // | 
|  | 3938            B(CreateArrayLiteral), U8(1), U8(simple_flags),                    // | 
|  | 3939            B(JumpIfUndefined), U8(69),                                        // | 
|  | 3940            B(JumpIfNull), U8(67),                                             // | 
|  | 3941            B(ToObject),                                                       // | 
|  | 3942            B(Star), R(1),                                                     // | 
|  | 3943            B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(1), U8(1),  // | 
|  | 3944            B(ForInPrepare), R(1),                                             // | 
|  | 3945            B(JumpIfUndefined), U8(55),                                        // | 
|  | 3946            B(Star), R(2),                                                     // | 
|  | 3947            B(LdaZero),                                                        // | 
|  | 3948            B(Star), R(1),                                                     // | 
|  | 3949            B(ForInDone), R(2),                                                // | 
|  | 3950            B(JumpIfTrue), U8(46),                                             // | 
|  | 3951            B(ForInNext), R(2), R(1),                                          // | 
|  | 3952            B(JumpIfUndefined), U8(36),                                        // | 
|  | 3953            B(Star), R(3),                                                     // | 
|  | 3954            B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot4)),        // | 
|  | 3955            B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot2)),         // | 
|  | 3956            B(Star), R(3),                                                     // | 
|  | 3957            B(LdaSmi8), U8(10),                                                // | 
|  | 3958            B(TestEqual), R(3),                                                // | 
|  | 3959            B(JumpIfFalse), U8(4),                                             // | 
|  | 3960            B(Jump), U8(16),                                                   // | 
|  | 3961            B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot3)),         // | 
|  | 3962            B(Star), R(3),                                                     // | 
|  | 3963            B(LdaSmi8), U8(20),                                                // | 
|  | 3964            B(TestEqual), R(3),                                                // | 
|  | 3965            B(JumpIfFalse), U8(4),                                             // | 
|  | 3966            B(Jump), U8(7),                                                    // | 
|  | 3967            B(Ldar), R(1),                                                     // | 
|  | 3968            B(Inc),                                                            // | 
|  | 3969            B(Jump), U8(-48),                                                  // | 
|  | 3970            B(LdaUndefined),                                                   // | 
|  | 3971            B(Return),                                                         // | 
|  | 3972        }, | 
|  | 3973        3, | 
|  | 3974        {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, | 
|  | 3975         InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 
|  | 3976       {"var x = [ 10, 11, 12 ] ;\n" | 
|  | 3977        "for (x[0] in [1,2,3]) { return x[3]; }", | 
|  | 3978        5 * kPointerSize, | 
|  | 3979        1, | 
|  | 3980        66, | 
|  | 3981        { | 
|  | 3982            B(LdaConstant), U8(0),                                             // | 
|  | 3983            B(CreateArrayLiteral), U8(0), U8(simple_flags),                    // | 
|  | 3984            B(Star), R(0),                                                     // | 
|  | 3985            B(LdaConstant), U8(1),                                             // | 
|  | 3986            B(CreateArrayLiteral), U8(1), U8(simple_flags),                    // | 
|  | 3987            B(JumpIfUndefined), U8(52),                                        // | 
|  | 3988            B(JumpIfNull), U8(50),                                             // | 
|  | 3989            B(ToObject),                                                       // | 
|  | 3990            B(Star), R(1),                                                     // | 
|  | 3991            B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(1), U8(1),  // | 
|  | 3992            B(ForInPrepare), R(1),                                             // | 
|  | 3993            B(JumpIfUndefined), U8(38),                                        // | 
|  | 3994            B(Star), R(2),                                                     // | 
|  | 3995            B(LdaZero),                                                        // | 
|  | 3996            B(Star), R(1),                                                     // | 
|  | 3997            B(ForInDone), R(2),                                                // | 
|  | 3998            B(JumpIfTrue), U8(29),                                             // | 
|  | 3999            B(ForInNext), R(2), R(1),                                          // | 
|  | 4000            B(JumpIfUndefined), U8(19),                                        // | 
|  | 4001            B(Star), R(3),                                                     // | 
|  | 4002            B(LdaZero),                                                        // | 
|  | 4003            B(Star), R(4),                                                     // | 
|  | 4004            B(Ldar), R(3),                                                     // | 
|  | 4005            B(KeyedStoreICSloppy), R(0), R(4), U8(vector->GetIndex(slot3)),    // | 
|  | 4006            B(LdaSmi8), U8(3),                                                 // | 
|  | 4007            B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot2)),           // | 
|  | 4008            B(Return),                                                         // | 
|  | 4009            B(Ldar), R(1),                                                     // | 
|  | 4010            B(Inc),                                                            // | 
|  | 4011            B(Jump), U8(-31),                                                  // | 
|  | 4012            B(LdaUndefined),                                                   // | 
|  | 4013            B(Return),                                                         // | 
|  | 4014        }, | 
|  | 4015        2, | 
|  | 4016        {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}}, | 
|  | 4017   }; | 
|  | 4018 | 
|  | 4019   for (size_t i = 0; i < arraysize(snippets); i++) { | 
|  | 4020     Handle<BytecodeArray> bytecode_array = | 
|  | 4021         helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 
|  | 4022     CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 
|  | 4023   } | 
|  | 4024 } | 
|  | 4025 | 
|  | 4026 | 
| 3820 TEST(Conditional) { | 4027 TEST(Conditional) { | 
| 3821   InitializedHandleScope handle_scope; | 4028   InitializedHandleScope handle_scope; | 
| 3822   BytecodeGeneratorHelper helper; | 4029   BytecodeGeneratorHelper helper; | 
| 3823 | 4030 | 
| 3824   ExpectedSnippet<int> snippets[] = { | 4031   ExpectedSnippet<int> snippets[] = { | 
| 3825       {"return 1 ? 2 : 3;", | 4032       {"return 1 ? 2 : 3;", | 
| 3826        0, | 4033        0, | 
| 3827        1, | 4034        1, | 
| 3828        12, | 4035        12, | 
| 3829        { | 4036        { | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 3858   for (size_t i = 0; i < arraysize(snippets); i++) { | 4065   for (size_t i = 0; i < arraysize(snippets); i++) { | 
| 3859     Handle<BytecodeArray> bytecode_array = | 4066     Handle<BytecodeArray> bytecode_array = | 
| 3860         helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4067         helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 
| 3861     CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4068     CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 
| 3862   } | 4069   } | 
| 3863 } | 4070 } | 
| 3864 | 4071 | 
| 3865 }  // namespace interpreter | 4072 }  // namespace interpreter | 
| 3866 }  // namespace internal | 4073 }  // namespace internal | 
| 3867 }  // namespace v8 | 4074 }  // namespace v8 | 
| OLD | NEW | 
|---|