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

Side by Side Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1503963002: [Interpreter] Adds wide variant of CreateLiterals. Adds CreateLiterals to BytecodeGraphBuilder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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 // TODO(jochen): Remove this after the setting is turned on globally. 5 // TODO(jochen): Remove this after the setting is turned on globally.
6 #define V8_IMMINENT_DEPRECATION_WARNINGS 6 #define V8_IMMINENT_DEPRECATION_WARNINGS
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "src/compiler/pipeline.h" 10 #include "src/compiler/pipeline.h"
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 SNPrintF(script, "%s", snippets[i].code_snippet); 1179 SNPrintF(script, "%s", snippets[i].code_snippet);
1180 1180
1181 BytecodeGraphTester tester(isolate, zone, script.start(), "*"); 1181 BytecodeGraphTester tester(isolate, zone, script.start(), "*");
1182 auto callable = tester.GetCallable<Handle<Object>>("f"); 1182 auto callable = tester.GetCallable<Handle<Object>>("f");
1183 Handle<Object> return_value = 1183 Handle<Object> return_value =
1184 callable(snippets[i].parameter(0)).ToHandleChecked(); 1184 callable(snippets[i].parameter(0)).ToHandleChecked();
1185 CHECK(return_value->SameValue(*snippets[i].return_value())); 1185 CHECK(return_value->SameValue(*snippets[i].return_value()));
1186 } 1186 }
1187 } 1187 }
1188 1188
1189
1190 TEST(BytecodeGraphBuilderRegExpLiterals) {
1191 HandleAndZoneScope scope;
1192 Isolate* isolate = scope.main_isolate();
1193 Zone* zone = scope.main_zone();
1194 Factory* factory = isolate->factory();
1195
1196 ExpectedSnippet<0> snippets[] = {
1197 {"return /abd/.exec('cccabbdd');", {factory->null_value()}},
1198 {"return /ab+d/.exec('cccabbdd')[0];",
1199 {factory->NewStringFromStaticChars("abbd")}},
1200 {"return /ab+d/.exec('cccabbdd')[1];", {factory->undefined_value()}},
1201 {"return /AbC/i.exec('ssaBC')[0];",
1202 {factory->NewStringFromStaticChars("aBC")}},
1203 {"return 'ssaBC'.match(/AbC/i)[0];",
1204 {factory->NewStringFromStaticChars("aBC")}},
1205 {"return 'ssaBCtAbC'.match(/(AbC)/gi)[1];",
1206 {factory->NewStringFromStaticChars("AbC")}},
1207 };
1208
1209 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
1210 for (size_t i = 0; i < num_snippets; i++) {
1211 ScopedVector<char> script(1024);
1212 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1213 snippets[i].code_snippet, kFunctionName);
1214
1215 BytecodeGraphTester tester(isolate, zone, script.start());
1216 auto callable = tester.GetCallable<>();
1217 Handle<Object> return_value = callable().ToHandleChecked();
1218 CHECK(return_value->SameValue(*snippets[i].return_value()));
1219 }
1220 }
1221
1222
1223 TEST(BytecodeGraphBuilderArrayLiterals) {
1224 HandleAndZoneScope scope;
1225 Isolate* isolate = scope.main_isolate();
1226 Zone* zone = scope.main_zone();
1227 Factory* factory = isolate->factory();
1228
1229 ExpectedSnippet<0> snippets[] = {
1230 {"return [][0];", {factory->undefined_value()}},
1231 {"return [1, 3, 2][1];", {factory->NewNumberFromInt(3)}},
1232 {"return ['a', 'b', 'c'][2];", {factory->NewStringFromStaticChars("c")}},
1233 {"var a = 100; return [a, a++, a + 2, a + 3][2];",
1234 {factory->NewNumberFromInt(103)}},
1235 {"var a = 100; return [a, ++a, a + 2, a + 3][1];",
1236 {factory->NewNumberFromInt(101)}},
1237 {"return [[1, 2, 3], ['a', 'b', 'c']][1][0];",
1238 {factory->NewStringFromStaticChars("a")}},
1239 {"var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];",
1240 {factory->NewStringFromStaticChars("test")}},
1241 {"var t = 't'; return [[t, t + 'est'], [1 + t]][1][0];",
1242 {factory->NewStringFromStaticChars("1t")}}};
1243
1244 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
1245 for (size_t i = 0; i < num_snippets; i++) {
1246 ScopedVector<char> script(1024);
1247 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1248 snippets[i].code_snippet, kFunctionName);
1249
1250 BytecodeGraphTester tester(isolate, zone, script.start());
1251 auto callable = tester.GetCallable<>();
1252 Handle<Object> return_value = callable().ToHandleChecked();
1253 CHECK(return_value->SameValue(*snippets[i].return_value()));
1254 }
1255 }
1256
1257
1258 TEST(BytecodeGraphBuilderObjectLiterals) {
1259 HandleAndZoneScope scope;
1260 Isolate* isolate = scope.main_isolate();
1261 Zone* zone = scope.main_zone();
1262 Factory* factory = isolate->factory();
1263
1264 ExpectedSnippet<0> snippets[] = {
1265 {"return { }.name;", {factory->undefined_value()}},
1266 {"return { name: 'string', val: 9.2 }.name;",
1267 {factory->NewStringFromStaticChars("string")}},
1268 {"return { name: 'string', val: 9.2 }['name'];",
1269 {factory->NewStringFromStaticChars("string")}},
1270 {"var a = 15; return { name: 'string', val: a }.val;",
1271 {factory->NewNumberFromInt(15)}},
1272 {"var a = 15; var b = 'val'; return { name: 'string', val: a }[b];",
1273 {factory->NewNumberFromInt(15)}},
1274 {"var a = 5; return { val: a, val: a + 1 }.val;",
1275 {factory->NewNumberFromInt(6)}},
1276 {"return { func: function() { return 'test' } }.func();",
1277 {factory->NewStringFromStaticChars("test")}},
1278 {"return { func(a) { return a + 'st'; } }.func('te');",
1279 {factory->NewStringFromStaticChars("test")}},
1280 {"return { get a() { return 22; } }.a;", {factory->NewNumberFromInt(22)}},
1281 {"var a = { get b() { return this.x + 't'; },\n"
1282 " set b(val) { this.x = val + 's' } };\n"
1283 "a.b = 'te';\n"
1284 "return a.b;",
1285 {factory->NewStringFromStaticChars("test")}},
1286 {"var a = 123; return { 1: a }[1];", {factory->NewNumberFromInt(123)}},
1287 {"return Object.getPrototypeOf({ __proto__: null });",
1288 {factory->null_value()}},
1289 {"var a = 'test'; return { [a]: 1 }.test;",
1290 {factory->NewNumberFromInt(1)}},
1291 {"var a = 'test'; return { b: a, [a]: a + 'ing' }['test']",
1292 {factory->NewStringFromStaticChars("testing")}},
1293 {"var a = 'proto_str';\n"
1294 "var b = { [a]: 1, __proto__: { var : a } };\n"
1295 "return Object.getPrototypeOf(b).var",
1296 {factory->NewStringFromStaticChars("proto_str")}},
1297 {"var n = 'name';\n"
1298 "return { [n]: 'val', get a() { return 987 } }['a'];",
1299 {factory->NewNumberFromInt(987)}},
1300 };
1301
1302 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
1303 for (size_t i = 0; i < num_snippets; i++) {
1304 ScopedVector<char> script(1024);
1305 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1306 snippets[i].code_snippet, kFunctionName);
1307
1308 BytecodeGraphTester tester(isolate, zone, script.start());
1309 auto callable = tester.GetCallable<>();
1310 Handle<Object> return_value = callable().ToHandleChecked();
1311 CHECK(return_value->SameValue(*snippets[i].return_value()));
1312 }
1313 }
1314
1189 } // namespace compiler 1315 } // namespace compiler
1190 } // namespace internal 1316 } // namespace internal
1191 } // namespace v8 1317 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698