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

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: Re-work ForInPrepare. 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
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 3de904304321aca96a86be2e854275f6f0dcc631..a6b00880c998b08eca6f72abdc23b92bb608b832 100644
--- a/test/cctest/compiler/test-run-bytecode-graph-builder.cc
+++ b/test/cctest/compiler/test-run-bytecode-graph-builder.cc
@@ -708,11 +708,6 @@ TEST(BytecodeGraphBuilderGlobals) {
}
-TEST(BytecodeGraphBuilderToObject) {
- // TODO(mythria): tests for ToObject. Needs ForIn.
-}
-
-
TEST(BytecodeGraphBuilderToName) {
HandleAndZoneScope scope;
Isolate* isolate = scope.main_isolate();
@@ -1838,6 +1833,57 @@ TEST(BytecodeGraphBuilderFor) {
}
}
+
+TEST(BytecodeGraphBuilderForIn) {
+ HandleAndZoneScope scope;
+ Isolate* isolate = scope.main_isolate();
+ Zone* zone = scope.main_zone();
+ Factory* factory = isolate->factory();
+ ExpectedSnippet<0> snippets[] = {
+ {"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)}},
+ // TODO(oth): test break/continue nested.
+ };
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698