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

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

Issue 1417053004: [Interpreter] Add conditional expressions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_prologue
Patch Set: 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
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index 2994387bfd7f383f97a7b949d209022648c65dee..18ccaf25f38d17d6d7dbaad9371f9fd14a502a7e 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -2264,3 +2264,37 @@ TEST(InterpreterCreateArguments) {
CHECK(return_val->SameValue(*args[create_args[i].second]));
}
}
+
+
+TEST(InterpreterConditional) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+
+ std::pair<const char*, Handle<Object>> conditional[8] = {
+ std::make_pair("return true ? 2 : 3;",
+ handle(Smi::FromInt(2), isolate)),
+ std::make_pair("return false ? 2 : 3;",
+ handle(Smi::FromInt(3), isolate)),
+ std::make_pair("var a = 1; return a ? 20 : 30;",
+ handle(Smi::FromInt(20), isolate)),
+ std::make_pair("var a = 1; return a ? 20 : 30;",
+ handle(Smi::FromInt(20), isolate)),
+ std::make_pair("var a = 'string'; return a ? 20 : 30;",
+ handle(Smi::FromInt(20), isolate)),
+ std::make_pair("var a = undefined; return a ? 20 : 30;",
+ handle(Smi::FromInt(30), isolate)),
+ std::make_pair("return 1 ? 2 ? 3 : 4 : 5;",
+ handle(Smi::FromInt(3), isolate)),
+ std::make_pair("return 0 ? 2 ? 3 : 4 : 5;",
+ handle(Smi::FromInt(5), isolate)),
+ };
+
+ for (size_t i = 0; i < arraysize(conditional); i++) {
+ std::string source(InterpreterTester::SourceForBody(conditional[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(*conditional[i].second));
+ }
+}
« src/interpreter/bytecode-generator.cc ('K') | « 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