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

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

Issue 154133002: Test for miscellaneous (pre)parse errors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 "try { } catch (eval) { }", 1368 "try { } catch (eval) { }",
1369 "try { } catch (arguments) { }", 1369 "try { } catch (arguments) { }",
1370 "function eval() { }", 1370 "function eval() { }",
1371 "function arguments() { }", 1371 "function arguments() { }",
1372 "function foo(eval) { }", 1372 "function foo(eval) { }",
1373 "function foo(arguments) { }", 1373 "function foo(arguments) { }",
1374 "function foo(bar, eval) { }", 1374 "function foo(bar, eval) { }",
1375 "function foo(bar, arguments) { }", 1375 "function foo(bar, arguments) { }",
1376 "eval = 1;", 1376 "eval = 1;",
1377 "arguments = 1;", 1377 "arguments = 1;",
1378 "var foo = eval = 1;",
1379 "var foo = arguments = 1;",
1378 "++eval;", 1380 "++eval;",
1379 "++arguments;", 1381 "++arguments;",
1380 "eval++;", 1382 "eval++;",
1381 "arguments++;", 1383 "arguments++;",
1382 NULL 1384 NULL
1383 }; 1385 };
1384 1386
1385 v8::HandleScope handles(CcTest::isolate()); 1387 v8::HandleScope handles(CcTest::isolate());
1386 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1388 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1387 v8::Context::Scope context_scope(context); 1389 v8::Context::Scope context_scope(context);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 // mode, it isn't. 1424 // mode, it isn't.
1423 const char* context_data[][2] = { 1425 const char* context_data[][2] = {
1424 { "", "" }, 1426 { "", "" },
1425 { "\"use strict\";", "}" }, 1427 { "\"use strict\";", "}" },
1426 { "var eval; function test_func() {", "}"}, 1428 { "var eval; function test_func() {", "}"},
1427 { "var eval; function test_func() {\"use strict\"; ", "}"}, 1429 { "var eval; function test_func() {\"use strict\"; ", "}"},
1428 { NULL, NULL } 1430 { NULL, NULL }
1429 }; 1431 };
1430 1432
1431 const char* statement_data[] = { 1433 const char* statement_data[] = {
1432 "var interface = 42;", 1434 "var interface;",
1433 "var foo, interface;", 1435 "var foo, interface;",
1434 "try { } catch (interface) { }", 1436 "try { } catch (interface) { }",
1435 "function interface() { }", 1437 "function interface() { }",
1436 "function foo(interface) { }", 1438 "function foo(interface) { }",
1437 "function foo(bar, interface) { }", 1439 "function foo(bar, interface) { }",
1438 "interface = 1;", 1440 "interface = 1;",
1441 "var foo = interface = 1;",
1439 "++interface;", 1442 "++interface;",
1440 "interface++;", 1443 "interface++;",
1441 NULL 1444 NULL
1442 }; 1445 };
1443 1446
1444 v8::HandleScope handles(CcTest::isolate()); 1447 v8::HandleScope handles(CcTest::isolate());
1445 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1448 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1446 v8::Context::Scope context_scope(context); 1449 v8::Context::Scope context_scope(context);
1447 1450
1448 int marker; 1451 int marker;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 // strict mode. 1483 // strict mode.
1481 const char* context_data[][2] = { 1484 const char* context_data[][2] = {
1482 { "", "" }, 1485 { "", "" },
1483 { "\"use strict\";", "}" }, 1486 { "\"use strict\";", "}" },
1484 { "var eval; function test_func() {", "}"}, 1487 { "var eval; function test_func() {", "}"},
1485 { "var eval; function test_func() {\"use strict\"; ", "}"}, 1488 { "var eval; function test_func() {\"use strict\"; ", "}"},
1486 { NULL, NULL } 1489 { NULL, NULL }
1487 }; 1490 };
1488 1491
1489 const char* statement_data[] = { 1492 const char* statement_data[] = {
1490 "var super = 42;", 1493 "var super;",
1491 "var foo, super;", 1494 "var foo, super;",
1492 "try { } catch (super) { }", 1495 "try { } catch (super) { }",
1493 "function super() { }", 1496 "function super() { }",
1494 "function foo(super) { }", 1497 "function foo(super) { }",
1495 "function foo(bar, super) { }", 1498 "function foo(bar, super) { }",
1496 "super = 1;", 1499 "super = 1;",
1500 "var foo = super = 1;",
1497 "++super;", 1501 "++super;",
1498 "super++;", 1502 "super++;",
1499 "function foo super", 1503 "function foo super",
1500 NULL 1504 NULL
1501 }; 1505 };
1502 1506
1503 v8::HandleScope handles(CcTest::isolate()); 1507 v8::HandleScope handles(CcTest::isolate());
1504 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1508 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1505 v8::Context::Scope context_scope(context); 1509 v8::Context::Scope context_scope(context);
1506 1510
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 }; 1555 };
1552 1556
1553 const char* statement_data[] = { 1557 const char* statement_data[] = {
1554 "var yield;", 1558 "var yield;",
1555 "var foo, yield;", 1559 "var foo, yield;",
1556 "try { } catch (yield) { }", 1560 "try { } catch (yield) { }",
1557 "function yield() { }", 1561 "function yield() { }",
1558 "function foo(yield) { }", 1562 "function foo(yield) { }",
1559 "function foo(bar, yield) { }", 1563 "function foo(bar, yield) { }",
1560 "yield = 1;", 1564 "yield = 1;",
1565 "var foo = yield = 1;",
1561 "++yield;", 1566 "++yield;",
1562 "yield++;", 1567 "yield++;",
1563 "yield 2;", // this is legal inside generator 1568 "yield 2;", // this is legal inside generator
1564 "yield * 2;", // this is legal inside generator 1569 "yield * 2;", // this is legal inside generator
1565 NULL 1570 NULL
1566 }; 1571 };
1567 1572
1568 v8::HandleScope handles(CcTest::isolate()); 1573 v8::HandleScope handles(CcTest::isolate());
1569 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1574 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1570 v8::Context::Scope context_scope(context); 1575 v8::Context::Scope context_scope(context);
(...skipping 18 matching lines...) Expand all
1589 int length = i::OS::SNPrintF(program, 1594 int length = i::OS::SNPrintF(program,
1590 "%s%s%s", 1595 "%s%s%s",
1591 context_data[i][0], 1596 context_data[i][0],
1592 statement_data[j], 1597 statement_data[j],
1593 context_data[i][1]); 1598 context_data[i][1]);
1594 CHECK(length == kProgramSize); 1599 CHECK(length == kProgramSize);
1595 TestParserSync(program.start(), flags, ARRAY_SIZE(flags)); 1600 TestParserSync(program.start(), flags, ARRAY_SIZE(flags));
1596 } 1601 }
1597 } 1602 }
1598 } 1603 }
1604
1605
1606 TEST(ErrorsNameOfStrictFunction) {
1607 // Tests that illegal tokens as names of a strict function produce the correct
1608 // errors.
1609 const char* statement_data[] = {
1610 "function eval() { }", // legal
1611 "function eval() {\"use strict\";}", // illegal
1612 "function arguments() { }", // legal
1613 "function arguments() {\"use strict\";}", // illegal
1614 // Future reserved words are always illegal
1615 "function super() { }", // illegal
1616 "function super() {\"use strict\";}", // illegal
1617 "function interface() { }", // legal
1618 "function interface() {\"use strict\";}", // illegal
1619 "function yield() { }", // legal
1620 "function yield() {\"use strict\";}", // illegal
1621 NULL
1622 };
1623
1624 v8::HandleScope handles(CcTest::isolate());
1625 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1626 v8::Context::Scope context_scope(context);
1627
1628 int marker;
1629 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1630 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1631
1632 static const ParserFlag flags[] = {
1633 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1634 kAllowForOf
1635 };
1636 for (int j = 0; statement_data[j] != NULL; ++j) {
1637 TestParserSync(statement_data[j], flags, ARRAY_SIZE(flags));
1638 }
1639 }
1640
1641
1642 TEST(ErrorsIllegalWordsAsLabels) {
1643 // Tests that illegal tokens as labels produce the correct errors.
1644 const char* context_data[][2] = {
1645 { "", "" },
1646 { "\"use strict\";", "}" },
1647 { NULL, NULL }
1648 };
1649
1650 const char* statement_data[] = {
1651 "mylabel: while(true) { break mylabel; }",
1652 "eval: while(true) { break eval; }",
1653 "arguments: while(true) { break arguments; }",
1654 "super: while(true) { break super; }", // always illegal
1655 "interface: while(true) { break interface; }",
1656 "yield: while(true) { break yield; }",
1657 NULL
1658 };
1659
1660 v8::HandleScope handles(CcTest::isolate());
1661 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1662 v8::Context::Scope context_scope(context);
1663
1664 int marker;
1665 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1666 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1667
1668 static const ParserFlag flags[] = {
1669 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1670 kAllowForOf
1671 };
1672 for (int i = 0; context_data[i][0] != NULL; ++i) {
1673 for (int j = 0; statement_data[j] != NULL; ++j) {
1674 int kPrefixLen = i::StrLength(context_data[i][0]);
1675 int kStatementLen = i::StrLength(statement_data[j]);
1676 int kSuffixLen = i::StrLength(context_data[i][1]);
1677 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen;
1678
1679 // Plug the source code pieces together.
1680 i::ScopedVector<char> program(kProgramSize + 1);
1681 int length = i::OS::SNPrintF(program,
1682 "%s%s%s",
1683 context_data[i][0],
1684 statement_data[j],
1685 context_data[i][1]);
1686 CHECK(length == kProgramSize);
1687 TestParserSync(program.start(), flags, ARRAY_SIZE(flags));
1688 }
1689 }
1690 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698