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

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

Issue 1618693005: [Interpreter] Add ForOf support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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
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 <utility> 5 #include <utility>
6 6
7 #include "src/compiler/pipeline.h" 7 #include "src/compiler/pipeline.h"
8 #include "src/execution.h" 8 #include "src/execution.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/interpreter/bytecode-array-builder.h" 10 #include "src/interpreter/bytecode-array-builder.h"
(...skipping 2276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 snippets[i].code_snippet, kFunctionName); 2287 snippets[i].code_snippet, kFunctionName);
2288 2288
2289 BytecodeGraphTester tester(isolate, zone, script.start()); 2289 BytecodeGraphTester tester(isolate, zone, script.start());
2290 auto callable = tester.GetCallable<>(); 2290 auto callable = tester.GetCallable<>();
2291 Handle<Object> return_value = callable().ToHandleChecked(); 2291 Handle<Object> return_value = callable().ToHandleChecked();
2292 CHECK(return_value->SameValue(*snippets[i].return_value())); 2292 CHECK(return_value->SameValue(*snippets[i].return_value()));
2293 } 2293 }
2294 } 2294 }
2295 2295
2296 2296
2297 TEST(BytecodeGraphBuilderForOf) {
2298 HandleAndZoneScope scope;
2299 Isolate* isolate = scope.main_isolate();
2300 Zone* zone = scope.main_zone();
2301 Factory* factory = isolate->factory();
2302 ExpectedSnippet<0> snippets[] = {
2303 {" var r = 0;\n"
2304 " for (var a of [0,6,7,9]) { r += a; }\n"
2305 " return r;\n",
2306 {handle(Smi::FromInt(22), isolate)}},
2307 {" var r = '';\n"
2308 " for (var a of 'foobar') { r = a + r; }\n"
2309 " return r;\n",
2310 {factory->NewStringFromStaticChars("raboof")}},
2311 {" var a = [1, 2, 3];\n"
2312 " a.name = 4;\n"
2313 " var r = 0;\n"
2314 " for (var x of a) { r += x; }\n"
2315 " return r;\n",
2316 {handle(Smi::FromInt(6), isolate)}},
2317 {" var r = '';\n"
2318 " var data = [1, 2, 3]; \n"
2319 " for (a of data) { delete data[0]; r += a; } return r;",
2320 {factory->NewStringFromStaticChars("123")}},
2321 {" var r = '';\n"
2322 " var data = [1, 2, 3]; \n"
2323 " for (a of data) { delete data[2]; r += a; } return r;",
2324 {factory->NewStringFromStaticChars("12undefined")}},
2325 {" var r = '';\n"
2326 " var data = [1, 2, 3]; \n"
2327 " for (a of data) { delete data; r += a; } return r;",
2328 {factory->NewStringFromStaticChars("123")}},
2329 {" var r = '';\n"
2330 " var input = 'foobar';\n"
2331 " for (var a of input) {\n"
2332 " if (a == 'b') break;\n"
2333 " r += a;\n"
2334 " }\n"
2335 " return r;\n",
2336 {factory->NewStringFromStaticChars("foo")}},
2337 {" var r = '';\n"
2338 " var input = 'foobar';\n"
2339 " for (var a of input) {\n"
2340 " if (a == 'b') continue;\n"
2341 " r += a;\n"
2342 " }\n"
2343 " return r;\n",
2344 {factory->NewStringFromStaticChars("fooar")}},
2345 {" var r = '';\n"
2346 " var data = [1, 2, 3, 4]; \n"
2347 " for (a of data) { data[2] = 567; r += a; }\n"
2348 " return r;\n",
2349 {factory->NewStringFromStaticChars("125674")}},
2350 {" var r = '';\n"
2351 " var data = [1, 2, 3, 4]; \n"
2352 " for (a of data) { data[4] = 567; r += a; }\n"
2353 " return r;\n",
2354 {factory->NewStringFromStaticChars("1234567")}},
2355 {" var r = '';\n"
2356 " var data = [1, 2, 3, 4]; \n"
2357 " for (a of data) { data[5] = 567; r += a; }\n"
2358 " return r;\n",
2359 {factory->NewStringFromStaticChars("1234undefined567")}},
2360 {" var r = '';\n"
2361 " var obj = new Object();\n"
2362 " obj[Symbol.iterator] = function() { return {\n"
2363 " index: 3,\n"
2364 " data: ['a', 'b', 'c', 'd'],"
2365 " next: function() {"
2366 " return {"
2367 " done: this.index == -1,\n"
2368 " value: this.index < 0 ? undefined : this.data[this.index--]\n"
2369 " }\n"
2370 " }\n"
2371 " }}\n"
2372 " for (a of obj) { r += a }\n"
2373 " return r;\n",
2374 {factory->NewStringFromStaticChars("dcba")}},
2375 };
2376
2377 for (size_t i = 0; i < arraysize(snippets); i++) {
2378 ScopedVector<char> script(1024);
2379 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
2380 snippets[i].code_snippet, kFunctionName);
2381
2382 BytecodeGraphTester tester(isolate, zone, script.start());
2383 auto callable = tester.GetCallable<>();
2384 Handle<Object> return_value = callable().ToHandleChecked();
2385 CHECK(return_value->SameValue(*snippets[i].return_value()));
2386 }
2387 }
2388
2389
2297 TEST(JumpWithConstantsAndWideConstants) { 2390 TEST(JumpWithConstantsAndWideConstants) {
2298 HandleAndZoneScope scope; 2391 HandleAndZoneScope scope;
2299 auto isolate = scope.main_isolate(); 2392 auto isolate = scope.main_isolate();
2300 const int kStep = 19; 2393 const int kStep = 19;
2301 int start = 7; 2394 int start = 7;
2302 for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) { 2395 for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) {
2303 std::stringstream filler_os; 2396 std::stringstream filler_os;
2304 // Generate a string that consumes constant pool entries and 2397 // Generate a string that consumes constant pool entries and
2305 // spread out branch distances in script below. 2398 // spread out branch distances in script below.
2306 for (int i = 0; i < constants; i++) { 2399 for (int i = 0; i < constants; i++) {
(...skipping 23 matching lines...) Expand all
2330 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); 2423 callable(factory->NewNumberFromInt(a)).ToHandleChecked();
2331 static const int results[] = {11, 12, 2}; 2424 static const int results[] = {11, 12, 2};
2332 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); 2425 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]);
2333 } 2426 }
2334 } 2427 }
2335 } 2428 }
2336 2429
2337 } // namespace compiler 2430 } // namespace compiler
2338 } // namespace internal 2431 } // namespace internal
2339 } // namespace v8 2432 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698