Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1396693003: [Interpreter] Add function literal support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_newcontext
Patch Set: Review comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698