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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1399773002: [Interpreter] Adds logical and, logical or and comma operators to interpreter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed formatting problems with the expected bytecode initialization 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 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 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 1665
1666 for (size_t i = 0; i < arraysize(literals); i++) { 1666 for (size_t i = 0; i < arraysize(literals); i++) {
1667 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1667 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1668 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1668 InterpreterTester tester(handles.main_isolate(), source.c_str());
1669 auto callable = tester.GetCallable<>(); 1669 auto callable = tester.GetCallable<>();
1670 1670
1671 Handle<i::Object> return_value = callable().ToHandleChecked(); 1671 Handle<i::Object> return_value = callable().ToHandleChecked();
1672 CHECK(return_value->SameValue(*literals[i].second)); 1672 CHECK(return_value->SameValue(*literals[i].second));
1673 } 1673 }
1674 } 1674 }
1675
1676
1677 TEST(InterpreterComma) {
1678 HandleAndZoneScope handles;
1679 i::Isolate* isolate = handles.main_isolate();
1680 i::Factory* factory = isolate->factory();
1681
1682 std::pair<const char*, Handle<Object>> literals[6] = {
1683 std::make_pair("var a; return 0, a;\n", factory->undefined_value()),
1684 std::make_pair("return 'a', 2.2, 3;\n",
1685 Handle<Object>(Smi::FromInt(3), isolate)),
1686 std::make_pair("return 'a', 'b', 'c';\n",
1687 factory->NewStringFromStaticChars("c")),
1688 std::make_pair("return 3.2, 2.3, 4.5;\n", factory->NewNumber(4.5)),
1689 std::make_pair("var a = 10; return b = a, b = b+1;\n",
1690 Handle<Object>(Smi::FromInt(11), isolate)),
1691 std::make_pair("var a = 10; return b = a, b = b+1, b + 10;\n",
1692 Handle<Object>(Smi::FromInt(21), isolate))};
1693
1694 for (size_t i = 0; i < arraysize(literals); i++) {
1695 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1696 InterpreterTester tester(handles.main_isolate(), source.c_str());
1697 auto callable = tester.GetCallable<>();
1698
1699 Handle<i::Object> return_value = callable().ToHandleChecked();
1700 CHECK(return_value->SameValue(*literals[i].second));
1701 }
1702 }
1703
1704
1705 TEST(InterpreterLogicalOr) {
1706 HandleAndZoneScope handles;
1707 i::Isolate* isolate = handles.main_isolate();
1708 i::Factory* factory = isolate->factory();
1709
1710 std::pair<const char*, Handle<Object>> literals[5] = {
1711 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()),
1712 std::make_pair("var a, b = 10; return a || b;\n",
1713 Handle<Object>(Smi::FromInt(10), isolate)),
1714 std::make_pair("var a = '0', b = 10; return a || b;\n",
1715 factory->NewStringFromStaticChars("0")),
1716 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)),
1717 std::make_pair("return 'a' || 0;\n",
1718 factory->NewStringFromStaticChars("a"))};
1719
1720 for (size_t i = 0; i < arraysize(literals); i++) {
1721 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1722 InterpreterTester tester(handles.main_isolate(), source.c_str());
1723 auto callable = tester.GetCallable<>();
1724
1725 Handle<i::Object> return_value = callable().ToHandleChecked();
1726 CHECK(return_value->SameValue(*literals[i].second));
1727 }
1728 }
1729
1730
1731 TEST(InterpreterLogicalAnd) {
1732 HandleAndZoneScope handles;
1733 i::Isolate* isolate = handles.main_isolate();
1734 i::Factory* factory = isolate->factory();
1735
1736 std::pair<const char*, Handle<Object>> literals[7] = {
1737 std::make_pair("var a, b = 10; return a && b;\n",
1738 factory->undefined_value()),
1739 std::make_pair("var a = 0, b = 10; return a && b / a;\n",
1740 Handle<Object>(Smi::FromInt(0), isolate)),
1741 std::make_pair("var a = '0', b = 10; return a && b;\n",
1742 Handle<Object>(Smi::FromInt(10), isolate)),
1743 std::make_pair("return 0.0 && 3.2;\n",
1744 Handle<Object>(Smi::FromInt(0), isolate)),
1745 std::make_pair("return 'a' && 'b';\n",
1746 factory->NewStringFromStaticChars("b")),
1747 std::make_pair("return 'a' && 0 || 'b', 'c';\n",
1748 factory->NewStringFromStaticChars("c")),
1749 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n",
1750 Handle<Object>(Smi::FromInt(1), isolate))};
1751
1752 for (size_t i = 0; i < arraysize(literals); i++) {
1753 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1754 InterpreterTester tester(handles.main_isolate(), source.c_str());
1755 auto callable = tester.GetCallable<>();
1756
1757 Handle<i::Object> return_value = callable().ToHandleChecked();
1758 CHECK(return_value->SameValue(*literals[i].second));
1759 }
1760 }
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