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

Side by Side 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: Last patch was not complete. Forgot few changes. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/execution.h" 7 #include "src/execution.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/interpreter/bytecode-array-builder.h" 9 #include "src/interpreter/bytecode-array-builder.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 CHECK(return_value->SameValue(*literals[i].second)); 1982 CHECK(return_value->SameValue(*literals[i].second));
1983 } 1983 }
1984 } 1984 }
1985 1985
1986 1986
1987 TEST(InterpreterLogicalOr) { 1987 TEST(InterpreterLogicalOr) {
1988 HandleAndZoneScope handles; 1988 HandleAndZoneScope handles;
1989 i::Isolate* isolate = handles.main_isolate(); 1989 i::Isolate* isolate = handles.main_isolate();
1990 i::Factory* factory = isolate->factory(); 1990 i::Factory* factory = isolate->factory();
1991 1991
1992 std::pair<const char*, Handle<Object>> literals[5] = { 1992 std::pair<const char*, Handle<Object>> literals[] = {
1993 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()), 1993 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()),
1994 std::make_pair("var a, b = 10; return a || b;\n", 1994 std::make_pair("var a, b = 10; return a || b;\n",
1995 handle(Smi::FromInt(10), isolate)), 1995 handle(Smi::FromInt(10), isolate)),
1996 std::make_pair("var a = '0', b = 10; return a || b;\n", 1996 std::make_pair("var a = '0', b = 10; return a || b;\n",
1997 factory->NewStringFromStaticChars("0")), 1997 factory->NewStringFromStaticChars("0")),
1998 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)), 1998 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)),
1999 std::make_pair("return 'a' || 0;\n", 1999 std::make_pair("return 'a' || 0;\n",
2000 factory->NewStringFromStaticChars("a"))}; 2000 factory->NewStringFromStaticChars("a")),
2001 std::make_pair("var a = '0', b = 10; return (a == 0) || b;\n",
2002 factory->true_value())};
2001 2003
2002 for (size_t i = 0; i < arraysize(literals); i++) { 2004 for (size_t i = 0; i < arraysize(literals); i++) {
2003 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 2005 std::string source(InterpreterTester::SourceForBody(literals[i].first));
2004 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2006 InterpreterTester tester(handles.main_isolate(), source.c_str());
2005 auto callable = tester.GetCallable<>(); 2007 auto callable = tester.GetCallable<>();
2006 2008
2007 Handle<i::Object> return_value = callable().ToHandleChecked(); 2009 Handle<i::Object> return_value = callable().ToHandleChecked();
2008 CHECK(return_value->SameValue(*literals[i].second)); 2010 CHECK(return_value->SameValue(*literals[i].second));
2009 } 2011 }
2010 } 2012 }
2011 2013
2012 2014
2013 TEST(InterpreterLogicalAnd) { 2015 TEST(InterpreterLogicalAnd) {
2014 HandleAndZoneScope handles; 2016 HandleAndZoneScope handles;
2015 i::Isolate* isolate = handles.main_isolate(); 2017 i::Isolate* isolate = handles.main_isolate();
2016 i::Factory* factory = isolate->factory(); 2018 i::Factory* factory = isolate->factory();
2017 2019
2018 std::pair<const char*, Handle<Object>> literals[7] = { 2020 std::pair<const char*, Handle<Object>> literals[] = {
2019 std::make_pair("var a, b = 10; return a && b;\n", 2021 std::make_pair("var a, b = 10; return a && b;\n",
2020 factory->undefined_value()), 2022 factory->undefined_value()),
2021 std::make_pair("var a = 0, b = 10; return a && b / a;\n", 2023 std::make_pair("var a = 0, b = 10; return a && b / a;\n",
2022 handle(Smi::FromInt(0), isolate)), 2024 handle(Smi::FromInt(0), isolate)),
2023 std::make_pair("var a = '0', b = 10; return a && b;\n", 2025 std::make_pair("var a = '0', b = 10; return a && b;\n",
2024 handle(Smi::FromInt(10), isolate)), 2026 handle(Smi::FromInt(10), isolate)),
2025 std::make_pair("return 0.0 && 3.2;\n", 2027 std::make_pair("return 0.0 && 3.2;\n", handle(Smi::FromInt(0), isolate)),
2026 handle(Smi::FromInt(0), isolate)),
2027 std::make_pair("return 'a' && 'b';\n", 2028 std::make_pair("return 'a' && 'b';\n",
2028 factory->NewStringFromStaticChars("b")), 2029 factory->NewStringFromStaticChars("b")),
2029 std::make_pair("return 'a' && 0 || 'b', 'c';\n", 2030 std::make_pair("return 'a' && 0 || 'b', 'c';\n",
2030 factory->NewStringFromStaticChars("c")), 2031 factory->NewStringFromStaticChars("c")),
2031 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", 2032 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n",
2032 handle(Smi::FromInt(1), isolate))}; 2033 handle(Smi::FromInt(1), isolate)),
2034 std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n",
2035 factory->true_value())};
2033 2036
2034 for (size_t i = 0; i < arraysize(literals); i++) { 2037 for (size_t i = 0; i < arraysize(literals); i++) {
2035 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 2038 std::string source(InterpreterTester::SourceForBody(literals[i].first));
2036 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2039 InterpreterTester tester(handles.main_isolate(), source.c_str());
2037 auto callable = tester.GetCallable<>(); 2040 auto callable = tester.GetCallable<>();
2038 2041
2039 Handle<i::Object> return_value = callable().ToHandleChecked(); 2042 Handle<i::Object> return_value = callable().ToHandleChecked();
2040 CHECK(return_value->SameValue(*literals[i].second)); 2043 CHECK(return_value->SameValue(*literals[i].second));
2041 } 2044 }
2042 } 2045 }
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 2494
2492 for (size_t i = 0; i < arraysize(test_global_delete); i++) { 2495 for (size_t i = 0; i < arraysize(test_global_delete); i++) {
2493 InterpreterTester tester(handles.main_isolate(), 2496 InterpreterTester tester(handles.main_isolate(),
2494 test_global_delete[i].first); 2497 test_global_delete[i].first);
2495 auto callable = tester.GetCallable<>(); 2498 auto callable = tester.GetCallable<>();
2496 2499
2497 Handle<i::Object> return_value = callable().ToHandleChecked(); 2500 Handle<i::Object> return_value = callable().ToHandleChecked();
2498 CHECK(return_value->SameValue(*test_global_delete[i].second)); 2501 CHECK(return_value->SameValue(*test_global_delete[i].second));
2499 } 2502 }
2500 } 2503 }
2504
2505
2506 TEST(InterpreterBasicLoops) {
2507 HandleAndZoneScope handles;
2508 i::Isolate* isolate = handles.main_isolate();
2509 i::Factory* factory = isolate->factory();
2510
2511 std::pair<const char*, Handle<Object>> loops[] = {
2512 std::make_pair("var a = 10; var b = 1;\n"
2513 "while (a) {\n"
2514 " b = b * 2;\n"
2515 " a = a - 1;\n"
2516 "};\n"
2517 "return b;\n",
2518 factory->NewHeapNumber(1024)),
2519 std::make_pair("var a = 1; var b = 1;\n"
2520 "do {\n"
2521 " b = b * 2;\n"
2522 " --a;\n"
2523 "} while(a);\n"
2524 "return b;\n",
2525 handle(Smi::FromInt(2), isolate)),
2526 std::make_pair("var b = 1;\n"
2527 "for ( var a = 10; a; a--) {\n"
2528 " b *= 2;\n"
2529 "}\n"
2530 "return b;",
2531 factory->NewHeapNumber(1024)),
2532 std::make_pair("var a = 10; var b = 1;\n"
2533 "while (a > 0) {\n"
2534 " b = b * 2;\n"
2535 " a = a - 1;\n"
2536 "};\n"
2537 "return b;\n",
2538 factory->NewHeapNumber(1024)),
2539 std::make_pair("var a = 1; var b = 1;\n"
2540 "do {\n"
2541 " b = b * 2;\n"
2542 " --a;\n"
2543 "} while(a);\n"
2544 "return b;\n",
2545 handle(Smi::FromInt(2), isolate)),
2546 std::make_pair("var b = 1;\n"
2547 "for ( var a = 10; a > 0; a--) {\n"
2548 " b *= 2;\n"
2549 "}\n"
2550 "return b;",
2551 factory->NewHeapNumber(1024))};
2552
2553 for (size_t i = 0; i < arraysize(loops); i++) {
2554 std::string source(InterpreterTester::SourceForBody(loops[i].first));
2555 InterpreterTester tester(handles.main_isolate(), source.c_str());
2556 auto callable = tester.GetCallable<>();
2557
2558 Handle<i::Object> return_value = callable().ToHandleChecked();
2559 CHECK(return_value->SameValue(*loops[i].second));
2560 }
2561 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698