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 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 | 1718 |
1719 for (size_t i = 0; i < arraysize(literals); i++) { | 1719 for (size_t i = 0; i < arraysize(literals); i++) { |
1720 std::string source(InterpreterTester::SourceForBody(literals[i].first)); | 1720 std::string source(InterpreterTester::SourceForBody(literals[i].first)); |
1721 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1721 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
1722 auto callable = tester.GetCallable<>(); | 1722 auto callable = tester.GetCallable<>(); |
1723 | 1723 |
1724 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1724 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1725 CHECK(return_value->SameValue(*literals[i].second)); | 1725 CHECK(return_value->SameValue(*literals[i].second)); |
1726 } | 1726 } |
1727 } | 1727 } |
| 1728 |
| 1729 |
| 1730 TEST(InterpreterConstruct) { |
| 1731 HandleAndZoneScope handles; |
| 1732 |
| 1733 std::string source( |
| 1734 "function counter() { this.count = 0; }\n" |
| 1735 "function " + |
| 1736 InterpreterTester::function_name() + |
| 1737 "() {\n" |
| 1738 " var c = new counter();\n" |
| 1739 " return c.count;\n" |
| 1740 "}"); |
| 1741 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1742 auto callable = tester.GetCallable<>(); |
| 1743 |
| 1744 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1745 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0)); |
| 1746 } |
| 1747 |
| 1748 |
| 1749 TEST(InterpreterConstructWithArgument) { |
| 1750 HandleAndZoneScope handles; |
| 1751 |
| 1752 std::string source( |
| 1753 "function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
| 1754 "function " + |
| 1755 InterpreterTester::function_name() + |
| 1756 "() {\n" |
| 1757 " var c = new counter(3);\n" |
| 1758 " return c.x;\n" |
| 1759 "}"); |
| 1760 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1761 auto callable = tester.GetCallable<>(); |
| 1762 |
| 1763 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1764 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
| 1765 } |
| 1766 |
| 1767 |
| 1768 TEST(InterpreterConstructWithArguments) { |
| 1769 HandleAndZoneScope handles; |
| 1770 |
| 1771 std::string source( |
| 1772 "function counter(arg0, arg1) {\n" |
| 1773 " this.count = 7; this.x = arg0; this.y = arg1;\n" |
| 1774 "}\n" |
| 1775 "function " + |
| 1776 InterpreterTester::function_name() + |
| 1777 "() {\n" |
| 1778 " var c = new counter(3, 5);\n" |
| 1779 " return c.count + c.x + c.y;\n" |
| 1780 "}"); |
| 1781 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1782 auto callable = tester.GetCallable<>(); |
| 1783 |
| 1784 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1785 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
| 1786 } |
OLD | NEW |