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

Unified Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1412683011: [Interpreter] Enable assignments in expressions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. Created 5 years, 1 month 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-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index 49df43ce9582d9c647046fa66ea2ffa370128d2b..d26ca1dd4cb2a919329d414d519c155c116c74e4 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -2618,7 +2618,6 @@ TEST(InterpreterBasicLoops) {
TEST(InterpreterForIn) {
HandleAndZoneScope handles;
- // TODO(oth): Add a test here for delete mid-loop when delete is ready.
std::pair<const char*, int> for_in_samples[] = {
{"function f() {\n"
" var r = -1;\n"
@@ -2885,6 +2884,132 @@ TEST(InterpreterSwitch) {
}
}
+
+TEST(InterpreterAssignmentInExpressions) {
+ HandleAndZoneScope handles;
+
+ std::pair<const char*, int> samples[] = {
+ {"function f() {\n"
+ " var x = 7;\n"
+ " var y = x + (x = 1) + (x = 2);\n"
+ " return y;\n"
+ "}",
+ 10},
+ {"function f() {\n"
+ " var x = 7;\n"
+ " var y = x + (x = 1) + (x = 2);\n"
+ " return x;\n"
+ "}",
+ 2},
+ {"function f() {\n"
+ " var x = 55;\n"
+ " x = x + (x = 100) + (x = 101);\n"
+ " return x;\n"
+ "}",
+ 256},
+ {"function f() {\n"
+ " var x = 7;\n"
+ " return ++x + x + x++;\n"
+ "}",
+ 24},
+ {"function f() {\n"
+ " var x = 7;\n"
+ " var y = 1 + ++x + x + x++;\n"
+ " return x;\n"
+ "}",
+ 9},
+ {"function f() {\n"
+ " var x = 7;\n"
+ " var y = ++x + x + x++;\n"
+ " return x;\n"
+ "}",
+ 9},
+ {"function f() {\n"
+ " var x = 7, y = 100, z = 1000;\n"
+ " return x + (x += 3) + y + (y *= 10) + (z *= 7) + z;\n"
+ "}",
+ 15117},
+ {"function f() {\n"
+ " var inner = function (x) { return x + (x = 2) + (x = 4) + x; };\n"
+ " return inner(1);\n"
+ "}",
+ 11},
+ {"function f() {\n"
+ " var x = 1, y = 2;\n"
+ " x = x + (x = 3) + y + (y = 4), y = y + (y = 5) + y + x;\n"
+ " return x + y;\n"
+ "}",
+ 10 + 24},
+ {"function f() {\n"
+ " var x = 0;\n"
+ " var y = x | (x = 1) | (x = 2);\n"
+ " return x;\n"
+ "}",
+ 2},
+ {"function f() {\n"
+ " var x = 0;\n"
+ " var y = x || (x = 1);\n"
+ " return x;\n"
+ "}",
+ 1},
+ {"function f() {\n"
+ " var x = 1;\n"
+ " var y = x && (x = 2) && (x = 3);\n"
+ " return x;\n"
+ "}",
+ 3},
+ {"function f() {\n"
+ " var x = 1;\n"
+ " var y = x || (x = 2);\n"
+ " return x;\n"
+ "}",
+ 1},
+ {"function f() {\n"
+ " var x = 1;\n"
+ " x = (x << (x = 3)) | (x = 16);\n"
+ " return x;\n"
+ "}",
+ 24},
+ {"function f() {\n"
+ " var r = 7;\n"
+ " var s = 11;\n"
+ " var t = 13;\n"
+ " var u = r + s + t + (r = 10) + (s = 20) +"
+ " (t = (r + s)) + r + s + t;\n"
+ " return r + s + t + u;\n"
+ "}",
+ 211},
+ {"function f() {\n"
+ " var r = 7;\n"
+ " var s = 11;\n"
+ " var t = 13;\n"
+ " return r > (3 * s * (s = 1)) ? (t + (t += 1)) : (r + (r = 4));\n"
+ "}",
+ 11},
+ {"function f() {\n"
+ " var r = 7;\n"
+ " var s = 11;\n"
+ " var t = 13;\n"
+ " return r > (3 * s * (s = 0)) ? (t + (t += 1)) : (r + (r = 4));\n"
+ "}",
+ 27},
+ {"function f() {\n"
+ " var r = 7;\n"
+ " var s = 11;\n"
+ " var t = 13;\n"
+ " return (r + (r = 5)) > s ? r : t;\n"
+ "}",
+ 5},
rmcilroy 2015/11/05 16:34:51 Could you add a test for something like: functio
oth 2015/11/12 11:32:15 Done.
+ };
+
+ for (size_t i = 0; i < arraysize(samples); i++) {
+ InterpreterTester tester(handles.main_isolate(), samples[i].first);
+ auto callable = tester.GetCallable<>();
+ Handle<Object> return_val = callable().ToHandleChecked();
+ CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second);
+ }
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698