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

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

Issue 1400753003: [Interpreter] Add array literal support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_literal
Patch Set: Rebase 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 static Handle<Object> NewObject(const char* script) { 96 static Handle<Object> NewObject(const char* script) {
97 return v8::Utils::OpenHandle(*CompileRun(script)); 97 return v8::Utils::OpenHandle(*CompileRun(script));
98 } 98 }
99 99
100 static Handle<String> GetName(Isolate* isolate, const char* name) { 100 static Handle<String> GetName(Isolate* isolate, const char* name) {
101 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); 101 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name);
102 return isolate->factory()->string_table()->LookupString(isolate, result); 102 return isolate->factory()->string_table()->LookupString(isolate, result);
103 } 103 }
104 104
105 static std::string SourceForBody(const char* body) {
106 return "function " + function_name() + "() {\n" + std::string(body) + "\n}";
107 }
108
105 static std::string function_name() { 109 static std::string function_name() {
106 return std::string(kFunctionName); 110 return std::string(kFunctionName);
107 } 111 }
108 112
109 private: 113 private:
110 Isolate* isolate_; 114 Isolate* isolate_;
111 const char* source_; 115 const char* source_;
112 MaybeHandle<BytecodeArray> bytecode_; 116 MaybeHandle<BytecodeArray> bytecode_;
113 MaybeHandle<TypeFeedbackVector> feedback_vector_; 117 MaybeHandle<TypeFeedbackVector> feedback_vector_;
114 118
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 "function " + InterpreterTester::function_name() + "(a) {\n" 1634 "function " + InterpreterTester::function_name() + "(a) {\n"
1631 " return (function(x){ return x + 2; })(a);\n" 1635 " return (function(x){ return x + 2; })(a);\n"
1632 "}"); 1636 "}");
1633 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1637 InterpreterTester tester(handles.main_isolate(), source.c_str());
1634 auto callable = tester.GetCallable<Handle<Object>>(); 1638 auto callable = tester.GetCallable<Handle<Object>>();
1635 1639
1636 Handle<i::Object> return_val = callable( 1640 Handle<i::Object> return_val = callable(
1637 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); 1641 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked();
1638 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); 1642 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5));
1639 } 1643 }
1644
1645
1646 TEST(InterpreterArrayLiterals) {
1647 HandleAndZoneScope handles;
1648 i::Isolate* isolate = handles.main_isolate();
1649 i::Factory* factory = isolate->factory();
1650
1651 std::pair<const char*, Handle<Object>> literals[6] = {
1652 std::make_pair("return [][0];\n",
1653 factory->undefined_value()),
1654 std::make_pair("return [1, 3, 2][1];\n",
1655 Handle<Object>(Smi::FromInt(3), isolate)),
1656 std::make_pair("return ['a', 'b', 'c'][2];\n",
1657 factory->NewStringFromStaticChars("c")),
1658 std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n",
1659 Handle<Object>(Smi::FromInt(102), isolate)),
1660 std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n",
1661 factory->NewStringFromStaticChars("a")),
1662 std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n",
1663 factory->NewStringFromStaticChars("test"))
1664 };
1665
1666 for (size_t i = 0; i < arraysize(literals); i++) {
1667 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1668 InterpreterTester tester(handles.main_isolate(), source.c_str());
1669 auto callable = tester.GetCallable<>();
1670
1671 Handle<i::Object> return_value = callable().ToHandleChecked();
1672 CHECK(return_value->SameValue(*literals[i].second));
1673 }
1674 }
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