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

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

Issue 1416623003: [Interpreter] Add support for for count operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix gcc error 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 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 1717
1718 TEST(InterpreterArrayLiterals) { 1718 TEST(InterpreterArrayLiterals) {
1719 HandleAndZoneScope handles; 1719 HandleAndZoneScope handles;
1720 i::Isolate* isolate = handles.main_isolate(); 1720 i::Isolate* isolate = handles.main_isolate();
1721 i::Factory* factory = isolate->factory(); 1721 i::Factory* factory = isolate->factory();
1722 1722
1723 std::pair<const char*, Handle<Object>> literals[6] = { 1723 std::pair<const char*, Handle<Object>> literals[6] = {
1724 std::make_pair("return [][0];\n", 1724 std::make_pair("return [][0];\n",
1725 factory->undefined_value()), 1725 factory->undefined_value()),
1726 std::make_pair("return [1, 3, 2][1];\n", 1726 std::make_pair("return [1, 3, 2][1];\n",
1727 Handle<Object>(Smi::FromInt(3), isolate)), 1727 handle(Smi::FromInt(3), isolate)),
1728 std::make_pair("return ['a', 'b', 'c'][2];\n", 1728 std::make_pair("return ['a', 'b', 'c'][2];\n",
1729 factory->NewStringFromStaticChars("c")), 1729 factory->NewStringFromStaticChars("c")),
1730 std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n", 1730 std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n",
1731 Handle<Object>(Smi::FromInt(102), isolate)), 1731 handle(Smi::FromInt(102), isolate)),
1732 std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n", 1732 std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n",
1733 factory->NewStringFromStaticChars("a")), 1733 factory->NewStringFromStaticChars("a")),
1734 std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n", 1734 std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n",
1735 factory->NewStringFromStaticChars("test")) 1735 factory->NewStringFromStaticChars("test"))
1736 }; 1736 };
1737 1737
1738 for (size_t i = 0; i < arraysize(literals); i++) { 1738 for (size_t i = 0; i < arraysize(literals); i++) {
1739 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1739 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1740 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1740 InterpreterTester tester(handles.main_isolate(), source.c_str());
1741 auto callable = tester.GetCallable<>(); 1741 auto callable = tester.GetCallable<>();
1742 1742
1743 Handle<i::Object> return_value = callable().ToHandleChecked(); 1743 Handle<i::Object> return_value = callable().ToHandleChecked();
1744 CHECK(return_value->SameValue(*literals[i].second)); 1744 CHECK(return_value->SameValue(*literals[i].second));
1745 } 1745 }
1746 } 1746 }
1747 1747
1748 1748
1749 TEST(InterpreterObjectLiterals) { 1749 TEST(InterpreterObjectLiterals) {
1750 HandleAndZoneScope handles; 1750 HandleAndZoneScope handles;
1751 i::Isolate* isolate = handles.main_isolate(); 1751 i::Isolate* isolate = handles.main_isolate();
1752 i::Factory* factory = isolate->factory(); 1752 i::Factory* factory = isolate->factory();
1753 1753
1754 std::pair<const char*, Handle<Object>> literals[14] = { 1754 std::pair<const char*, Handle<Object>> literals[14] = {
1755 std::make_pair("return { }.name;", 1755 std::make_pair("return { }.name;",
1756 factory->undefined_value()), 1756 factory->undefined_value()),
1757 std::make_pair("return { name: 'string', val: 9.2 }.name;", 1757 std::make_pair("return { name: 'string', val: 9.2 }.name;",
1758 factory->NewStringFromStaticChars("string")), 1758 factory->NewStringFromStaticChars("string")),
1759 std::make_pair("var a = 15; return { name: 'string', val: a }.val;", 1759 std::make_pair("var a = 15; return { name: 'string', val: a }.val;",
1760 Handle<Object>(Smi::FromInt(15), isolate)), 1760 handle(Smi::FromInt(15), isolate)),
1761 std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;", 1761 std::make_pair("var a = 5; return { val: a, val: a + 1 }.val;",
1762 Handle<Object>(Smi::FromInt(6), isolate)), 1762 handle(Smi::FromInt(6), isolate)),
1763 std::make_pair("return { func: function() { return 'test' } }.func();", 1763 std::make_pair("return { func: function() { return 'test' } }.func();",
1764 factory->NewStringFromStaticChars("test")), 1764 factory->NewStringFromStaticChars("test")),
1765 std::make_pair("return { func(a) { return a + 'st'; } }.func('te');", 1765 std::make_pair("return { func(a) { return a + 'st'; } }.func('te');",
1766 factory->NewStringFromStaticChars("test")), 1766 factory->NewStringFromStaticChars("test")),
1767 std::make_pair("return { get a() { return 22; } }.a;", 1767 std::make_pair("return { get a() { return 22; } }.a;",
1768 Handle<Object>(Smi::FromInt(22), isolate)), 1768 handle(Smi::FromInt(22), isolate)),
1769 std::make_pair("var a = { get b() { return this.x + 't'; },\n" 1769 std::make_pair("var a = { get b() { return this.x + 't'; },\n"
1770 " set b(val) { this.x = val + 's' } };\n" 1770 " set b(val) { this.x = val + 's' } };\n"
1771 "a.b = 'te';\n" 1771 "a.b = 'te';\n"
1772 "return a.b;", 1772 "return a.b;",
1773 factory->NewStringFromStaticChars("test")), 1773 factory->NewStringFromStaticChars("test")),
1774 std::make_pair("var a = 123; return { 1: a }[1];", 1774 std::make_pair("var a = 123; return { 1: a }[1];",
1775 Handle<Object>(Smi::FromInt(123), isolate)), 1775 handle(Smi::FromInt(123), isolate)),
1776 std::make_pair("return Object.getPrototypeOf({ __proto__: null });", 1776 std::make_pair("return Object.getPrototypeOf({ __proto__: null });",
1777 factory->null_value()), 1777 factory->null_value()),
1778 std::make_pair("var a = 'test'; return { [a]: 1 }.test;", 1778 std::make_pair("var a = 'test'; return { [a]: 1 }.test;",
1779 Handle<Object>(Smi::FromInt(1), isolate)), 1779 handle(Smi::FromInt(1), isolate)),
1780 std::make_pair("var a = 'test'; return { b: a, [a]: a + 'ing' }['test']", 1780 std::make_pair("var a = 'test'; return { b: a, [a]: a + 'ing' }['test']",
1781 factory->NewStringFromStaticChars("testing")), 1781 factory->NewStringFromStaticChars("testing")),
1782 std::make_pair("var a = 'proto_str';\n" 1782 std::make_pair("var a = 'proto_str';\n"
1783 "var b = { [a]: 1, __proto__: { var : a } };\n" 1783 "var b = { [a]: 1, __proto__: { var : a } };\n"
1784 "return Object.getPrototypeOf(b).var", 1784 "return Object.getPrototypeOf(b).var",
1785 factory->NewStringFromStaticChars("proto_str")), 1785 factory->NewStringFromStaticChars("proto_str")),
1786 std::make_pair("var n = 'name';\n" 1786 std::make_pair("var n = 'name';\n"
1787 "return { [n]: 'val', get a() { return 987 } }['a'];", 1787 "return { [n]: 'val', get a() { return 987 } }['a'];",
1788 Handle<Object>(Smi::FromInt(987), isolate)), 1788 handle(Smi::FromInt(987), isolate)),
1789 }; 1789 };
1790 1790
1791 for (size_t i = 0; i < arraysize(literals); i++) { 1791 for (size_t i = 0; i < arraysize(literals); i++) {
1792 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1792 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1793 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1793 InterpreterTester tester(handles.main_isolate(), source.c_str());
1794 auto callable = tester.GetCallable<>(); 1794 auto callable = tester.GetCallable<>();
1795 1795
1796 Handle<i::Object> return_value = callable().ToHandleChecked(); 1796 Handle<i::Object> return_value = callable().ToHandleChecked();
1797 CHECK(return_value->SameValue(*literals[i].second)); 1797 CHECK(return_value->SameValue(*literals[i].second));
1798 } 1798 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); 1857 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15));
1858 } 1858 }
1859 1859
1860 1860
1861 TEST(InterpreterContextVariables) { 1861 TEST(InterpreterContextVariables) {
1862 HandleAndZoneScope handles; 1862 HandleAndZoneScope handles;
1863 i::Isolate* isolate = handles.main_isolate(); 1863 i::Isolate* isolate = handles.main_isolate();
1864 1864
1865 std::pair<const char*, Handle<Object>> context_vars[5] = { 1865 std::pair<const char*, Handle<Object>> context_vars[5] = {
1866 std::make_pair("var a; (function() { a = 1; })(); return a;", 1866 std::make_pair("var a; (function() { a = 1; })(); return a;",
1867 Handle<Object>(Smi::FromInt(1), isolate)), 1867 handle(Smi::FromInt(1), isolate)),
1868 std::make_pair("var a = 10; (function() { a; })(); return a;", 1868 std::make_pair("var a = 10; (function() { a; })(); return a;",
1869 Handle<Object>(Smi::FromInt(10), isolate)), 1869 handle(Smi::FromInt(10), isolate)),
1870 std::make_pair("var a = 20; var b = 30;\n" 1870 std::make_pair("var a = 20; var b = 30;\n"
1871 "return (function() { return a + b; })();", 1871 "return (function() { return a + b; })();",
1872 Handle<Object>(Smi::FromInt(50), isolate)), 1872 handle(Smi::FromInt(50), isolate)),
1873 std::make_pair("'use strict'; let a = 1;\n" 1873 std::make_pair("'use strict'; let a = 1;\n"
1874 "{ let b = 2; return (function() { return a + b; })(); }", 1874 "{ let b = 2; return (function() { return a + b; })(); }",
1875 Handle<Object>(Smi::FromInt(3), isolate)), 1875 handle(Smi::FromInt(3), isolate)),
1876 std::make_pair("'use strict'; let a = 10;\n" 1876 std::make_pair("'use strict'; let a = 10;\n"
1877 "{ let b = 20; var c = function() { [a, b] };\n" 1877 "{ let b = 20; var c = function() { [a, b] };\n"
1878 " return a + b; }", 1878 " return a + b; }",
1879 Handle<Object>(Smi::FromInt(30), isolate)), 1879 handle(Smi::FromInt(30), isolate)),
1880 }; 1880 };
1881 1881
1882 for (size_t i = 0; i < arraysize(context_vars); i++) { 1882 for (size_t i = 0; i < arraysize(context_vars); i++) {
1883 std::string source(InterpreterTester::SourceForBody(context_vars[i].first)); 1883 std::string source(InterpreterTester::SourceForBody(context_vars[i].first));
1884 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1884 InterpreterTester tester(handles.main_isolate(), source.c_str());
1885 auto callable = tester.GetCallable<>(); 1885 auto callable = tester.GetCallable<>();
1886 1886
1887 Handle<i::Object> return_value = callable().ToHandleChecked(); 1887 Handle<i::Object> return_value = callable().ToHandleChecked();
1888 CHECK(return_value->SameValue(*context_vars[i].second)); 1888 CHECK(return_value->SameValue(*context_vars[i].second));
1889 } 1889 }
1890 } 1890 }
1891 1891
1892 1892
1893 TEST(InterpreterContextParameters) { 1893 TEST(InterpreterContextParameters) {
1894 HandleAndZoneScope handles; 1894 HandleAndZoneScope handles;
1895 i::Isolate* isolate = handles.main_isolate(); 1895 i::Isolate* isolate = handles.main_isolate();
1896 1896
1897 std::pair<const char*, Handle<Object>> context_params[3] = { 1897 std::pair<const char*, Handle<Object>> context_params[3] = {
1898 std::make_pair("return (function() { return arg1; })();", 1898 std::make_pair("return (function() { return arg1; })();",
1899 Handle<Object>(Smi::FromInt(1), isolate)), 1899 handle(Smi::FromInt(1), isolate)),
1900 std::make_pair("(function() { arg1 = 4; })(); return arg1;", 1900 std::make_pair("(function() { arg1 = 4; })(); return arg1;",
1901 Handle<Object>(Smi::FromInt(4), isolate)), 1901 handle(Smi::FromInt(4), isolate)),
1902 std::make_pair("(function() { arg3 = arg2 - arg1; })(); return arg3;", 1902 std::make_pair("(function() { arg3 = arg2 - arg1; })(); return arg3;",
1903 Handle<Object>(Smi::FromInt(1), isolate)), 1903 handle(Smi::FromInt(1), isolate)),
1904 }; 1904 };
1905 1905
1906 for (size_t i = 0; i < arraysize(context_params); i++) { 1906 for (size_t i = 0; i < arraysize(context_params); i++) {
1907 std::string source = "function " + InterpreterTester::function_name() + 1907 std::string source = "function " + InterpreterTester::function_name() +
1908 "(arg1, arg2, arg3) {" + context_params[i].first + "}"; 1908 "(arg1, arg2, arg3) {" + context_params[i].first + "}";
1909 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1909 InterpreterTester tester(handles.main_isolate(), source.c_str());
1910 auto callable = 1910 auto callable =
1911 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); 1911 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>();
1912 1912
1913 Handle<Object> a1 = Handle<Object>(Smi::FromInt(1), isolate); 1913 Handle<Object> a1 = handle(Smi::FromInt(1), isolate);
1914 Handle<Object> a2 = Handle<Object>(Smi::FromInt(2), isolate); 1914 Handle<Object> a2 = handle(Smi::FromInt(2), isolate);
1915 Handle<Object> a3 = Handle<Object>(Smi::FromInt(3), isolate); 1915 Handle<Object> a3 = handle(Smi::FromInt(3), isolate);
1916 Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked(); 1916 Handle<i::Object> return_value = callable(a1, a2, a3).ToHandleChecked();
1917 CHECK(return_value->SameValue(*context_params[i].second)); 1917 CHECK(return_value->SameValue(*context_params[i].second));
1918 } 1918 }
1919 } 1919 }
1920 1920
1921 1921
1922 TEST(InterpreterComma) { 1922 TEST(InterpreterComma) {
1923 HandleAndZoneScope handles; 1923 HandleAndZoneScope handles;
1924 i::Isolate* isolate = handles.main_isolate(); 1924 i::Isolate* isolate = handles.main_isolate();
1925 i::Factory* factory = isolate->factory(); 1925 i::Factory* factory = isolate->factory();
1926 1926
1927 std::pair<const char*, Handle<Object>> literals[6] = { 1927 std::pair<const char*, Handle<Object>> literals[6] = {
1928 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), 1928 std::make_pair("var a; return 0, a;\n", factory->undefined_value()),
1929 std::make_pair("return 'a', 2.2, 3;\n", 1929 std::make_pair("return 'a', 2.2, 3;\n",
1930 Handle<Object>(Smi::FromInt(3), isolate)), 1930 handle(Smi::FromInt(3), isolate)),
1931 std::make_pair("return 'a', 'b', 'c';\n", 1931 std::make_pair("return 'a', 'b', 'c';\n",
1932 factory->NewStringFromStaticChars("c")), 1932 factory->NewStringFromStaticChars("c")),
1933 std::make_pair("return 3.2, 2.3, 4.5;\n", factory->NewNumber(4.5)), 1933 std::make_pair("return 3.2, 2.3, 4.5;\n", factory->NewNumber(4.5)),
1934 std::make_pair("var a = 10; return b = a, b = b+1;\n", 1934 std::make_pair("var a = 10; return b = a, b = b+1;\n",
1935 Handle<Object>(Smi::FromInt(11), isolate)), 1935 handle(Smi::FromInt(11), isolate)),
1936 std::make_pair("var a = 10; return b = a, b = b+1, b + 10;\n", 1936 std::make_pair("var a = 10; return b = a, b = b+1, b + 10;\n",
1937 Handle<Object>(Smi::FromInt(21), isolate))}; 1937 handle(Smi::FromInt(21), isolate))};
1938 1938
1939 for (size_t i = 0; i < arraysize(literals); i++) { 1939 for (size_t i = 0; i < arraysize(literals); i++) {
1940 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1940 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1941 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1941 InterpreterTester tester(handles.main_isolate(), source.c_str());
1942 auto callable = tester.GetCallable<>(); 1942 auto callable = tester.GetCallable<>();
1943 1943
1944 Handle<i::Object> return_value = callable().ToHandleChecked(); 1944 Handle<i::Object> return_value = callable().ToHandleChecked();
1945 CHECK(return_value->SameValue(*literals[i].second)); 1945 CHECK(return_value->SameValue(*literals[i].second));
1946 } 1946 }
1947 } 1947 }
1948 1948
1949 1949
1950 TEST(InterpreterLogicalOr) { 1950 TEST(InterpreterLogicalOr) {
1951 HandleAndZoneScope handles; 1951 HandleAndZoneScope handles;
1952 i::Isolate* isolate = handles.main_isolate(); 1952 i::Isolate* isolate = handles.main_isolate();
1953 i::Factory* factory = isolate->factory(); 1953 i::Factory* factory = isolate->factory();
1954 1954
1955 std::pair<const char*, Handle<Object>> literals[5] = { 1955 std::pair<const char*, Handle<Object>> literals[5] = {
1956 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()), 1956 std::make_pair("var a, b; return a || b;\n", factory->undefined_value()),
1957 std::make_pair("var a, b = 10; return a || b;\n", 1957 std::make_pair("var a, b = 10; return a || b;\n",
1958 Handle<Object>(Smi::FromInt(10), isolate)), 1958 handle(Smi::FromInt(10), isolate)),
1959 std::make_pair("var a = '0', b = 10; return a || b;\n", 1959 std::make_pair("var a = '0', b = 10; return a || b;\n",
1960 factory->NewStringFromStaticChars("0")), 1960 factory->NewStringFromStaticChars("0")),
1961 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)), 1961 std::make_pair("return 0 || 3.2;\n", factory->NewNumber(3.2)),
1962 std::make_pair("return 'a' || 0;\n", 1962 std::make_pair("return 'a' || 0;\n",
1963 factory->NewStringFromStaticChars("a"))}; 1963 factory->NewStringFromStaticChars("a"))};
1964 1964
1965 for (size_t i = 0; i < arraysize(literals); i++) { 1965 for (size_t i = 0; i < arraysize(literals); i++) {
1966 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1966 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1967 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1967 InterpreterTester tester(handles.main_isolate(), source.c_str());
1968 auto callable = tester.GetCallable<>(); 1968 auto callable = tester.GetCallable<>();
1969 1969
1970 Handle<i::Object> return_value = callable().ToHandleChecked(); 1970 Handle<i::Object> return_value = callable().ToHandleChecked();
1971 CHECK(return_value->SameValue(*literals[i].second)); 1971 CHECK(return_value->SameValue(*literals[i].second));
1972 } 1972 }
1973 } 1973 }
1974 1974
1975 1975
1976 TEST(InterpreterLogicalAnd) { 1976 TEST(InterpreterLogicalAnd) {
1977 HandleAndZoneScope handles; 1977 HandleAndZoneScope handles;
1978 i::Isolate* isolate = handles.main_isolate(); 1978 i::Isolate* isolate = handles.main_isolate();
1979 i::Factory* factory = isolate->factory(); 1979 i::Factory* factory = isolate->factory();
1980 1980
1981 std::pair<const char*, Handle<Object>> literals[7] = { 1981 std::pair<const char*, Handle<Object>> literals[7] = {
1982 std::make_pair("var a, b = 10; return a && b;\n", 1982 std::make_pair("var a, b = 10; return a && b;\n",
1983 factory->undefined_value()), 1983 factory->undefined_value()),
1984 std::make_pair("var a = 0, b = 10; return a && b / a;\n", 1984 std::make_pair("var a = 0, b = 10; return a && b / a;\n",
1985 Handle<Object>(Smi::FromInt(0), isolate)), 1985 handle(Smi::FromInt(0), isolate)),
1986 std::make_pair("var a = '0', b = 10; return a && b;\n", 1986 std::make_pair("var a = '0', b = 10; return a && b;\n",
1987 Handle<Object>(Smi::FromInt(10), isolate)), 1987 handle(Smi::FromInt(10), isolate)),
1988 std::make_pair("return 0.0 && 3.2;\n", 1988 std::make_pair("return 0.0 && 3.2;\n",
1989 Handle<Object>(Smi::FromInt(0), isolate)), 1989 handle(Smi::FromInt(0), isolate)),
1990 std::make_pair("return 'a' && 'b';\n", 1990 std::make_pair("return 'a' && 'b';\n",
1991 factory->NewStringFromStaticChars("b")), 1991 factory->NewStringFromStaticChars("b")),
1992 std::make_pair("return 'a' && 0 || 'b', 'c';\n", 1992 std::make_pair("return 'a' && 0 || 'b', 'c';\n",
1993 factory->NewStringFromStaticChars("c")), 1993 factory->NewStringFromStaticChars("c")),
1994 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n", 1994 std::make_pair("var x = 1, y = 3; return x && 0 + 1 || y;\n",
1995 Handle<Object>(Smi::FromInt(1), isolate))}; 1995 handle(Smi::FromInt(1), isolate))};
1996 1996
1997 for (size_t i = 0; i < arraysize(literals); i++) { 1997 for (size_t i = 0; i < arraysize(literals); i++) {
1998 std::string source(InterpreterTester::SourceForBody(literals[i].first)); 1998 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1999 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1999 InterpreterTester tester(handles.main_isolate(), source.c_str());
2000 auto callable = tester.GetCallable<>(); 2000 auto callable = tester.GetCallable<>();
2001 2001
2002 Handle<i::Object> return_value = callable().ToHandleChecked(); 2002 Handle<i::Object> return_value = callable().ToHandleChecked();
2003 CHECK(return_value->SameValue(*literals[i].second)); 2003 CHECK(return_value->SameValue(*literals[i].second));
2004 } 2004 }
2005 } 2005 }
(...skipping 30 matching lines...) Expand all
2036 TEST(InterpreterThrow) { 2036 TEST(InterpreterThrow) {
2037 HandleAndZoneScope handles; 2037 HandleAndZoneScope handles;
2038 i::Isolate* isolate = handles.main_isolate(); 2038 i::Isolate* isolate = handles.main_isolate();
2039 i::Factory* factory = isolate->factory(); 2039 i::Factory* factory = isolate->factory();
2040 2040
2041 // TODO(rmcilroy): modify tests when we have real try catch support. 2041 // TODO(rmcilroy): modify tests when we have real try catch support.
2042 std::pair<const char*, Handle<Object>> throws[6] = { 2042 std::pair<const char*, Handle<Object>> throws[6] = {
2043 std::make_pair("throw undefined;\n", 2043 std::make_pair("throw undefined;\n",
2044 factory->undefined_value()), 2044 factory->undefined_value()),
2045 std::make_pair("throw 1;\n", 2045 std::make_pair("throw 1;\n",
2046 Handle<Object>(Smi::FromInt(1), isolate)), 2046 handle(Smi::FromInt(1), isolate)),
2047 std::make_pair("throw 'Error';\n", 2047 std::make_pair("throw 'Error';\n",
2048 factory->NewStringFromStaticChars("Error")), 2048 factory->NewStringFromStaticChars("Error")),
2049 std::make_pair("var a = true; if (a) { throw 'Error'; }\n", 2049 std::make_pair("var a = true; if (a) { throw 'Error'; }\n",
2050 factory->NewStringFromStaticChars("Error")), 2050 factory->NewStringFromStaticChars("Error")),
2051 std::make_pair("var a = false; if (a) { throw 'Error'; }\n", 2051 std::make_pair("var a = false; if (a) { throw 'Error'; }\n",
2052 factory->undefined_value()), 2052 factory->undefined_value()),
2053 std::make_pair("throw 'Error1'; throw 'Error2'\n", 2053 std::make_pair("throw 'Error1'; throw 'Error2'\n",
2054 factory->NewStringFromStaticChars("Error1")), 2054 factory->NewStringFromStaticChars("Error1")),
2055 }; 2055 };
2056 2056
2057 const char* try_wrapper = 2057 const char* try_wrapper =
2058 "(function() { try { f(); } catch(e) { return e; }})()"; 2058 "(function() { try { f(); } catch(e) { return e; }})()";
2059 2059
2060 for (size_t i = 0; i < arraysize(throws); i++) { 2060 for (size_t i = 0; i < arraysize(throws); i++) {
2061 std::string source(InterpreterTester::SourceForBody(throws[i].first)); 2061 std::string source(InterpreterTester::SourceForBody(throws[i].first));
2062 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2062 InterpreterTester tester(handles.main_isolate(), source.c_str());
2063 tester.GetCallable<>(); 2063 tester.GetCallable<>();
2064 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); 2064 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper));
2065 CHECK(thrown_obj->SameValue(*throws[i].second)); 2065 CHECK(thrown_obj->SameValue(*throws[i].second));
2066 } 2066 }
2067 } 2067 }
2068
2069
2070 TEST(InterpreterCountOperators) {
2071 HandleAndZoneScope handles;
2072 i::Isolate* isolate = handles.main_isolate();
2073 i::Factory* factory = isolate->factory();
2074
2075 std::pair<const char*, Handle<Object>> count_ops[16] = {
2076 std::make_pair("var a = 1; return ++a;",
2077 handle(Smi::FromInt(2), isolate)),
2078 std::make_pair("var a = 1; return a++;",
2079 handle(Smi::FromInt(1), isolate)),
2080 std::make_pair("var a = 5; return --a;",
2081 handle(Smi::FromInt(4), isolate)),
2082 std::make_pair("var a = 5; return a--;",
2083 handle(Smi::FromInt(5), isolate)),
2084 std::make_pair("var a = 5.2; return --a;",
2085 factory->NewHeapNumber(4.2)),
2086 std::make_pair("var a = 'string'; return ++a;",
2087 factory->nan_value()),
2088 std::make_pair("var a = 'string'; return a--;",
2089 factory->nan_value()),
2090 std::make_pair("var a = true; return ++a;",
2091 handle(Smi::FromInt(2), isolate)),
2092 std::make_pair("var a = false; return a--;",
2093 handle(Smi::FromInt(0), isolate)),
2094 std::make_pair("var a = { val: 11 }; return ++a.val;",
2095 handle(Smi::FromInt(12), isolate)),
2096 std::make_pair("var a = { val: 11 }; return a.val--;",
2097 handle(Smi::FromInt(11), isolate)),
2098 std::make_pair("var a = { val: 11 }; return ++a.val;",
2099 handle(Smi::FromInt(12), isolate)),
2100 std::make_pair("var name = 'val'; var a = { val: 22 }; return --a[name];",
2101 handle(Smi::FromInt(21), isolate)),
2102 std::make_pair("var name = 'val'; var a = { val: 22 }; return a[name]++;",
2103 handle(Smi::FromInt(22), isolate)),
2104 std::make_pair("var a = 1; (function() { a = 2 })(); return ++a;",
2105 handle(Smi::FromInt(3), isolate)),
2106 std::make_pair("var a = 1; (function() { a = 2 })(); return a--;",
2107 handle(Smi::FromInt(2), isolate)),
2108 };
2109
2110 for (size_t i = 0; i < arraysize(count_ops); i++) {
2111 std::string source(InterpreterTester::SourceForBody(count_ops[i].first));
2112 InterpreterTester tester(handles.main_isolate(), source.c_str());
2113 auto callable = tester.GetCallable<>();
2114
2115 Handle<i::Object> return_value = callable().ToHandleChecked();
2116 CHECK(return_value->SameValue(*count_ops[i].second));
2117 }
2118 }
2119
2120
2121 TEST(InterpreterGlobalCountOperators) {
2122 HandleAndZoneScope handles;
2123 i::Isolate* isolate = handles.main_isolate();
2124
2125 std::pair<const char*, Handle<Object>> count_ops[6] = {
2126 std::make_pair("var global = 100;function f(){ return ++global; }",
2127 handle(Smi::FromInt(101), isolate)),
2128 std::make_pair("var global = 100; function f(){ return --global; }",
2129 handle(Smi::FromInt(99), isolate)),
2130 std::make_pair("var global = 100; function f(){ return global++; }",
2131 handle(Smi::FromInt(100), isolate)),
2132 std::make_pair("unallocated = 200; function f(){ return ++unallocated; }",
2133 handle(Smi::FromInt(201), isolate)),
2134 std::make_pair("unallocated = 200; function f(){ return --unallocated; }",
2135 handle(Smi::FromInt(199), isolate)),
2136 std::make_pair("unallocated = 200; function f(){ return unallocated++; }",
2137 handle(Smi::FromInt(200), isolate)),
2138 };
2139
2140 for (size_t i = 0; i < arraysize(count_ops); i++) {
2141 InterpreterTester tester(handles.main_isolate(), count_ops[i].first);
2142 auto callable = tester.GetCallable<>();
2143
2144 Handle<i::Object> return_value = callable().ToHandleChecked();
2145 CHECK(return_value->SameValue(*count_ops[i].second));
2146 }
2147 }
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