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

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

Issue 349603004: test-parsing: Add functionality to specify "always true flags". (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: maybe like this? Created 6 years, 6 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 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 "Expected error on:\n" 1291 "Expected error on:\n"
1292 "\t%s\n" 1292 "\t%s\n"
1293 "However, parser and preparser succeeded", 1293 "However, parser and preparser succeeded",
1294 source->ToCString().get()); 1294 source->ToCString().get());
1295 CHECK(false); 1295 CHECK(false);
1296 } 1296 }
1297 } 1297 }
1298 1298
1299 1299
1300 void TestParserSync(const char* source, 1300 void TestParserSync(const char* source,
1301 const ParserFlag* flag_list, 1301 const ParserFlag* varying_flags,
1302 size_t flag_list_length, 1302 size_t varying_flags_length,
1303 ParserSyncTestResult result = kSuccessOrError) { 1303 ParserSyncTestResult result = kSuccessOrError,
1304 const ParserFlag* always_true_flags = NULL,
1305 size_t always_true_flags_length = 0) {
1304 i::Handle<i::String> str = 1306 i::Handle<i::String> str =
1305 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(source); 1307 CcTest::i_isolate()->factory()->NewStringFromAsciiChecked(source);
1306 for (int bits = 0; bits < (1 << flag_list_length); bits++) { 1308 for (int bits = 0; bits < (1 << varying_flags_length); bits++) {
1307 i::EnumSet<ParserFlag> flags; 1309 i::EnumSet<ParserFlag> flags;
1308 for (size_t flag_index = 0; flag_index < flag_list_length; flag_index++) { 1310 for (size_t flag_index = 0; flag_index < varying_flags_length;
1309 if ((bits & (1 << flag_index)) != 0) flags.Add(flag_list[flag_index]); 1311 ++flag_index) {
1312 if ((bits & (1 << flag_index)) != 0) flags.Add(varying_flags[flag_index]);
1313 }
1314 for (size_t flag_index = 0; flag_index < always_true_flags_length;
1315 ++flag_index) {
1316 flags.Add(always_true_flags[flag_index]);
1310 } 1317 }
1311 TestParserSyncWithFlags(str, flags, result); 1318 TestParserSyncWithFlags(str, flags, result);
1312 } 1319 }
1313 } 1320 }
1314 1321
1315 1322
1316 TEST(ParserSync) { 1323 TEST(ParserSync) {
1317 const char* context_data[][2] = { 1324 const char* context_data[][2] = {
1318 { "", "" }, 1325 { "", "" },
1319 { "{", "}" }, 1326 { "{", "}" },
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 v8::String::Utf8Value exception(try_catch.Exception()); 1458 v8::String::Utf8Value exception(try_catch.Exception());
1452 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", 1459 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
1453 *exception); 1460 *exception);
1454 } 1461 }
1455 1462
1456 1463
1457 void RunParserSyncTest(const char* context_data[][2], 1464 void RunParserSyncTest(const char* context_data[][2],
1458 const char* statement_data[], 1465 const char* statement_data[],
1459 ParserSyncTestResult result, 1466 ParserSyncTestResult result,
1460 const ParserFlag* flags = NULL, 1467 const ParserFlag* flags = NULL,
1461 int flags_len = 0) { 1468 int flags_len = 0,
1469 const ParserFlag* always_true_flags = NULL,
1470 int always_true_flags_len = 0) {
1462 v8::HandleScope handles(CcTest::isolate()); 1471 v8::HandleScope handles(CcTest::isolate());
1463 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1472 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1464 v8::Context::Scope context_scope(context); 1473 v8::Context::Scope context_scope(context);
1465 1474
1466 int marker; 1475 int marker;
1467 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1476 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1468 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1477 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1469 1478
1470 static const ParserFlag default_flags[] = { 1479 static const ParserFlag default_flags[] = {
1471 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1480 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1472 kAllowForOf, kAllowNativesSyntax 1481 kAllowForOf, kAllowNativesSyntax
1473 }; 1482 };
1474 if (!flags) { 1483 ParserFlag* generated_flags = NULL;
1484 if (flags == NULL) {
1475 flags = default_flags; 1485 flags = default_flags;
1476 flags_len = ARRAY_SIZE(default_flags); 1486 flags_len = ARRAY_SIZE(default_flags);
1487 if (always_true_flags != NULL) {
1488 // Remove always_true_flags from default_flags.
1489 CHECK(always_true_flags_len < flags_len);
1490 generated_flags = new ParserFlag[flags_len - always_true_flags_len];
1491 int flag_index = 0;
1492 for (int i = 0; i < flags_len; ++i) {
1493 bool use_flag = true;
1494 for (int j = 0; j < always_true_flags_len; ++j) {
1495 if (flags[i] == always_true_flags[j]) {
1496 use_flag = false;
1497 break;
1498 }
1499 }
1500 if (use_flag) generated_flags[flag_index++] = flags[i];
1501 }
1502 CHECK(flag_index == flags_len - always_true_flags_len);
1503 flags_len = flag_index;
1504 flags = generated_flags;
1505 }
1477 } 1506 }
1478 for (int i = 0; context_data[i][0] != NULL; ++i) { 1507 for (int i = 0; context_data[i][0] != NULL; ++i) {
1479 for (int j = 0; statement_data[j] != NULL; ++j) { 1508 for (int j = 0; statement_data[j] != NULL; ++j) {
1480 int kPrefixLen = i::StrLength(context_data[i][0]); 1509 int kPrefixLen = i::StrLength(context_data[i][0]);
1481 int kStatementLen = i::StrLength(statement_data[j]); 1510 int kStatementLen = i::StrLength(statement_data[j]);
1482 int kSuffixLen = i::StrLength(context_data[i][1]); 1511 int kSuffixLen = i::StrLength(context_data[i][1]);
1483 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen; 1512 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen;
1484 1513
1485 // Plug the source code pieces together. 1514 // Plug the source code pieces together.
1486 i::ScopedVector<char> program(kProgramSize + 1); 1515 i::ScopedVector<char> program(kProgramSize + 1);
1487 int length = i::SNPrintF(program, 1516 int length = i::SNPrintF(program,
1488 "%s%s%s", 1517 "%s%s%s",
1489 context_data[i][0], 1518 context_data[i][0],
1490 statement_data[j], 1519 statement_data[j],
1491 context_data[i][1]); 1520 context_data[i][1]);
1492 CHECK(length == kProgramSize); 1521 CHECK(length == kProgramSize);
1493 TestParserSync(program.start(), 1522 TestParserSync(program.start(),
1494 flags, 1523 flags,
1495 flags_len, 1524 flags_len,
1496 result); 1525 result,
1526 always_true_flags,
1527 always_true_flags_len);
1497 } 1528 }
1498 } 1529 }
1530 delete[] generated_flags;
1499 } 1531 }
1500 1532
1501 1533
1502 TEST(ErrorsEvalAndArguments) { 1534 TEST(ErrorsEvalAndArguments) {
1503 // Tests that both preparsing and parsing produce the right kind of errors for 1535 // Tests that both preparsing and parsing produce the right kind of errors for
1504 // using "eval" and "arguments" as identifiers. Without the strict mode, it's 1536 // using "eval" and "arguments" as identifiers. Without the strict mode, it's
1505 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it 1537 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it
1506 // isn't. 1538 // isn't.
1507 const char* context_data[][2] = { 1539 const char* context_data[][2] = {
1508 { "\"use strict\";", "" }, 1540 { "\"use strict\";", "" },
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 "var foo = yield = 1;", 1789 "var foo = yield = 1;",
1758 "++yield;", 1790 "++yield;",
1759 "yield++;", 1791 "yield++;",
1760 NULL 1792 NULL
1761 }; 1793 };
1762 1794
1763 RunParserSyncTest(context_data, statement_data, kError); 1795 RunParserSyncTest(context_data, statement_data, kError);
1764 } 1796 }
1765 1797
1766 1798
1767 TEST(ErrorsYield) { 1799 TEST(NoErrorsYield) {
1768 const char* context_data[][2] = { 1800 const char* context_data[][2] = {
1769 { "function * is_gen() {", "}" }, 1801 { "function * is_gen() {", "}" },
1770 { NULL, NULL } 1802 { NULL, NULL }
1771 }; 1803 };
1772 1804
1773 const char* statement_data[] = { 1805 const char* statement_data[] = {
1774 "yield 2;", // this is legal inside generator 1806 "yield 2;", // this is legal inside generator
1775 "yield * 2;", // this is legal inside generator 1807 "yield * 2;", // this is legal inside generator
1776 NULL 1808 NULL
1777 }; 1809 };
1778 1810
1779 // Here we cannot assert that there is no error, since there will be without 1811 // This test requires kAllowGenerators to succeed.
1780 // the kAllowGenerators flag. However, we test that Parser and PreParser 1812 static const ParserFlag always_true_flags[] = {
1781 // produce the same errors. 1813 kAllowGenerators
1782 RunParserSyncTest(context_data, statement_data, kSuccessOrError); 1814 };
1815 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1816 always_true_flags, 1);
1783 } 1817 }
1784 1818
1785 1819
1786 TEST(ErrorsNameOfStrictFunction) { 1820 TEST(ErrorsNameOfStrictFunction) {
1787 // Tests that illegal tokens as names of a strict function produce the correct 1821 // Tests that illegal tokens as names of a strict function produce the correct
1788 // errors. 1822 // errors.
1789 const char* context_data[][2] = { 1823 const char* context_data[][2] = {
1790 { "", ""}, 1824 { "", ""},
1791 { "\"use strict\";", ""}, 1825 { "\"use strict\";", ""},
1792 { NULL, NULL } 1826 { NULL, NULL }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2123 const char* context_data[][2] = { 2157 const char* context_data[][2] = {
2124 {"", ""}, 2158 {"", ""},
2125 { NULL, NULL } 2159 { NULL, NULL }
2126 }; 2160 };
2127 2161
2128 const char* statement_data[] = { 2162 const char* statement_data[] = {
2129 "%someintrinsic(arg)", 2163 "%someintrinsic(arg)",
2130 NULL 2164 NULL
2131 }; 2165 };
2132 2166
2133 // Parsing will fail or succeed depending on whether we allow natives syntax 2167 // This test requires kAllowNativesSyntax to succeed.
2134 // or not. 2168 static const ParserFlag always_true_flags[] = {
2135 RunParserSyncTest(context_data, statement_data, kSuccessOrError); 2169 kAllowNativesSyntax
2170 };
2171
2172 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2173 always_true_flags, 1);
2136 } 2174 }
2137 2175
2138 2176
2139 TEST(NoErrorsNewExpression) { 2177 TEST(NoErrorsNewExpression) {
2140 const char* context_data[][2] = { 2178 const char* context_data[][2] = {
2141 {"", ""}, 2179 {"", ""},
2142 {"var f =", ""}, 2180 {"var f =", ""},
2143 { NULL, NULL } 2181 { NULL, NULL }
2144 }; 2182 };
2145 2183
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
2542 v8::Local<v8::String> source = 2580 v8::Local<v8::String> source =
2543 v8::String::NewFromTwoByte(isolate, two_byte_source); 2581 v8::String::NewFromTwoByte(isolate, two_byte_source);
2544 v8::Local<v8::Value> result = CompileRun(source); 2582 v8::Local<v8::Value> result = CompileRun(source);
2545 CHECK(result->IsString()); 2583 CHECK(result->IsString());
2546 v8::Local<v8::String> expected_name = 2584 v8::Local<v8::String> expected_name =
2547 v8::String::NewFromTwoByte(isolate, two_byte_name); 2585 v8::String::NewFromTwoByte(isolate, two_byte_name);
2548 CHECK(result->Equals(expected_name)); 2586 CHECK(result->Equals(expected_name));
2549 i::DeleteArray(two_byte_source); 2587 i::DeleteArray(two_byte_source);
2550 i::DeleteArray(two_byte_name); 2588 i::DeleteArray(two_byte_name);
2551 } 2589 }
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