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

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

Issue 1429983002: [es6] early error when Identifier is an escaped reserved word (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Cosmetic fixup 1 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
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 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); 1525 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
1526 parser->set_allow_harmony_destructuring( 1526 parser->set_allow_harmony_destructuring(
1527 flags.Contains(kAllowHarmonyDestructuring)); 1527 flags.Contains(kAllowHarmonyDestructuring));
1528 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); 1528 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
1529 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); 1529 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst));
1530 } 1530 }
1531 1531
1532 1532
1533 void TestParserSyncWithFlags(i::Handle<i::String> source, 1533 void TestParserSyncWithFlags(i::Handle<i::String> source,
1534 i::EnumSet<ParserFlag> flags, 1534 i::EnumSet<ParserFlag> flags,
1535 ParserSyncTestResult result) { 1535 ParserSyncTestResult result,
1536 bool is_module = false) {
1536 i::Isolate* isolate = CcTest::i_isolate(); 1537 i::Isolate* isolate = CcTest::i_isolate();
1537 i::Factory* factory = isolate->factory(); 1538 i::Factory* factory = isolate->factory();
1538 1539
1539 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1540 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1540 int preparser_materialized_literals = -1; 1541 int preparser_materialized_literals = -1;
1541 int parser_materialized_literals = -2; 1542 int parser_materialized_literals = -2;
1542 1543
1543 // Preparse the data. 1544 // Preparse the data.
1544 i::CompleteParserRecorder log; 1545 i::CompleteParserRecorder log;
1545 { 1546 if (!is_module) {
adamk 2015/11/04 23:42:02 Please add something of this form to make this cle
caitp (gmail) 2015/11/06 19:08:06 Done.
1546 i::Scanner scanner(isolate->unicode_cache()); 1547 i::Scanner scanner(isolate->unicode_cache());
1547 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1548 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1548 i::Zone zone; 1549 i::Zone zone;
1549 i::AstValueFactory ast_value_factory( 1550 i::AstValueFactory ast_value_factory(
1550 &zone, CcTest::i_isolate()->heap()->HashSeed()); 1551 &zone, CcTest::i_isolate()->heap()->HashSeed());
1551 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 1552 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
1552 stack_limit); 1553 stack_limit);
1553 SetParserFlags(&preparser, flags); 1554 SetParserFlags(&preparser, flags);
1554 scanner.Initialize(&stream); 1555 scanner.Initialize(&stream);
1555 i::PreParser::PreParseResult result = preparser.PreParseProgram( 1556 i::PreParser::PreParseResult result = preparser.PreParseProgram(
1556 &preparser_materialized_literals); 1557 &preparser_materialized_literals);
1557 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1558 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1558 } 1559 }
1559
1560 bool preparse_error = log.HasError(); 1560 bool preparse_error = log.HasError();
1561 1561
1562 // Parse the data 1562 // Parse the data
1563 i::FunctionLiteral* function; 1563 i::FunctionLiteral* function;
1564 { 1564 {
1565 i::Handle<i::Script> script = factory->NewScript(source); 1565 i::Handle<i::Script> script = factory->NewScript(source);
1566 i::Zone zone; 1566 i::Zone zone;
1567 i::ParseInfo info(&zone, script); 1567 i::ParseInfo info(&zone, script);
1568 i::Parser parser(&info); 1568 i::Parser parser(&info);
1569 SetParserFlags(&parser, flags); 1569 SetParserFlags(&parser, flags);
1570 info.set_global(); 1570 if (is_module) {
1571 info.set_module();
1572 } else {
1573 info.set_global();
1574 }
1571 parser.Parse(&info); 1575 parser.Parse(&info);
1572 function = info.literal(); 1576 function = info.literal();
1573 if (function) { 1577 if (function) {
1574 parser_materialized_literals = function->materialized_literal_count(); 1578 parser_materialized_literals = function->materialized_literal_count();
1575 } 1579 }
1576 } 1580 }
1577 1581
1578 // Check that preparsing fails iff parsing fails. 1582 // Check that preparsing fails iff parsing fails.
1579 if (function == NULL) { 1583 if (function == NULL) {
1580 // Extract exception from the parser. 1584 // Extract exception from the parser.
1581 CHECK(isolate->has_pending_exception()); 1585 CHECK(isolate->has_pending_exception());
1582 i::Handle<i::JSObject> exception_handle( 1586 i::Handle<i::JSObject> exception_handle(
1583 i::JSObject::cast(isolate->pending_exception())); 1587 i::JSObject::cast(isolate->pending_exception()));
1584 i::Handle<i::String> message_string = 1588 i::Handle<i::String> message_string =
1585 i::Handle<i::String>::cast(i::Object::GetProperty( 1589 i::Handle<i::String>::cast(i::Object::GetProperty(
1586 isolate, exception_handle, "message").ToHandleChecked()); 1590 isolate, exception_handle, "message").ToHandleChecked());
1587 1591
1588 if (result == kSuccess) { 1592 if (result == kSuccess) {
1589 v8::base::OS::Print( 1593 v8::base::OS::Print(
1590 "Parser failed on:\n" 1594 "Parser failed on:\n"
1591 "\t%s\n" 1595 "\t%s\n"
1592 "with error:\n" 1596 "with error:\n"
1593 "\t%s\n" 1597 "\t%s\n"
1594 "However, we expected no error.", 1598 "However, we expected no error.",
1595 source->ToCString().get(), message_string->ToCString().get()); 1599 source->ToCString().get(), message_string->ToCString().get());
1596 CHECK(false); 1600 CHECK(false);
1597 } 1601 }
1598 1602
1599 if (!preparse_error) { 1603 if (!is_module && !preparse_error) {
adamk 2015/11/04 23:42:02 and then use it here too
1600 v8::base::OS::Print( 1604 v8::base::OS::Print(
1601 "Parser failed on:\n" 1605 "Parser failed on:\n"
1602 "\t%s\n" 1606 "\t%s\n"
1603 "with error:\n" 1607 "with error:\n"
1604 "\t%s\n" 1608 "\t%s\n"
1605 "However, the preparser succeeded", 1609 "However, the preparser succeeded",
1606 source->ToCString().get(), message_string->ToCString().get()); 1610 source->ToCString().get(), message_string->ToCString().get());
1607 CHECK(false); 1611 CHECK(false);
1608 } 1612 }
1609 // Check that preparser and parser produce the same error. 1613 // Check that preparser and parser produce the same error.
1610 i::Handle<i::String> preparser_message = 1614 if (!is_module) {
adamk 2015/11/04 23:42:02 and here
1611 FormatMessage(log.ErrorMessageData()); 1615 i::Handle<i::String> preparser_message =
1612 if (!i::String::Equals(message_string, preparser_message)) { 1616 FormatMessage(log.ErrorMessageData());
1613 v8::base::OS::Print( 1617 if (!i::String::Equals(message_string, preparser_message)) {
1614 "Expected parser and preparser to produce the same error on:\n" 1618 v8::base::OS::Print(
1615 "\t%s\n" 1619 "Expected parser and preparser to produce the same error on:\n"
1616 "However, found the following error messages\n" 1620 "\t%s\n"
1617 "\tparser: %s\n" 1621 "However, found the following error messages\n"
1618 "\tpreparser: %s\n", 1622 "\tparser: %s\n"
1619 source->ToCString().get(), 1623 "\tpreparser: %s\n",
1620 message_string->ToCString().get(), 1624 source->ToCString().get(), message_string->ToCString().get(),
1621 preparser_message->ToCString().get()); 1625 preparser_message->ToCString().get());
1622 CHECK(false); 1626 CHECK(false);
1627 }
1623 } 1628 }
1624 } else if (preparse_error) { 1629 } else if (!is_module && preparse_error) {
adamk 2015/11/04 23:42:02 and here
1625 v8::base::OS::Print( 1630 v8::base::OS::Print(
1626 "Preparser failed on:\n" 1631 "Preparser failed on:\n"
1627 "\t%s\n" 1632 "\t%s\n"
1628 "with error:\n" 1633 "with error:\n"
1629 "\t%s\n" 1634 "\t%s\n"
1630 "However, the parser succeeded", 1635 "However, the parser succeeded",
1631 source->ToCString().get(), 1636 source->ToCString().get(),
1632 FormatMessage(log.ErrorMessageData())->ToCString().get()); 1637 FormatMessage(log.ErrorMessageData())->ToCString().get());
1633 CHECK(false); 1638 CHECK(false);
1634 } else if (result == kError) { 1639 } else if (result == kError) {
1635 v8::base::OS::Print( 1640 v8::base::OS::Print(
1636 "Expected error on:\n" 1641 "Expected error on:\n"
1637 "\t%s\n" 1642 "\t%s\n"
1638 "However, parser and preparser succeeded", 1643 "However, parser and preparser succeeded",
1639 source->ToCString().get()); 1644 source->ToCString().get());
1640 CHECK(false); 1645 CHECK(false);
1641 } else if (preparser_materialized_literals != parser_materialized_literals) { 1646 } else if (!is_module &&
adamk 2015/11/04 23:42:02 and here
1647 preparser_materialized_literals != parser_materialized_literals) {
1642 v8::base::OS::Print( 1648 v8::base::OS::Print(
1643 "Preparser materialized literals (%d) differ from Parser materialized " 1649 "Preparser materialized literals (%d) differ from Parser materialized "
1644 "literals (%d) on:\n" 1650 "literals (%d) on:\n"
1645 "\t%s\n" 1651 "\t%s\n"
1646 "However, parser and preparser succeeded", 1652 "However, parser and preparser succeeded",
1647 preparser_materialized_literals, parser_materialized_literals, 1653 preparser_materialized_literals, parser_materialized_literals,
1648 source->ToCString().get()); 1654 source->ToCString().get());
1649 CHECK(false); 1655 CHECK(false);
1650 } 1656 }
1651 } 1657 }
1652 1658
1653 1659
1654 void TestParserSync(const char* source, 1660 void TestParserSync(const char* source, const ParserFlag* varying_flags,
1655 const ParserFlag* varying_flags,
1656 size_t varying_flags_length, 1661 size_t varying_flags_length,
1657 ParserSyncTestResult result = kSuccessOrError, 1662 ParserSyncTestResult result = kSuccessOrError,
1658 const ParserFlag* always_true_flags = NULL, 1663 const ParserFlag* always_true_flags = NULL,
1659 size_t always_true_flags_length = 0, 1664 size_t always_true_flags_length = 0,
1660 const ParserFlag* always_false_flags = NULL, 1665 const ParserFlag* always_false_flags = NULL,
1661 size_t always_false_flags_length = 0) { 1666 size_t always_false_flags_length = 0,
1667 bool is_module = false) {
1662 i::Handle<i::String> str = 1668 i::Handle<i::String> str =
1663 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(source); 1669 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(source);
1664 for (int bits = 0; bits < (1 << varying_flags_length); bits++) { 1670 for (int bits = 0; bits < (1 << varying_flags_length); bits++) {
1665 i::EnumSet<ParserFlag> flags; 1671 i::EnumSet<ParserFlag> flags;
1666 for (size_t flag_index = 0; flag_index < varying_flags_length; 1672 for (size_t flag_index = 0; flag_index < varying_flags_length;
1667 ++flag_index) { 1673 ++flag_index) {
1668 if ((bits & (1 << flag_index)) != 0) flags.Add(varying_flags[flag_index]); 1674 if ((bits & (1 << flag_index)) != 0) flags.Add(varying_flags[flag_index]);
1669 } 1675 }
1670 for (size_t flag_index = 0; flag_index < always_true_flags_length; 1676 for (size_t flag_index = 0; flag_index < always_true_flags_length;
1671 ++flag_index) { 1677 ++flag_index) {
1672 flags.Add(always_true_flags[flag_index]); 1678 flags.Add(always_true_flags[flag_index]);
1673 } 1679 }
1674 for (size_t flag_index = 0; flag_index < always_false_flags_length; 1680 for (size_t flag_index = 0; flag_index < always_false_flags_length;
1675 ++flag_index) { 1681 ++flag_index) {
1676 flags.Remove(always_false_flags[flag_index]); 1682 flags.Remove(always_false_flags[flag_index]);
1677 } 1683 }
1678 TestParserSyncWithFlags(str, flags, result); 1684 TestParserSyncWithFlags(str, flags, result, is_module);
1679 } 1685 }
1680 } 1686 }
1681 1687
1682 1688
1683 TEST(ParserSync) { 1689 TEST(ParserSync) {
1684 const char* context_data[][2] = { 1690 const char* context_data[][2] = {
1685 { "", "" }, 1691 { "", "" },
1686 { "{", "}" }, 1692 { "{", "}" },
1687 { "if (true) ", " else {}" }, 1693 { "if (true) ", " else {}" },
1688 { "if (true) {} else ", "" }, 1694 { "if (true) {} else ", "" },
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 v8::String::Utf8Value exception(try_catch.Exception()); 1818 v8::String::Utf8Value exception(try_catch.Exception());
1813 CHECK_EQ(0, 1819 CHECK_EQ(0,
1814 strcmp("SyntaxError: Octal literals are not allowed in strict mode.", 1820 strcmp("SyntaxError: Octal literals are not allowed in strict mode.",
1815 *exception)); 1821 *exception));
1816 } 1822 }
1817 1823
1818 1824
1819 void RunParserSyncTest(const char* context_data[][2], 1825 void RunParserSyncTest(const char* context_data[][2],
1820 const char* statement_data[], 1826 const char* statement_data[],
1821 ParserSyncTestResult result, 1827 ParserSyncTestResult result,
1822 const ParserFlag* flags = NULL, 1828 const ParserFlag* flags = NULL, int flags_len = 0,
1823 int flags_len = 0,
1824 const ParserFlag* always_true_flags = NULL, 1829 const ParserFlag* always_true_flags = NULL,
1825 int always_true_len = 0, 1830 int always_true_len = 0,
1826 const ParserFlag* always_false_flags = NULL, 1831 const ParserFlag* always_false_flags = NULL,
1827 int always_false_len = 0) { 1832 int always_false_len = 0, bool is_module = false) {
1828 v8::HandleScope handles(CcTest::isolate()); 1833 v8::HandleScope handles(CcTest::isolate());
1829 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 1834 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
1830 v8::Context::Scope context_scope(context); 1835 v8::Context::Scope context_scope(context);
1831 1836
1832 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1837 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1833 i::GetCurrentStackPosition() - 128 * 1024); 1838 i::GetCurrentStackPosition() - 128 * 1024);
1834 1839
1835 // Experimental feature flags should not go here; pass the flags as 1840 // Experimental feature flags should not go here; pass the flags as
1836 // always_true_flags if the test needs them. 1841 // always_true_flags if the test needs them.
1837 static const ParserFlag default_flags[] = { 1842 static const ParserFlag default_flags[] = {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen; 1875 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen;
1871 1876
1872 // Plug the source code pieces together. 1877 // Plug the source code pieces together.
1873 i::ScopedVector<char> program(kProgramSize + 1); 1878 i::ScopedVector<char> program(kProgramSize + 1);
1874 int length = i::SNPrintF(program, 1879 int length = i::SNPrintF(program,
1875 "%s%s%s", 1880 "%s%s%s",
1876 context_data[i][0], 1881 context_data[i][0],
1877 statement_data[j], 1882 statement_data[j],
1878 context_data[i][1]); 1883 context_data[i][1]);
1879 CHECK(length == kProgramSize); 1884 CHECK(length == kProgramSize);
1880 TestParserSync(program.start(), 1885 TestParserSync(program.start(), flags, flags_len, result,
1881 flags, 1886 always_true_flags, always_true_len, always_false_flags,
1882 flags_len, 1887 always_false_len, is_module);
1883 result,
1884 always_true_flags,
1885 always_true_len,
1886 always_false_flags,
1887 always_false_len);
1888 } 1888 }
1889 } 1889 }
1890 delete[] generated_flags; 1890 delete[] generated_flags;
1891 } 1891 }
1892 1892
1893 1893
1894 void RunModuleParserSyncTest(const char* context_data[][2],
1895 const char* statement_data[],
1896 ParserSyncTestResult result,
1897 const ParserFlag* flags = NULL, int flags_len = 0,
1898 const ParserFlag* always_true_flags = NULL,
1899 int always_true_len = 0,
1900 const ParserFlag* always_false_flags = NULL,
1901 int always_false_len = 0) {
1902 bool flag = i::FLAG_harmony_modules;
1903 i::FLAG_harmony_modules = true;
1904 RunParserSyncTest(context_data, statement_data, result, flags, flags_len,
1905 always_true_flags, always_true_len, always_false_flags,
1906 always_false_len, true);
1907 i::FLAG_harmony_modules = flag;
1908 }
1909
1910
1894 TEST(ErrorsEvalAndArguments) { 1911 TEST(ErrorsEvalAndArguments) {
1895 // Tests that both preparsing and parsing produce the right kind of errors for 1912 // Tests that both preparsing and parsing produce the right kind of errors for
1896 // using "eval" and "arguments" as identifiers. Without the strict mode, it's 1913 // using "eval" and "arguments" as identifiers. Without the strict mode, it's
1897 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it 1914 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it
1898 // isn't. 1915 // isn't.
1899 const char* context_data[][2] = { 1916 const char* context_data[][2] = {
1900 {"\"use strict\";", ""}, 1917 {"\"use strict\";", ""},
1901 {"\"use strong\";", ""}, 1918 {"\"use strong\";", ""},
1902 {"var eval; function test_func() {\"use strict\"; ", "}"}, 1919 {"var eval; function test_func() {\"use strict\"; ", "}"},
1903 {"var eval; function test_func() {\"use strong\"; ", "}"}, 1920 {"var eval; function test_func() {\"use strong\"; ", "}"},
(...skipping 5324 matching lines...) Expand 10 before | Expand all | Expand 10 after
7228 NULL 7245 NULL
7229 }; 7246 };
7230 // clang-format on 7247 // clang-format on
7231 7248
7232 static const ParserFlag fail_flags[] = { 7249 static const ParserFlag fail_flags[] = {
7233 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, 7250 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst,
7234 kAllowHarmonyDestructuring}; 7251 kAllowHarmonyDestructuring};
7235 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, 7252 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags,
7236 arraysize(fail_flags)); 7253 arraysize(fail_flags));
7237 } 7254 }
7255
7256
7257 TEST(EscapedKeywords) {
7258 // clang-format off
7259 const char* sloppy_context_data[][2] = {
7260 {"", ""},
7261 {NULL, NULL}
7262 };
7263
7264 const char* strict_context_data[][2] = {
7265 {"'use strict';", ""},
7266 {NULL, NULL}
7267 };
7268
7269 const char* fail_data[] = {
7270 "for (var i = 0; i < 100; ++i) { br\\u0065ak; }",
7271 "cl\\u0061ss Foo {}",
7272 "var x = cl\\u0061ss {}",
7273 "\\u0063onst foo = 1;",
7274 "while (i < 10) { if (i++ & 1) c\\u006fntinue; this.x++; }",
7275 "d\\u0065bugger;",
7276 "d\\u0065lete this.a;",
7277 "\\u0063o { } while(0)",
7278 "if (d\\u006f { true }) {}",
7279 "if (false) { this.a = 1; } \\u0065lse { this.b = 1; }",
7280 "e\\u0078port var foo;",
7281 "try { } catch (e) {} f\\u0069nally { }",
7282 "f\\u006fr (var i = 0; i < 10; ++i);",
7283 "f\\u0075nction fn() {}",
7284 "var f = f\\u0075nction() {}",
7285 "\\u0069f (true) { }",
7286 "\\u0069mport blah from './foo.js';",
7287 "n\\u0065w function f() {}",
7288 "(function() { r\\u0065turn; })()",
7289 "class C extends function() {} { constructor() { sup\\u0065r() } }",
7290 "class C extends function() {} { constructor() { sup\\u0065r.a = 1 } }",
7291 "sw\\u0069tch (this.a) {}",
7292 "var x = th\\u0069s;",
7293 "th\\u0069s.a = 1;",
7294 "thr\\u006fw 'boo';",
7295 "t\\u0072y { true } catch (e) {}",
7296 "var x = typ\\u0065of 'blah'",
7297 "v\\u0061r a = true",
7298 "var v\\u0061r = true",
7299 "(function() { return v\\u006fid 0; })()",
7300 "wh\\u0069le (true) { }",
7301 "w\\u0069th (this.scope) { }",
7302 "(function*() { y\\u0069eld 1; })()",
7303
7304 "var \\u0065num = 1;",
7305 "var { \\u0065num } = {}",
7306 "(\\u0065num = 1);",
7307
7308 // Null / Boolean literals
7309 "(x === n\\u0075ll);",
7310 "var x = n\\u0075ll;",
7311 "var n\\u0075ll = 1;",
7312 "var { n\\u0075ll } = { 1 };",
7313 "n\\u0075ll = 1;",
7314 "(x === tr\\u0075e);",
7315 "var x = tr\\u0075e;",
7316 "var tr\\u0075e = 1;",
7317 "var { tr\\u0075e } = {};",
7318 "tr\\u0075e = 1;",
7319 "(x === f\\u0061lse);",
7320 "var x = f\\u0061lse;",
7321 "var f\\u0061lse = 1;",
7322 "var { f\\u0061lse } = {};",
7323 "f\\u0061lse = 1;",
7324
7325 // TODO(caitp): consistent error messages for labeled statements and
7326 // expressions
7327 "switch (this.a) { c\\u0061se 6: break; }",
7328 "try { } c\\u0061tch (e) {}",
7329 "switch (this.a) { d\\u0065fault: break; }",
7330 "class C \\u0065xtends function B() {} {}",
7331 "for (var a i\\u006e this) {}",
7332 "if ('foo' \\u0069n this) {}",
7333 "if (this \\u0069nstanceof Array) {}",
7334 "(n\\u0065w function f() {})",
7335 "(typ\\u0065of 123)",
7336 "(v\\u006fid 0)",
7337 "do { ; } wh\\u0069le (true) { }",
7338 "(function*() { return (n++, y\\u0069eld 1); })()",
7339 "class C { st\\u0061tic bar() {} }",
7340
7341 "(y\\u0069eld);",
7342 "var y\\u0069eld = 1;",
7343 "var { y\\u0069eld } = {};",
7344 NULL
7345 };
7346 // clang-format on
7347
7348 static const ParserFlag always_flags[] = {kAllowHarmonySloppy,
7349 kAllowHarmonyDestructuring};
7350 RunParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0,
7351 always_flags, arraysize(always_flags));
7352 RunParserSyncTest(strict_context_data, fail_data, kError, NULL, 0,
7353 always_flags, arraysize(always_flags));
7354 RunModuleParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0,
7355 always_flags, arraysize(always_flags));
7356
7357 // clang-format off
7358 const char* let_data[] = {
7359 "var l\\u0065t = 1;",
7360 "l\\u0065t = 1;",
7361 "(l\\u0065t === 1);",
7362 NULL
7363 };
7364 // clang-format on
7365
7366 RunParserSyncTest(sloppy_context_data, let_data, kError, NULL, 0,
7367 always_flags, arraysize(always_flags));
7368 RunParserSyncTest(strict_context_data, let_data, kError, NULL, 0,
7369 always_flags, arraysize(always_flags));
7370
7371 static const ParserFlag sloppy_let_flags[] = {
7372 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kAllowHarmonyDestructuring};
7373 RunParserSyncTest(sloppy_context_data, let_data, kError, NULL, 0,
7374 sloppy_let_flags, arraysize(sloppy_let_flags));
7375
7376 // Non-errors in sloppy mode
7377 const char* valid_data[] = {"(\\u0069mplements = 1);",
7378 "var impl\\u0065ments = 1;",
7379 "var { impl\\u0065ments } = {};",
7380 "(\\u0069nterface = 1);",
7381 "var int\\u0065rface = 1;",
7382 "var { int\\u0065rface } = {};",
7383 "(p\\u0061ckage = 1);",
7384 "var packa\\u0067e = 1;",
7385 "var { packa\\u0067e } = {};",
7386 "(p\\u0072ivate = 1);",
7387 "var p\\u0072ivate;",
7388 "var { p\\u0072ivate } = {};",
7389 "(prot\\u0065cted);",
7390 "var prot\\u0065cted = 1;",
7391 "var { prot\\u0065cted } = {};",
7392 "(publ\\u0069c);",
7393 "var publ\\u0069c = 1;",
7394 "var { publ\\u0069c } = {};",
7395 NULL};
7396 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess, NULL, 0,
7397 always_flags, arraysize(always_flags));
7398 RunParserSyncTest(strict_context_data, valid_data, kError, NULL, 0,
7399 always_flags, arraysize(always_flags));
7400 RunModuleParserSyncTest(strict_context_data, valid_data, kError, NULL, 0,
7401 always_flags, arraysize(always_flags));
7402 }
OLDNEW
« src/scanner.cc ('K') | « src/token.h ('k') | test/mozilla/mozilla.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698