Index: test/cctest/compiler/test-run-bytecode-graph-builder.cc |
diff --git a/test/cctest/compiler/test-run-bytecode-graph-builder.cc b/test/cctest/compiler/test-run-bytecode-graph-builder.cc |
index 8c0922933c0b84b0077766316160e02536082117..98e36819436f2cc115efcffe7e626904ba8ea3b5 100644 |
--- a/test/cctest/compiler/test-run-bytecode-graph-builder.cc |
+++ b/test/cctest/compiler/test-run-bytecode-graph-builder.cc |
@@ -1880,6 +1880,79 @@ TEST(BytecodeGraphBuilderFor) { |
} |
} |
+ |
+TEST(BytecodeGraphBuilderForIn) { |
+ HandleAndZoneScope scope; |
+ Isolate* isolate = scope.main_isolate(); |
+ Zone* zone = scope.main_zone(); |
+ Factory* factory = isolate->factory(); |
+ ExpectedSnippet<0> snippets[] = { |
+ {"var sum = 0;\n" |
+ "var empty = null;\n" |
+ "for (var x in empty) { sum++; }\n" |
+ "return sum;", |
+ {factory->NewNumberFromInt(0)}}, |
+ {"var sum = 100;\n" |
+ "var empty = 1;\n" |
+ "for (var x in empty) { sum++; }\n" |
+ "return sum;", |
+ {factory->NewNumberFromInt(100)}}, |
+ {"for (var x in [ 10, 20, 30 ]) {}\n" |
+ "return 2;", |
+ {factory->NewNumberFromInt(2)}}, |
+ {"var last = 0;\n" |
+ "for (var x in [ 10, 20, 30 ]) {\n" |
+ " last = x;\n" |
+ "}\n" |
+ "return +last;", |
+ {factory->NewNumberFromInt(2)}}, |
+ {"var first = -1;\n" |
+ "for (var x in [ 10, 20, 30 ]) {\n" |
+ " first = +x;\n" |
+ " if (first > 0) break;\n" |
+ "}\n" |
+ "return first;", |
+ {factory->NewNumberFromInt(1)}}, |
+ {"var first = -1;\n" |
+ "for (var x in [ 10, 20, 30 ]) {\n" |
+ " if (first >= 0) continue;\n" |
+ " first = x;\n" |
+ "}\n" |
+ "return +first;", |
+ {factory->NewNumberFromInt(0)}}, |
+ {"var sum = 0;\n" |
+ "for (var x in [ 10, 20, 30 ]) {\n" |
+ " for (var y in [ 11, 22, 33, 44, 55, 66, 77 ]) {\n" |
+ " sum += 1;\n" |
+ " }\n" |
+ "}\n" |
+ "return sum;", |
+ {factory->NewNumberFromInt(21)}}, |
+ {"var sum = 0;\n" |
+ "for (var x in [ 10, 20, 30 ]) {\n" |
+ " for (var y in [ 11, 22, 33, 44, 55, 66, 77 ]) {\n" |
+ " if (sum == 7) break;\n" |
+ " if (sum == 6) continue;\n" |
+ " sum += 1;\n" |
+ " }\n" |
+ "}\n" |
+ "return sum;", |
+ {factory->NewNumberFromInt(6)}}, |
+ }; |
+ |
+ for (size_t i = 0; i < arraysize(snippets); i++) { |
+ ScopedVector<char> script(1024); |
+ SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, |
+ snippets[i].code_snippet, kFunctionName); |
+ |
+ BytecodeGraphTester tester(isolate, zone, script.start()); |
+ auto callable = tester.GetCallable<>(); |
+ Handle<Object> return_value = callable().ToHandleChecked(); |
+ CHECK(return_value->SameValue(*snippets[i].return_value())); |
+ } |
+} |
+ |
+ |
} // namespace compiler |
} // namespace internal |
} // namespace v8 |