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

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

Issue 1426913002: [Interpreter] Merges ToBoolean and JumpIfTrue/False bytecodes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased the patch and used the new Repeat_32 macro for tests 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 3fb12af4801afefe75e564355f5bf278ffef5ae1..972d6dc0a5b0db2172ca3ec93c841a9f9b864cdd 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -2012,7 +2012,7 @@ TEST(InterpreterLogicalOr) {
i::Isolate* isolate = handles.main_isolate();
i::Factory* factory = isolate->factory();
- std::pair<const char*, Handle<Object>> literals[5] = {
+ std::pair<const char*, Handle<Object>> literals[] = {
std::make_pair("var a, b; return a || b;\n", factory->undefined_value()),
std::make_pair("var a, b = 10; return a || b;\n",
handle(Smi::FromInt(10), isolate)),
@@ -2020,7 +2020,9 @@ TEST(InterpreterLogicalOr) {
factory->NewStringFromStaticChars("0")),
std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)),
std::make_pair("return 'a' || 0;\n",
- factory->NewStringFromStaticChars("a"))};
+ factory->NewStringFromStaticChars("a")),
+ std::make_pair("var a = '0', b = 10; return (a == 0) || b;\n",
+ factory->true_value())};
for (size_t i = 0; i < arraysize(literals); i++) {
std::string source(InterpreterTester::SourceForBody(literals[i].first));
@@ -2038,21 +2040,22 @@ TEST(InterpreterLogicalAnd) {
i::Isolate* isolate = handles.main_isolate();
i::Factory* factory = isolate->factory();
- std::pair<const char*, Handle<Object>> literals[7] = {
+ std::pair<const char*, Handle<Object>> literals[] = {
std::make_pair("var a, b = 10; return a && b;\n",
factory->undefined_value()),
std::make_pair("var a = 0, b = 10; return a && b / a;\n",
handle(Smi::FromInt(0), isolate)),
std::make_pair("var a = '0', b = 10; return a && b;\n",
handle(Smi::FromInt(10), isolate)),
- std::make_pair("return 0.0 && 3.2;\n",
- handle(Smi::FromInt(0), isolate)),
+ std::make_pair("return 0.0 && 3.2;\n", handle(Smi::FromInt(0), isolate)),
std::make_pair("return 'a' && 'b';\n",
factory->NewStringFromStaticChars("b")),
std::make_pair("return 'a' && 0 || 'b', 'c';\n",
factory->NewStringFromStaticChars("c")),
std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n",
- handle(Smi::FromInt(1), isolate))};
+ handle(Smi::FromInt(1), isolate)),
+ std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n",
+ factory->true_value())};
for (size_t i = 0; i < arraysize(literals); i++) {
std::string source(InterpreterTester::SourceForBody(literals[i].first));
@@ -2522,6 +2525,64 @@ TEST(InterpreterGlobalDelete) {
}
+TEST(InterpreterBasicLoops) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::pair<const char*, Handle<Object>> loops[] = {
+ std::make_pair("var a = 10; var b = 1;\n"
+ "while (a) {\n"
+ " b = b * 2;\n"
+ " a = a - 1;\n"
+ "};\n"
+ "return b;\n",
+ factory->NewHeapNumber(1024)),
+ std::make_pair("var a = 1; var b = 1;\n"
+ "do {\n"
+ " b = b * 2;\n"
+ " --a;\n"
+ "} while(a);\n"
+ "return b;\n",
+ handle(Smi::FromInt(2), isolate)),
+ std::make_pair("var b = 1;\n"
+ "for ( var a = 10; a; a--) {\n"
+ " b *= 2;\n"
+ "}\n"
+ "return b;",
+ factory->NewHeapNumber(1024)),
+ std::make_pair("var a = 10; var b = 1;\n"
+ "while (a > 0) {\n"
+ " b = b * 2;\n"
+ " a = a - 1;\n"
+ "};\n"
+ "return b;\n",
+ factory->NewHeapNumber(1024)),
+ std::make_pair("var a = 1; var b = 1;\n"
+ "do {\n"
+ " b = b * 2;\n"
+ " --a;\n"
+ "} while(a);\n"
+ "return b;\n",
+ handle(Smi::FromInt(2), isolate)),
+ std::make_pair("var b = 1;\n"
+ "for ( var a = 10; a > 0; a--) {\n"
+ " b *= 2;\n"
+ "}\n"
+ "return b;",
+ factory->NewHeapNumber(1024))};
+
+ for (size_t i = 0; i < arraysize(loops); i++) {
+ std::string source(InterpreterTester::SourceForBody(loops[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(*loops[i].second));
+ }
+}
+
+
TEST(InterpreterForIn) {
HandleAndZoneScope handles;
« 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