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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index bed394b1f3ca5d5fa977b203d5b8be9952752ba1..826c02e0b8d9d0af706fc00c99e25a92ce8c496d 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -102,6 +102,10 @@ class InterpreterTester {
return isolate->factory()->string_table()->LookupString(isolate, result);
}
+ static std::string SourceForBody(const char* body) {
+ return "function " + function_name() + "() {\n" + std::string(body) + "\n}";
+ }
+
static std::string function_name() {
return std::string(kFunctionName);
}
@@ -1570,3 +1574,32 @@ TEST(InterpreterFunctionLiteral) {
Handle<Smi>(Smi::FromInt(3), handles.main_isolate())).ToHandleChecked();
CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(5));
}
+
+
+TEST(InterpreterArrayLiterals) {
+ HandleAndZoneScope handles;
+ i::Isolate* isolate = handles.main_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::pair<const char*, Handle<Object>> literals[5] = {
+ 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.
+ Handle<Object>(Smi::FromInt(3), isolate)),
+ std::make_pair("return ['a', 'b', 'c'][2];\n",
+ factory->NewStringFromStaticChars("c")),
+ std::make_pair("var a = 100; return [a, a + 1, a + 2, a + 3][2];\n",
+ Handle<Object>(Smi::FromInt(102), isolate)),
+ std::make_pair("return [[1, 2, 3], ['a', 'b', 'c']][1][0];\n",
+ factory->NewStringFromStaticChars("a")),
+ std::make_pair("var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];\n",
+ factory->NewStringFromStaticChars("test"))
+ };
+
+ for (size_t i = 0; i < arraysize(literals); i++) {
+ std::string source(InterpreterTester::SourceForBody(literals[i].first));
+ InterpreterTester tester(handles.main_isolate(), source.c_str());
+ auto callable = tester.GetCallable<>();
+
+ Handle<i::Object> return_value = callable().ToHandleChecked();
+ CHECK(return_value->SameValue(*literals[i].second));
+ }
+}
« 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