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

Unified Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1531693002: [Interpreter] Implement ForIn in bytecode graph builder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@oth-0009-phi
Patch Set: Minor clean-up/simplication in Runtime_InterpreterForInPrepare. Created 5 years 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
« no previous file with comments | « src/runtime/runtime-interpreter.cc ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/runtime/runtime-interpreter.cc ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698