| Index: test/cctest/interpreter/test-bytecode-generator.cc
|
| diff --git a/test/cctest/interpreter/test-bytecode-generator.cc b/test/cctest/interpreter/test-bytecode-generator.cc
|
| index 8325b5b7dba056a3f01cf6ffca76a2f6cee6756d..0cfea84575c2e3d2487804376c15ec976f519a88 100644
|
| --- a/test/cctest/interpreter/test-bytecode-generator.cc
|
| +++ b/test/cctest/interpreter/test-bytecode-generator.cc
|
| @@ -3817,6 +3817,225 @@ TEST(IllegalRedeclaration) {
|
| }
|
|
|
|
|
| +TEST(ForIn) {
|
| + InitializedHandleScope handle_scope;
|
| + BytecodeGeneratorHelper helper;
|
| + Zone zone;
|
| +
|
| + int simple_flags =
|
| + ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements;
|
| + int deep_elements_flags =
|
| + ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
|
| +
|
| + FeedbackVectorSpec feedback_spec(&zone);
|
| + feedback_spec.AddStoreICSlot();
|
| + FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
|
| + FeedbackVectorSlot slot3 = feedback_spec.AddStoreICSlot();
|
| + FeedbackVectorSlot slot4 = feedback_spec.AddStoreICSlot();
|
| + Handle<i::TypeFeedbackVector> vector =
|
| + i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
|
| +
|
| + ExpectedSnippet<InstanceType> snippets[] = {
|
| + {"for (var p in null) {}",
|
| + 2 * kPointerSize,
|
| + 1,
|
| + 2,
|
| + {B(LdaUndefined), B(Return)},
|
| + 0},
|
| + {"for (var p in undefined) {}",
|
| + 2 * kPointerSize,
|
| + 1,
|
| + 2,
|
| + {B(LdaUndefined), B(Return)},
|
| + 0},
|
| + {"var x = 'potatoes';\n"
|
| + "for (var p in x) { return p; }",
|
| + 5 * kPointerSize,
|
| + 1,
|
| + 56,
|
| + {
|
| + B(LdaConstant), U8(0), //
|
| + B(Star), R(1), //
|
| + B(Ldar), R(1), //
|
| + B(JumpIfUndefined), U8(48), //
|
| + B(JumpIfNull), U8(46), //
|
| + B(ToObject), //
|
| + B(Star), R(3), //
|
| + B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(3), U8(1), //
|
| + B(ForInPrepare), R(3), //
|
| + B(Star), R(4), //
|
| + B(LdaUndefined), //
|
| + B(TestEqualStrict), R(4), //
|
| + B(JumpIfTrue), U8(29), //
|
| + B(LdaZero), //
|
| + B(Star), R(3), //
|
| + B(ForInDone), R(4), //
|
| + B(JumpIfTrue), U8(22), //
|
| + B(Ldar), R(3), //
|
| + B(ForInNext), R(4), //
|
| + B(JumpIfUndefined), U8(11), //
|
| + B(Star), R(0), //
|
| + B(Ldar), R(0), //
|
| + B(Star), R(2), //
|
| + B(Ldar), R(2), //
|
| + B(Return), //
|
| + B(Ldar), R(3), //
|
| + B(Inc), //
|
| + B(Jump), U8(-24), //
|
| + B(LdaUndefined), //
|
| + B(Return), //
|
| + },
|
| + 1,
|
| + {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
| + {"var x = 0;\n"
|
| + "for (var p in [1,2,3]) { x += p; }",
|
| + 5 * kPointerSize,
|
| + 1,
|
| + 61,
|
| + {
|
| + B(LdaZero), //
|
| + B(Star), R(1), //
|
| + B(LdaConstant), U8(0), //
|
| + B(CreateArrayLiteral), U8(0), U8(simple_flags), //
|
| + B(JumpIfUndefined), U8(51), //
|
| + B(JumpIfNull), U8(49), //
|
| + B(ToObject), //
|
| + B(Star), R(3), //
|
| + B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(3), U8(1), //
|
| + B(ForInPrepare), R(3), //
|
| + B(Star), R(4), //
|
| + B(LdaUndefined), //
|
| + B(TestEqualStrict), R(4), //
|
| + B(JumpIfTrue), U8(32), //
|
| + B(LdaZero), //
|
| + B(Star), R(3), //
|
| + B(ForInDone), R(4), //
|
| + B(JumpIfTrue), U8(25), //
|
| + B(Ldar), R(3), //
|
| + B(ForInNext), R(4), //
|
| + B(JumpIfUndefined), U8(14), //
|
| + B(Star), R(0), //
|
| + B(Ldar), R(0), //
|
| + B(Star), R(2), //
|
| + B(Ldar), R(2), //
|
| + B(Add), R(1), //
|
| + B(Star), R(1), //
|
| + B(Ldar), R(3), //
|
| + B(Inc), //
|
| + B(Jump), U8(-27), //
|
| + B(LdaUndefined), //
|
| + B(Return), //
|
| + },
|
| + 1,
|
| + {InstanceType::FIXED_ARRAY_TYPE}},
|
| + {"var x = { 'a': 1, 'b': 2 };\n"
|
| + "for (x['a'] in [10, 20, 30]) {\n"
|
| + " if (x['a'] == 10) continue;\n"
|
| + " if (x['a'] == 20) break;\n"
|
| + "}",
|
| + 4 * kPointerSize,
|
| + 1,
|
| + 87,
|
| + {
|
| + B(LdaConstant), U8(0), //
|
| + B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
|
| + B(Star), R(0), //
|
| + B(LdaConstant), U8(1), //
|
| + B(CreateArrayLiteral), U8(1), U8(simple_flags), //
|
| + B(JumpIfUndefined), U8(73), //
|
| + B(JumpIfNull), U8(71), //
|
| + B(ToObject), //
|
| + B(Star), R(1), //
|
| + B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(1), U8(1), //
|
| + B(ForInPrepare), R(1), //
|
| + B(Star), R(2), //
|
| + B(LdaUndefined), //
|
| + B(TestEqualStrict), R(2), //
|
| + B(JumpIfTrue), U8(54), //
|
| + B(LdaZero), //
|
| + B(Star), R(1), //
|
| + B(ForInDone), R(2), //
|
| + B(JumpIfTrue), U8(47), //
|
| + B(Ldar), R(1), //
|
| + B(ForInNext), R(2), //
|
| + B(JumpIfUndefined), U8(36), //
|
| + B(Star), R(3), //
|
| + B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot4)), //
|
| + B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot2)), //
|
| + B(Star), R(3), //
|
| + B(LdaSmi8), U8(10), //
|
| + B(TestEqual), R(3), //
|
| + B(JumpIfFalse), U8(4), //
|
| + B(Jump), U8(16), //
|
| + B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot3)), //
|
| + B(Star), R(3), //
|
| + B(LdaSmi8), U8(20), //
|
| + B(TestEqual), R(3), //
|
| + B(JumpIfFalse), U8(4), //
|
| + B(Jump), U8(7), //
|
| + B(Ldar), R(1), //
|
| + B(Inc), //
|
| + B(Jump), U8(-49), //
|
| + B(LdaUndefined), //
|
| + B(Return), //
|
| + },
|
| + 3,
|
| + {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE,
|
| + InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
|
| + {"var x = [ 10, 11, 12 ] ;\n"
|
| + "for (x[0] in [1,2,3]) { return x[3]; }",
|
| + 5 * kPointerSize,
|
| + 1,
|
| + 70,
|
| + {
|
| + B(LdaConstant), U8(0), //
|
| + B(CreateArrayLiteral), U8(0), U8(simple_flags), //
|
| + B(Star), R(0), //
|
| + B(LdaConstant), U8(1), //
|
| + B(CreateArrayLiteral), U8(1), U8(simple_flags), //
|
| + B(JumpIfUndefined), U8(56), //
|
| + B(JumpIfNull), U8(54), //
|
| + B(ToObject), //
|
| + B(Star), R(1), //
|
| + B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(1), U8(1), //
|
| + B(ForInPrepare), R(1), //
|
| + B(Star), R(2), //
|
| + B(LdaUndefined), //
|
| + B(TestEqualStrict), R(2), //
|
| + B(JumpIfTrue), U8(37), //
|
| + B(LdaZero), //
|
| + B(Star), R(1), //
|
| + B(ForInDone), R(2), //
|
| + B(JumpIfTrue), U8(30), //
|
| + B(Ldar), R(1), //
|
| + B(ForInNext), R(2), //
|
| + B(JumpIfUndefined), U8(19), //
|
| + B(Star), R(3), //
|
| + B(LdaZero), //
|
| + B(Star), R(4), //
|
| + B(Ldar), R(3), //
|
| + B(KeyedStoreICSloppy), R(0), R(4), U8(vector->GetIndex(slot3)), //
|
| + B(LdaSmi8), U8(3), //
|
| + B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot2)), //
|
| + B(Return), //
|
| + B(Ldar), R(1), //
|
| + B(Inc), //
|
| + B(Jump), U8(-32), //
|
| + B(LdaUndefined), //
|
| + B(Return), //
|
| + },
|
| + 2,
|
| + {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}},
|
| + };
|
| +
|
| + for (size_t i = 0; i < arraysize(snippets); i++) {
|
| + Handle<BytecodeArray> bytecode_array =
|
| + helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
|
| + CheckBytecodeArrayEqual(snippets[i], bytecode_array);
|
| + }
|
| +}
|
| +
|
| +
|
| TEST(Conditional) {
|
| InitializedHandleScope handle_scope;
|
| BytecodeGeneratorHelper helper;
|
|
|