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 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1546 .CallRuntime(Runtime::kAdd, Register(0), 2) |
1547 .Return(); | 1547 .Return(); |
1548 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1548 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
1549 | 1549 |
1550 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1550 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
1551 auto callable = tester.GetCallable<>(); | 1551 auto callable = tester.GetCallable<>(); |
1552 | 1552 |
1553 Handle<Object> return_val = callable().ToHandleChecked(); | 1553 Handle<Object> return_val = callable().ToHandleChecked(); |
1554 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1554 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
1555 } | 1555 } |
| 1556 |
| 1557 |
| 1558 TEST(InterpreterFunctionLiteral) { |
| 1559 HandleAndZoneScope handles; |
| 1560 |
| 1561 // Test calling a function literal. |
| 1562 std::string source( |
| 1563 "function " + InterpreterTester::function_name() + "(a) {\n" |
| 1564 " return (function(x){ return x + 2; })(a);\n" |
| 1565 "}"); |
| 1566 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 1567 auto callable = tester.GetCallable<Handle<Object>>(); |
| 1568 |
| 1569 Handle<i::Object> return_val = callable( |
| 1570 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); |
| 1571 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); |
| 1572 } |
OLD | NEW |