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

Unified 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: Fixes for 32-bit. Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
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 f36a9e9cda75468a4ac110dd13dcf1f1086f09f3..ac00c95a02d363f4a3276f6ca23738b988b0ff34 100644
--- a/test/cctest/interpreter/test-bytecode-generator.cc
+++ b/test/cctest/interpreter/test-bytecode-generator.cc
@@ -3493,6 +3493,184 @@ 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 = 0;\n"
+ "for (var p in [1,2,3]) { x += p; }",
+ 6 * kPointerSize,
+ 1,
+ 58,
+ {
+ B(LdaZero), //
+ B(Star), R(1), //
+ B(LdaConstant), U8(0), //
+ B(CreateArrayLiteral), U8(0), U8(simple_flags), //
+ B(ForInPrepare), //
+ B(Star), R(3), //
+ B(LdaUndefined), //
+ B(TestEqualStrict), R(3), //
+ B(JumpIfTrue), U8(42), //
+ B(LdaZero), //
+ B(Star), R(4), //
+ B(ForInDone), R(3), //
+ B(JumpIfTrue), U8(35), //
+ B(Ldar), R(4), //
+ B(ForInNext), R(3), //
+ B(Star), R(5), //
+ B(LdaUndefined), //
+ B(TestEqualStrict), R(5), //
+ B(JumpIfTrue), U8(16), //
+ B(Ldar), R(5), //
+ 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(LdaSmi8), U8(1), //
+ B(Add), R(4), //
+ B(Star), R(4), //
+ B(Jump), U8(-35), //
+ 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"
+ "}",
+ 5 * kPointerSize,
+ 1,
+ 84,
+ {
+ 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(ForInPrepare), //
+ B(Star), R(1), //
+ B(LdaUndefined), //
+ B(TestEqualStrict), R(1), //
+ B(JumpIfTrue), U8(64), //
+ B(LdaZero), //
+ B(Star), R(2), //
+ B(ForInDone), R(1), //
+ B(JumpIfTrue), U8(57), //
+ B(Ldar), R(2), //
+ B(ForInNext), R(1), //
+ B(Star), R(3), //
+ B(LdaUndefined), //
+ B(TestEqualStrict), R(3), //
+ B(JumpIfTrue), U8(38), //
+ B(Ldar), R(3), //
+ B(Star), R(4), //
+ B(StoreICSloppy), R(0), U8(2), U8(vector->GetIndex(slot4)), //
+ B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot2)), //
+ B(Star), R(4), //
+ B(LdaSmi8), U8(10), //
+ B(TestEqual), R(4), //
+ B(JumpIfFalse), U8(4), //
+ B(Jump), U8(16), //
+ B(LoadICSloppy), R(0), U8(2), U8(vector->GetIndex(slot3)), //
+ B(Star), R(4), //
+ B(LdaSmi8), U8(20), //
+ B(TestEqual), R(4), //
+ B(JumpIfFalse), U8(4), //
+ B(Jump), U8(10), //
+ B(LdaSmi8), U8(1), //
+ B(Add), R(2), //
+ B(Star), R(2), //
+ B(Jump), U8(-57), //
+ 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]; }",
+ 6 * kPointerSize,
+ 1,
+ 67,
+ {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(ForInPrepare), //
+ B(Star), R(1), //
+ B(LdaUndefined), //
+ B(TestEqualStrict), R(1), //
+ B(JumpIfTrue), U8(47), //
+ B(LdaZero), //
+ B(Star), R(2), //
+ B(ForInDone), R(1), //
+ B(JumpIfTrue), U8(40), //
+ B(Ldar), R(2), //
+ B(ForInNext), R(1), //
+ B(Star), R(3), //
+ B(LdaUndefined), //
+ B(TestEqualStrict), R(3), //
+ B(JumpIfTrue), U8(21), //
+ B(Ldar), R(3), //
+ B(Star), R(4), //
+ B(LdaZero), //
+ B(Star), R(5), //
+ B(Ldar), R(4), //
+ B(KeyedStoreICSloppy), R(0), R(5), U8(vector->GetIndex(slot3)), //
+ B(LdaSmi8), U8(3), //
+ B(KeyedLoadICSloppy), R(0), U8(vector->GetIndex(slot2)), //
+ B(Return), //
+ B(LdaSmi8), U8(1), //
+ B(Add), R(2), //
+ B(Star), R(2), //
+ B(Jump), U8(-40), //
+ 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);
+ }
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698