| 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 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 "function " + InterpreterTester::function_name() + "(a) {\n" | 1630 "function " + InterpreterTester::function_name() + "(a) {\n" |
| 1631 " return (function(x){ return x + 2; })(a);\n" | 1631 " return (function(x){ return x + 2; })(a);\n" |
| 1632 "}"); | 1632 "}"); |
| 1633 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1633 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1634 auto callable = tester.GetCallable<Handle<Object>>(); | 1634 auto callable = tester.GetCallable<Handle<Object>>(); |
| 1635 | 1635 |
| 1636 Handle<i::Object> return_val = callable( | 1636 Handle<i::Object> return_val = callable( |
| 1637 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); | 1637 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); |
| 1638 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); | 1638 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
| 1639 } | 1639 } |
| 1640 |
| 1641 |
| 1642 TEST(InterpreterConstruct) { |
| 1643 HandleAndZoneScope handles; |
| 1644 |
| 1645 std::string source( |
| 1646 "function counter() { this.count = 0; }\n" |
| 1647 "function " + |
| 1648 InterpreterTester::function_name() + |
| 1649 "() {\n" |
| 1650 " var c = new counter();\n" |
| 1651 " return c.count;\n" |
| 1652 "}"); |
| 1653 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1654 auto callable = tester.GetCallable<>(); |
| 1655 |
| 1656 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1657 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0)); |
| 1658 } |
| 1659 |
| 1660 |
| 1661 TEST(InterpreterConstructWithArgument) { |
| 1662 HandleAndZoneScope handles; |
| 1663 |
| 1664 std::string source( |
| 1665 "function counter(arg0) { this.count = 17; this.x = arg0; }\n" |
| 1666 "function " + |
| 1667 InterpreterTester::function_name() + |
| 1668 "() {\n" |
| 1669 " var c = new counter(3);\n" |
| 1670 " return c.x;\n" |
| 1671 "}"); |
| 1672 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1673 auto callable = tester.GetCallable<>(); |
| 1674 |
| 1675 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1676 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
| 1677 } |
| 1678 |
| 1679 |
| 1680 TEST(InterpreterConstructWithArguments) { |
| 1681 HandleAndZoneScope handles; |
| 1682 |
| 1683 std::string source( |
| 1684 "function counter(arg0, arg1) { this.count = 17; this.x = arg0; this.y = " |
| 1685 "arg1; }\n" |
| 1686 "function " + |
| 1687 InterpreterTester::function_name() + |
| 1688 "() {\n" |
| 1689 " var c = new counter(3, 4);\n" |
| 1690 " return c.y;\n" |
| 1691 "}"); |
| 1692 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1693 auto callable = tester.GetCallable<>(); |
| 1694 |
| 1695 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1696 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(4)); |
| 1697 } |
| OLD | NEW |