OLD | NEW |
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 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1721 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
1722 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1722 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
1723 auto callable = tester.GetCallable<>(); | 1723 auto callable = tester.GetCallable<>(); |
1724 | 1724 |
1725 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1725 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1726 CHECK(return_value->SameValue(*literals[i].second)); | 1726 CHECK(return_value->SameValue(*literals[i].second)); |
1727 } | 1727 } |
1728 } | 1728 } |
1729 | 1729 |
1730 | 1730 |
| 1731 TEST(InterpreterConstruct) { |
| 1732 HandleAndZoneScope handles; |
| 1733 |
| 1734 std::string source( |
| 1735 "function counter() { this.count = 0; }\n" |
| 1736 "function " + |
| 1737 InterpreterTester::function_name() + |
| 1738 "() {\n" |
| 1739 " var c = new counter();\n" |
| 1740 " return c.count;\n" |
| 1741 "}"); |
| 1742 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1743 auto callable = tester.GetCallable<>(); |
| 1744 |
| 1745 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1746 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0)); |
| 1747 } |
| 1748 |
| 1749 |
| 1750 TEST(InterpreterConstructWithArgument) { |
| 1751 HandleAndZoneScope handles; |
| 1752 |
| 1753 std::string source( |
| 1754 "function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
| 1755 "function " + |
| 1756 InterpreterTester::function_name() + |
| 1757 "() {\n" |
| 1758 " var c = new counter(3);\n" |
| 1759 " return c.x;\n" |
| 1760 "}"); |
| 1761 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1762 auto callable = tester.GetCallable<>(); |
| 1763 |
| 1764 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1765 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
| 1766 } |
| 1767 |
| 1768 |
| 1769 TEST(InterpreterConstructWithArguments) { |
| 1770 HandleAndZoneScope handles; |
| 1771 |
| 1772 std::string source( |
| 1773 "function counter(arg0, arg1) {\n" |
| 1774 " this.count = 7; this.x = arg0; this.y = arg1;\n" |
| 1775 "}\n" |
| 1776 "function " + |
| 1777 InterpreterTester::function_name() + |
| 1778 "() {\n" |
| 1779 " var c = new counter(3, 5);\n" |
| 1780 " return c.count + c.x + c.y;\n" |
| 1781 "}"); |
| 1782 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1783 auto callable = tester.GetCallable<>(); |
| 1784 |
| 1785 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1786 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
| 1787 } |
| 1788 |
| 1789 |
1731 TEST(InterpreterComma) { | 1790 TEST(InterpreterComma) { |
1732 HandleAndZoneScope handles; | 1791 HandleAndZoneScope handles; |
1733 i::Isolate* isolate = handles.main_isolate(); | 1792 i::Isolate* isolate = handles.main_isolate(); |
1734 i::Factory* factory = isolate->factory(); | 1793 i::Factory* factory = isolate->factory(); |
1735 | 1794 |
1736 std::pair<const char*, Handle<Object>> literals[6] = { | 1795 std::pair<const char*, Handle<Object>> literals[6] = { |
1737 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), | 1796 std::make_pair("var a; return 0, a;\n", factory->undefined_value()), |
1738 std::make_pair("return 'a', 2.2, 3;\n", | 1797 std::make_pair("return 'a', 2.2, 3;\n", |
1739 Handle<Object>(Smi::FromInt(3), isolate)), | 1798 Handle<Object>(Smi::FromInt(3), isolate)), |
1740 std::make_pair("return 'a', 'b', 'c';\n", | 1799 std::make_pair("return 'a', 'b', 'c';\n", |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 | 1892 |
1834 // TODO(rmcilroy): modify tests when we have real try finally support. | 1893 // TODO(rmcilroy): modify tests when we have real try finally support. |
1835 std::string source(InterpreterTester::SourceForBody( | 1894 std::string source(InterpreterTester::SourceForBody( |
1836 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); | 1895 "var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;")); |
1837 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1896 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
1838 auto callable = tester.GetCallable<>(); | 1897 auto callable = tester.GetCallable<>(); |
1839 | 1898 |
1840 Handle<Object> return_val = callable().ToHandleChecked(); | 1899 Handle<Object> return_val = callable().ToHandleChecked(); |
1841 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); | 1900 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); |
1842 } | 1901 } |
OLD | NEW |