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

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

Issue 1641723002: [interpreter] Translate exception handlers into graph. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments. Created 4 years, 10 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
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | 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 <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 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 snippets[i].code_snippet, kFunctionName); 1405 snippets[i].code_snippet, kFunctionName);
1406 1406
1407 BytecodeGraphTester tester(isolate, zone, script.start()); 1407 BytecodeGraphTester tester(isolate, zone, script.start());
1408 auto callable = tester.GetCallable<Handle<Object>>(); 1408 auto callable = tester.GetCallable<Handle<Object>>();
1409 Handle<Object> return_value = 1409 Handle<Object> return_value =
1410 callable(snippets[i].parameter(0)).ToHandleChecked(); 1410 callable(snippets[i].parameter(0)).ToHandleChecked();
1411 CHECK(return_value->SameValue(*snippets[i].return_value())); 1411 CHECK(return_value->SameValue(*snippets[i].return_value()));
1412 } 1412 }
1413 } 1413 }
1414 1414
1415 TEST(BytecodeGraphBuilderTryCatch) {
1416 HandleAndZoneScope scope;
1417 Isolate* isolate = scope.main_isolate();
1418 Zone* zone = scope.main_zone();
1419
1420 ExpectedSnippet<0> snippets[] = {
1421 // TODO(mstarzinger): Fix cases where nothing throws.
1422 // {"var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;",
1423 // {handle(Smi::FromInt(2), isolate)}},
1424 {"var a; try { undef.x } catch(e) { a = 2 }; return a;",
1425 {handle(Smi::FromInt(2), isolate)}},
1426 {"var a; try { throw 1 } catch(e) { a = e + 2 }; return a;",
1427 {handle(Smi::FromInt(3), isolate)}},
1428 {"var a; try { throw 1 } catch(e) { a = e + 2 };"
1429 " try { throw a } catch(e) { a = e + 3 }; return a;",
1430 {handle(Smi::FromInt(6), isolate)}},
1431 };
1432
1433 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
1434 for (size_t i = 0; i < num_snippets; i++) {
1435 ScopedVector<char> script(1024);
1436 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1437 snippets[i].code_snippet, kFunctionName);
1438
1439 BytecodeGraphTester tester(isolate, zone, script.start());
1440 auto callable = tester.GetCallable<>();
1441 Handle<Object> return_value = callable().ToHandleChecked();
1442 CHECK(return_value->SameValue(*snippets[i].return_value()));
1443 }
1444 }
1445
1446 TEST(BytecodeGraphBuilderTryFinally1) {
1447 HandleAndZoneScope scope;
1448 Isolate* isolate = scope.main_isolate();
1449 Zone* zone = scope.main_zone();
1450
1451 ExpectedSnippet<0> snippets[] = {
1452 {"var a = 1; try { a = a + 1; } finally { a = a + 2; }; return a;",
1453 {handle(Smi::FromInt(4), isolate)}},
1454 // TODO(mstarzinger): Fix cases where nothing throws.
1455 // {"var a = 1; try { a = 2; return 23; } finally { a = 3 }; return a;",
1456 // {handle(Smi::FromInt(23), isolate)}},
1457 {"var a = 1; try { a = 2; throw 23; } finally { return a; };",
1458 {handle(Smi::FromInt(2), isolate)}},
1459 // {"var a = 1; for (var i = 10; i < 20; i += 5) {"
1460 // " try { a = 2; break; } finally { a = 3; }"
1461 // "} return a + i;",
1462 // {handle(Smi::FromInt(13), isolate)}},
1463 // {"var a = 1; for (var i = 10; i < 20; i += 5) {"
1464 // " try { a = 2; continue; } finally { a = 3; }"
1465 // "} return a + i;",
1466 // {handle(Smi::FromInt(23), isolate)}},
1467 // {"var a = 1; try { a = 2;"
1468 // " try { a = 3; throw 23; } finally { a = 4; }"
1469 // "} catch(e) { a = a + e; } return a;",
1470 // {handle(Smi::FromInt(27), isolate)}},
1471 };
1472
1473 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
1474 for (size_t i = 0; i < num_snippets; i++) {
1475 ScopedVector<char> script(1024);
1476 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1477 snippets[i].code_snippet, kFunctionName);
1478
1479 BytecodeGraphTester tester(isolate, zone, script.start());
1480 auto callable = tester.GetCallable<>();
1481 Handle<Object> return_value = callable().ToHandleChecked();
1482 CHECK(return_value->SameValue(*snippets[i].return_value()));
1483 }
1484 }
1485
1486 TEST(BytecodeGraphBuilderTryFinally2) {
1487 HandleAndZoneScope scope;
1488 Isolate* isolate = scope.main_isolate();
1489 Zone* zone = scope.main_zone();
1490
1491 ExpectedSnippet<0, const char*> snippets[] = {
1492 {"var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;",
1493 {"Uncaught 23"}},
1494 {"var a = 1; try { a = 2; throw 23; } finally { throw 42; };",
1495 {"Uncaught 42"}},
1496 };
1497
1498 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
1499 for (size_t i = 0; i < num_snippets; i++) {
1500 ScopedVector<char> script(1024);
1501 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1502 snippets[i].code_snippet, kFunctionName);
1503
1504 BytecodeGraphTester tester(isolate, zone, script.start());
1505 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get();
1506 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value());
1507 CHECK(
1508 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string)
1509 .FromJust());
1510 }
1511 }
1415 1512
1416 TEST(BytecodeGraphBuilderThrow) { 1513 TEST(BytecodeGraphBuilderThrow) {
1417 HandleAndZoneScope scope; 1514 HandleAndZoneScope scope;
1418 Isolate* isolate = scope.main_isolate(); 1515 Isolate* isolate = scope.main_isolate();
1419 Zone* zone = scope.main_zone(); 1516 Zone* zone = scope.main_zone();
1420 1517
1421 // TODO(mythria): Add more tests when real try-catch and deoptimization 1518 // TODO(mythria): Add more tests when real try-catch and deoptimization
1422 // information are supported. 1519 // information are supported.
1423 ExpectedSnippet<0, const char*> snippets[] = { 1520 ExpectedSnippet<0, const char*> snippets[] = {
1424 {"throw undefined;", {"Uncaught undefined"}}, 1521 {"throw undefined;", {"Uncaught undefined"}},
1425 {"throw 1;", {"Uncaught 1"}}, 1522 {"throw 1;", {"Uncaught 1"}},
1426 {"throw 'Error';", {"Uncaught Error"}}, 1523 {"throw 'Error';", {"Uncaught Error"}},
1427 {"throw 'Error1'; throw 'Error2'", {"Uncaught Error1"}}, 1524 {"throw 'Error1'; throw 'Error2'", {"Uncaught Error1"}},
1428 // TODO(mythria): Enable these tests when JumpIfTrue is supported. 1525 {"var a = true; if (a) { throw 'Error'; }", {"Uncaught Error"}},
1429 // {"var a = true; if (a) { throw 'Error'; }", {"Error"}},
1430 }; 1526 };
1431 1527
1432 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1528 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
1433 for (size_t i = 0; i < num_snippets; i++) { 1529 for (size_t i = 0; i < num_snippets; i++) {
1434 ScopedVector<char> script(1024); 1530 ScopedVector<char> script(1024);
1435 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1531 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1436 snippets[i].code_snippet, kFunctionName); 1532 snippets[i].code_snippet, kFunctionName);
1533
1437 BytecodeGraphTester tester(isolate, zone, script.start()); 1534 BytecodeGraphTester tester(isolate, zone, script.start());
1438 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); 1535 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get();
1439 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value()); 1536 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value());
1440 CHECK( 1537 CHECK(
1441 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) 1538 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string)
1442 .FromJust()); 1539 .FromJust());
1443 } 1540 }
1444 } 1541 }
1445 1542
1446 1543
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 Handle<Object> return_value = callable().ToHandleChecked(); 2552 Handle<Object> return_value = callable().ToHandleChecked();
2456 CHECK(return_value->SameValue(*snippets[i].return_value())); 2553 CHECK(return_value->SameValue(*snippets[i].return_value()));
2457 } 2554 }
2458 2555
2459 FLAG_harmony_do_expressions = old_flag; 2556 FLAG_harmony_do_expressions = old_flag;
2460 } 2557 }
2461 2558
2462 } // namespace compiler 2559 } // namespace compiler
2463 } // namespace internal 2560 } // namespace internal
2464 } // namespace v8 2561 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698