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 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1613 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1613 .CallRuntime(Runtime::kAdd, Register(0), 2) |
1614 .Return(); | 1614 .Return(); |
1615 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1615 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1616 | 1616 |
1617 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1617 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1618 auto callable = tester.GetCallable<>(); | 1618 auto callable = tester.GetCallable<>(); |
1619 | 1619 |
1620 Handle<Object> return_val = callable().ToHandleChecked(); | 1620 Handle<Object> return_val = callable().ToHandleChecked(); |
1621 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1621 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
1622 } | 1622 } |
| 1623 |
| 1624 |
| 1625 TEST(InterpreterFunctionLiteral) { |
| 1626 HandleAndZoneScope handles; |
| 1627 |
| 1628 // Test calling a function literal. |
| 1629 std::string source( |
| 1630 "function " + InterpreterTester::function_name() + "(a) {\n" |
| 1631 " return (function(x){ return x + 2; })(a);\n" |
| 1632 "}"); |
| 1633 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1634 auto callable = tester.GetCallable<Handle<Object>>(); |
| 1635 |
| 1636 Handle<i::Object> return_val = callable( |
| 1637 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); |
| 1638 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
| 1639 } |
OLD | NEW |