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

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: 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
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 "function " + InterpreterTester::function_name() + "(a) {\n" 1567 "function " + InterpreterTester::function_name() + "(a) {\n"
1564 " return (function(x){ return x + 2; })(a);\n" 1568 " return (function(x){ return x + 2; })(a);\n"
1565 "}"); 1569 "}");
1566 InterpreterTester tester(handles.main_isolate(), source.c_str()); 1570 InterpreterTester tester(handles.main_isolate(), source.c_str());
1567 auto callable = tester.GetCallable<Handle<Object>>(); 1571 auto callable = tester.GetCallable<Handle<Object>>();
1568 1572
1569 Handle<i::Object> return_val = callable( 1573 Handle<i::Object> return_val = callable(
1570 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked(); 1574 Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked();
1571 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5)); 1575 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5));
1572 } 1576 }
1577
1578
1579 TEST(InterpreterArrayLiterals) {
1580 HandleAndZoneScope handles;
1581 i::Isolate* isolate = handles.main_isolate();
1582 i::Factory* factory = isolate->factory();
1583
1584 std::pair<const char*, Handle<Object>> literals[5] = {
1585 std::make_pair("return [1, 3, 2][1];\n",
oth 2015/10/09 13:07:34 Coverage for the empty array case would be good.
rmcilroy 2015/10/09 13:14:02 Good plan, done.
1586 Handle<Object>(Smi::FromInt(3), isolate)),
1587 std::make_pair("return ['a', 'b', 'c'][2];\n",
1588 factory->NewStringFromStaticChars("c")),
1589 std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n",
1590 Handle<Object>(Smi::FromInt(102), isolate)),
1591 std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n",
1592 factory->NewStringFromStaticChars("a")),
1593 std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n",
1594 factory->NewStringFromStaticChars("test"))
1595 };
1596
1597 for (size_t i = 0; i < arraysize(literals); i++) {
1598 std::string source(InterpreterTester::SourceForBody(literals[i].first));
1599 InterpreterTester tester(handles.main_isolate(), source.c_str());
1600 auto callable = tester.GetCallable<>();
1601
1602 Handle<i::Object> return_value = callable().ToHandleChecked();
1603 CHECK(return_value->SameValue(*literals[i].second));
1604 }
1605 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698