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

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

Issue 1420503002: [Interpreter] Add support for compound expressions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 years, 1 month 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 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 }; 2138 };
2139 2139
2140 for (size_t i = 0; i < arraysize(count_ops); i++) { 2140 for (size_t i = 0; i < arraysize(count_ops); i++) {
2141 InterpreterTester tester(handles.main_isolate(), count_ops[i].first); 2141 InterpreterTester tester(handles.main_isolate(), count_ops[i].first);
2142 auto callable = tester.GetCallable<>(); 2142 auto callable = tester.GetCallable<>();
2143 2143
2144 Handle<i::Object> return_value = callable().ToHandleChecked(); 2144 Handle<i::Object> return_value = callable().ToHandleChecked();
2145 CHECK(return_value->SameValue(*count_ops[i].second)); 2145 CHECK(return_value->SameValue(*count_ops[i].second));
2146 } 2146 }
2147 } 2147 }
2148
2149
2150 TEST(InterpreterCompoundExpressions) {
2151 HandleAndZoneScope handles;
2152 i::Isolate* isolate = handles.main_isolate();
2153 i::Factory* factory = isolate->factory();
2154
2155 std::pair<const char*, Handle<Object>> compound_expr[5] = {
2156 std::make_pair("var a = 1; a += 2; return a;",
2157 Handle<Object>(Smi::FromInt(3), isolate)),
2158 std::make_pair("var a = 10; a /= 2; return a;",
2159 Handle<Object>(Smi::FromInt(5), isolate)),
2160 std::make_pair("var a = 'test'; a += 'ing'; return a;",
2161 factory->NewStringFromStaticChars("testing")),
2162 std::make_pair("var a = { val: 2 }; a.val *= 2; return a.val;",
2163 Handle<Object>(Smi::FromInt(4), isolate)),
2164 std::make_pair("var a = 1; (function f() { a = 2; })(); a += 24;"
2165 "return a;",
2166 Handle<Object>(Smi::FromInt(26), isolate)),
2167 };
2168
2169 for (size_t i = 0; i < arraysize(compound_expr); i++) {
2170 std::string source(
2171 InterpreterTester::SourceForBody(compound_expr[i].first));
2172 InterpreterTester tester(handles.main_isolate(), source.c_str());
2173 auto callable = tester.GetCallable<>();
2174
2175 Handle<i::Object> return_value = callable().ToHandleChecked();
2176 CHECK(return_value->SameValue(*compound_expr[i].second));
2177 }
2178 }
2179
2180
2181 TEST(InterpreterGlobalCompoundExpressions) {
2182 HandleAndZoneScope handles;
2183 i::Isolate* isolate = handles.main_isolate();
2184
2185 std::pair<const char*, Handle<Object>> compound_expr[2] = {
2186 std::make_pair("var global = 100;"
2187 "function f() { global += 20; return global; }",
2188 Handle<Object>(Smi::FromInt(120), isolate)),
2189 std::make_pair("unallocated = 100;"
2190 "function f() { unallocated -= 20; return unallocated; }",
2191 Handle<Object>(Smi::FromInt(80), isolate)),
2192 };
2193
2194 for (size_t i = 0; i < arraysize(compound_expr); i++) {
2195 InterpreterTester tester(handles.main_isolate(), compound_expr[i].first);
2196 auto callable = tester.GetCallable<>();
2197
2198 Handle<i::Object> return_value = callable().ToHandleChecked();
2199 CHECK(return_value->SameValue(*compound_expr[i].second));
2200 }
2201 }
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