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

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

Issue 1420503002: [Interpreter] Add support for compound expressions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 years, 2 months 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 | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index 63df7f73692f31e4ba7f629cdc271cde2fdb70e3..ba038aed49387d8d667a02f3db4d0355135d49c1 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -2145,3 +2145,57 @@ TEST(InterpreterGlobalCountOperators) {
CHECK(return_value->SameValue(*count_ops[i].second));
}
}
+
+
+TEST(InterpreterCompoundExpressions) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::pair<const char*, Handle<Object>> compound_expr[5] = {
+ std::make_pair("var a = 1; a += 2; return a;",
+ Handle<Object>(Smi::FromInt(3), isolate)),
+ std::make_pair("var a = 10; a /= 2; return a;",
+ Handle<Object>(Smi::FromInt(5), isolate)),
+ std::make_pair("var a = 'test'; a += 'ing'; return a;",
+ factory->NewStringFromStaticChars("testing")),
+ std::make_pair("var a = { val: 2 }; a.val *= 2; return a.val;",
+ Handle<Object>(Smi::FromInt(4), isolate)),
+ std::make_pair("var a = 1; (function f() { a = 2; })(); a += 24;"
+ "return a;",
+ Handle<Object>(Smi::FromInt(26), isolate)),
+ };
+
+ for (size_t i = 0; i < arraysize(compound_expr); i++) {
+ std::string source(
+ InterpreterTester::SourceForBody(compound_expr[i].first));
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*compound_expr[i].second));
+ }
+}
+
+
+TEST(InterpreterGlobalCompoundExpressions) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+
+ std::pair<const char*, Handle<Object>> compound_expr[2] = {
+ std::make_pair("var global = 100;"
+ "function f() { global += 20; return global; }",
+ Handle<Object>(Smi::FromInt(120), isolate)),
+ std::make_pair("unallocated = 100;"
+ "function f() { unallocated -= 20; return unallocated; }",
+ Handle<Object>(Smi::FromInt(80), isolate)),
+ };
+
+ for (size_t i = 0; i < arraysize(compound_expr); i++) {
+ InterpreterTester tester(handles.main_isolate(), compound_expr[i].first);
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*compound_expr[i].second));
+ }
+}
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698