Chromium Code Reviews| 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)); |
| + } |
| +} |