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

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: rebased the patch and used the new Repeat_32 macro for tests 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 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 CHECK(return_value->SameValue(*literals[i].second)); 2005 CHECK(return_value->SameValue(*literals[i].second));
2006 } 2006 }
2007 } 2007 }
2008 2008
2009 2009
2010 TEST(InterpreterLogicalOr) { 2010 TEST(InterpreterLogicalOr) {
2011 HandleAndZoneScope handles; 2011 HandleAndZoneScope handles;
2012 i::Isolate* isolate = handles.main_isolate(); 2012 i::Isolate* isolate = handles.main_isolate();
2013 i::Factory* factory = isolate->factory(); 2013 i::Factory* factory = isolate->factory();
2014 2014
2015 std::pair<const char*, Handle<Object>> literals[5] = { 2015 std::pair<const char*, Handle<Object>> literals[] = {
2016 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()), 2016 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()),
2017 std::make_pair("var a, b = 10; return a || b;\n", 2017 std::make_pair("var a, b = 10; return a || b;\n",
2018 handle(Smi::FromInt(10), isolate)), 2018 handle(Smi::FromInt(10), isolate)),
2019 std::make_pair("var a = '0', b = 10; return a || b;\n", 2019 std::make_pair("var a = '0', b = 10; return a || b;\n",
2020 factory->NewStringFromStaticChars("0")), 2020 factory->NewStringFromStaticChars("0")),
2021 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)), 2021 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)),
2022 std::make_pair("return 'a' || 0;\n", 2022 std::make_pair("return 'a' || 0;\n",
2023 factory->NewStringFromStaticChars("a"))}; 2023 factory->NewStringFromStaticChars("a")),
2024 std::make_pair("var a = '0', b = 10; return (a == 0) || b;\n",
2025 factory->true_value())};
2024 2026
2025 for (size_t i = 0; i < arraysize(literals); i++) { 2027 for (size_t i = 0; i < arraysize(literals); i++) {
2026 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 2028 std::string source(InterpreterTester::SourceForBody(literals[i].first));
2027 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2029 InterpreterTester tester(handles.main_isolate(), source.c_str());
2028 auto callable = tester.GetCallable<>(); 2030 auto callable = tester.GetCallable<>();
2029 2031
2030 Handle<i::Object> return_value = callable().ToHandleChecked(); 2032 Handle<i::Object> return_value = callable().ToHandleChecked();
2031 CHECK(return_value->SameValue(*literals[i].second)); 2033 CHECK(return_value->SameValue(*literals[i].second));
2032 } 2034 }
2033 } 2035 }
2034 2036
2035 2037
2036 TEST(InterpreterLogicalAnd) { 2038 TEST(InterpreterLogicalAnd) {
2037 HandleAndZoneScope handles; 2039 HandleAndZoneScope handles;
2038 i::Isolate* isolate = handles.main_isolate(); 2040 i::Isolate* isolate = handles.main_isolate();
2039 i::Factory* factory = isolate->factory(); 2041 i::Factory* factory = isolate->factory();
2040 2042
2041 std::pair<const char*, Handle<Object>> literals[7] = { 2043 std::pair<const char*, Handle<Object>> literals[] = {
2042 std::make_pair("var a, b = 10; return a && b;\n", 2044 std::make_pair("var a, b = 10; return a && b;\n",
2043 factory->undefined_value()), 2045 factory->undefined_value()),
2044 std::make_pair("var a = 0, b = 10; return a && b / a;\n", 2046 std::make_pair("var a = 0, b = 10; return a && b / a;\n",
2045 handle(Smi::FromInt(0), isolate)), 2047 handle(Smi::FromInt(0), isolate)),
2046 std::make_pair("var a = '0', b = 10; return a && b;\n", 2048 std::make_pair("var a = '0', b = 10; return a && b;\n",
2047 handle(Smi::FromInt(10), isolate)), 2049 handle(Smi::FromInt(10), isolate)),
2048 std::make_pair("return 0.0 && 3.2;\n", 2050 std::make_pair("return 0.0 && 3.2;\n", handle(Smi::FromInt(0), isolate)),
2049 handle(Smi::FromInt(0), isolate)),
2050 std::make_pair("return 'a' && 'b';\n", 2051 std::make_pair("return 'a' && 'b';\n",
2051 factory->NewStringFromStaticChars("b")), 2052 factory->NewStringFromStaticChars("b")),
2052 std::make_pair("return 'a' && 0 || 'b', 'c';\n", 2053 std::make_pair("return 'a' && 0 || 'b', 'c';\n",
2053 factory->NewStringFromStaticChars("c")), 2054 factory->NewStringFromStaticChars("c")),
2054 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", 2055 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n",
2055 handle(Smi::FromInt(1), isolate))}; 2056 handle(Smi::FromInt(1), isolate)),
2057 std::make_pair("var x = 1, y = 3; return (x == 1) && (3 == 3) || y;\n",
2058 factory->true_value())};
2056 2059
2057 for (size_t i = 0; i < arraysize(literals); i++) { 2060 for (size_t i = 0; i < arraysize(literals); i++) {
2058 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 2061 std::string source(InterpreterTester::SourceForBody(literals[i].first));
2059 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2062 InterpreterTester tester(handles.main_isolate(), source.c_str());
2060 auto callable = tester.GetCallable<>(); 2063 auto callable = tester.GetCallable<>();
2061 2064
2062 Handle<i::Object> return_value = callable().ToHandleChecked(); 2065 Handle<i::Object> return_value = callable().ToHandleChecked();
2063 CHECK(return_value->SameValue(*literals[i].second)); 2066 CHECK(return_value->SameValue(*literals[i].second));
2064 } 2067 }
2065 } 2068 }
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
2515 InterpreterTester tester(handles.main_isolate(), 2518 InterpreterTester tester(handles.main_isolate(),
2516 test_global_delete[i].first); 2519 test_global_delete[i].first);
2517 auto callable = tester.GetCallable<>(); 2520 auto callable = tester.GetCallable<>();
2518 2521
2519 Handle<i::Object> return_value = callable().ToHandleChecked(); 2522 Handle<i::Object> return_value = callable().ToHandleChecked();
2520 CHECK(return_value->SameValue(*test_global_delete[i].second)); 2523 CHECK(return_value->SameValue(*test_global_delete[i].second));
2521 } 2524 }
2522 } 2525 }
2523 2526
2524 2527
2528 TEST(InterpreterBasicLoops) {
2529 HandleAndZoneScope handles;
2530 i::Isolate* isolate = handles.main_isolate();
2531 i::Factory* factory = isolate->factory();
2532
2533 std::pair<const char*, Handle<Object>> loops[] = {
2534 std::make_pair("var a = 10; var b = 1;\n"
2535 "while (a) {\n"
2536 " b = b * 2;\n"
2537 " a = a - 1;\n"
2538 "};\n"
2539 "return b;\n",
2540 factory->NewHeapNumber(1024)),
2541 std::make_pair("var a = 1; var b = 1;\n"
2542 "do {\n"
2543 " b = b * 2;\n"
2544 " --a;\n"
2545 "} while(a);\n"
2546 "return b;\n",
2547 handle(Smi::FromInt(2), isolate)),
2548 std::make_pair("var b = 1;\n"
2549 "for ( var a = 10; a; a--) {\n"
2550 " b *= 2;\n"
2551 "}\n"
2552 "return b;",
2553 factory->NewHeapNumber(1024)),
2554 std::make_pair("var a = 10; var b = 1;\n"
2555 "while (a > 0) {\n"
2556 " b = b * 2;\n"
2557 " a = a - 1;\n"
2558 "};\n"
2559 "return b;\n",
2560 factory->NewHeapNumber(1024)),
2561 std::make_pair("var a = 1; var b = 1;\n"
2562 "do {\n"
2563 " b = b * 2;\n"
2564 " --a;\n"
2565 "} while(a);\n"
2566 "return b;\n",
2567 handle(Smi::FromInt(2), isolate)),
2568 std::make_pair("var b = 1;\n"
2569 "for ( var a = 10; a > 0; a--) {\n"
2570 " b *= 2;\n"
2571 "}\n"
2572 "return b;",
2573 factory->NewHeapNumber(1024))};
2574
2575 for (size_t i = 0; i < arraysize(loops); i++) {
2576 std::string source(InterpreterTester::SourceForBody(loops[i].first));
2577 InterpreterTester tester(handles.main_isolate(), source.c_str());
2578 auto callable = tester.GetCallable<>();
2579
2580 Handle<i::Object> return_value = callable().ToHandleChecked();
2581 CHECK(return_value->SameValue(*loops[i].second));
2582 }
2583 }
2584
2585
2525 TEST(InterpreterForIn) { 2586 TEST(InterpreterForIn) {
2526 HandleAndZoneScope handles; 2587 HandleAndZoneScope handles;
2527 2588
2528 // TODO(oth): Add a test here for delete mid-loop when delete is ready. 2589 // TODO(oth): Add a test here for delete mid-loop when delete is ready.
2529 std::pair<const char*, int> for_in_samples[] = { 2590 std::pair<const char*, int> for_in_samples[] = {
2530 {"function f() {\n" 2591 {"function f() {\n"
2531 " var r = -1;\n" 2592 " var r = -1;\n"
2532 " for (var a in null) { r = a; }\n" 2593 " for (var a in null) { r = a; }\n"
2533 " return r;\n" 2594 " return r;\n"
2534 "}", 2595 "}",
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2708 InterpreterTester tester(handles.main_isolate(), for_in_samples[i].first); 2769 InterpreterTester tester(handles.main_isolate(), for_in_samples[i].first);
2709 auto callable = tester.GetCallable<>(); 2770 auto callable = tester.GetCallable<>();
2710 Handle<Object> return_val = callable().ToHandleChecked(); 2771 Handle<Object> return_val = callable().ToHandleChecked();
2711 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), for_in_samples[i].second); 2772 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), for_in_samples[i].second);
2712 } 2773 }
2713 } 2774 }
2714 2775
2715 } // namespace interpreter 2776 } // namespace interpreter
2716 } // namespace internal 2777 } // namespace internal
2717 } // namespace v8 2778 } // namespace v8
OLDNEW
« 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