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

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: Sync test bytecode sequences to avoid unnecessary Ldar/Star instructions. 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 c1edc642e7a08aa2c98bb89004f86dae8e2400c4..829d82c3bf46920370a53299ffff03d2998ecb62 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -2617,7 +2617,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"
@@ -2950,6 +2949,148 @@ TEST(InterpreterNewTarget) {
CHECK(new_target_name->SameValue(*factory->NewStringFromStaticChars("f")));
}
+
+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},
+ {"function f(a) {\n"
+ " return a + (arguments[0] = 10);\n"
+ "}",
+ 50},
+ {"function f(a) {\n"
+ " return a + (arguments[0] = 10) + a;\n"
+ "}",
+ 60},
+ {"function f(a) {\n"
+ " return a + (arguments[0] = 10) + arguments[0];\n"
+ "}",
+ 60},
+ };
+
+ const int arg_value = 40;
+ for (size_t i = 0; i < arraysize(samples); i++) {
+ InterpreterTester tester(handles.main_isolate(), samples[i].first);
+ auto callable = tester.GetCallable<Handle<Object>>();
+ Handle<Object> return_val =
+ callable(handle(Smi::FromInt(arg_value), handles.main_isolate()))
+ .ToHandleChecked();
+ CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second);
+ }
+}
+
+
} // namespace interpreter
} // namespace internal
} // namespace v8
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698