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

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

Issue 194503004: Move ParseArguments to ParserBase and add tests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 9 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
« src/preparser.h ('K') | « src/preparser.cc ('k') | 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 17 matching lines...) Expand all
28 #include <stdlib.h> 28 #include <stdlib.h>
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <string.h> 30 #include <string.h>
31 31
32 #include "v8.h" 32 #include "v8.h"
33 33
34 #include "cctest.h" 34 #include "cctest.h"
35 #include "compiler.h" 35 #include "compiler.h"
36 #include "execution.h" 36 #include "execution.h"
37 #include "isolate.h" 37 #include "isolate.h"
38 #include "objects.h"
38 #include "parser.h" 39 #include "parser.h"
39 #include "preparser.h" 40 #include "preparser.h"
40 #include "scanner-character-streams.h" 41 #include "scanner-character-streams.h"
41 #include "token.h" 42 #include "token.h"
42 #include "utils.h" 43 #include "utils.h"
43 44
44 TEST(ScanKeywords) { 45 TEST(ScanKeywords) {
45 struct KeywordToken { 46 struct KeywordToken {
46 const char* keyword; 47 const char* keyword;
47 i::Token::Value token; 48 i::Token::Value token;
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); 1455 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script));
1455 CHECK(try_catch.HasCaught()); 1456 CHECK(try_catch.HasCaught());
1456 v8::String::Utf8Value exception(try_catch.Exception()); 1457 v8::String::Utf8Value exception(try_catch.Exception());
1457 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", 1458 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
1458 *exception); 1459 *exception);
1459 } 1460 }
1460 1461
1461 1462
1462 void RunParserSyncTest(const char* context_data[][2], 1463 void RunParserSyncTest(const char* context_data[][2],
1463 const char* statement_data[], 1464 const char* statement_data[],
1464 ParserSyncTestResult result) { 1465 ParserSyncTestResult result,
1466 const ParserFlag* flags = NULL,
1467 int flags_len = 0) {
1465 v8::HandleScope handles(CcTest::isolate()); 1468 v8::HandleScope handles(CcTest::isolate());
1466 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1469 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1467 v8::Context::Scope context_scope(context); 1470 v8::Context::Scope context_scope(context);
1468 1471
1469 int marker; 1472 int marker;
1470 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1473 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1471 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1474 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1472 1475
1473 static const ParserFlag flags[] = { 1476 static const ParserFlag default_flags[] = {
1474 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1477 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1475 kAllowForOf, kAllowNativesSyntax 1478 kAllowForOf, kAllowNativesSyntax
1476 }; 1479 };
1480 if (!flags) {
1481 flags = default_flags;
1482 flags_len = ARRAY_SIZE(default_flags);
1483 }
1477 for (int i = 0; context_data[i][0] != NULL; ++i) { 1484 for (int i = 0; context_data[i][0] != NULL; ++i) {
1478 for (int j = 0; statement_data[j] != NULL; ++j) { 1485 for (int j = 0; statement_data[j] != NULL; ++j) {
1479 int kPrefixLen = i::StrLength(context_data[i][0]); 1486 int kPrefixLen = i::StrLength(context_data[i][0]);
1480 int kStatementLen = i::StrLength(statement_data[j]); 1487 int kStatementLen = i::StrLength(statement_data[j]);
1481 int kSuffixLen = i::StrLength(context_data[i][1]); 1488 int kSuffixLen = i::StrLength(context_data[i][1]);
1482 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen; 1489 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen;
1483 1490
1484 // Plug the source code pieces together. 1491 // Plug the source code pieces together.
1485 i::ScopedVector<char> program(kProgramSize + 1); 1492 i::ScopedVector<char> program(kProgramSize + 1);
1486 int length = i::OS::SNPrintF(program, 1493 int length = i::OS::SNPrintF(program,
1487 "%s%s%s", 1494 "%s%s%s",
1488 context_data[i][0], 1495 context_data[i][0],
1489 statement_data[j], 1496 statement_data[j],
1490 context_data[i][1]); 1497 context_data[i][1]);
1491 CHECK(length == kProgramSize); 1498 CHECK(length == kProgramSize);
1492 TestParserSync(program.start(), 1499 TestParserSync(program.start(),
1493 flags, 1500 flags,
1494 ARRAY_SIZE(flags), 1501 flags_len,
1495 result); 1502 result);
1496 } 1503 }
1497 } 1504 }
1498 } 1505 }
1499 1506
1500 1507
1501 TEST(ErrorsEvalAndArguments) { 1508 TEST(ErrorsEvalAndArguments) {
1502 // Tests that both preparsing and parsing produce the right kind of errors for 1509 // Tests that both preparsing and parsing produce the right kind of errors for
1503 // using "eval" and "arguments" as identifiers. Without the strict mode, it's 1510 // using "eval" and "arguments" as identifiers. Without the strict mode, it's
1504 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it 1511 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 "if: 4", 2318 "if: 4",
2312 "interface: 5", 2319 "interface: 5",
2313 "super: 6", 2320 "super: 6",
2314 "eval: 7", 2321 "eval: 7",
2315 "arguments: 8", 2322 "arguments: 8",
2316 NULL 2323 NULL
2317 }; 2324 };
2318 2325
2319 RunParserSyncTest(context_data, statement_data, kSuccess); 2326 RunParserSyncTest(context_data, statement_data, kSuccess);
2320 } 2327 }
2328
2329
2330 TEST(TooManyArguments) {
2331 const char* context_data[][2] = {
2332 {"foo(", "0)"},
2333 { NULL, NULL }
2334 };
2335
2336 using v8::internal::Code;
2337 char statement[Code::kMaxArguments * 2];
2338 for (int i = 0; i < Code::kMaxArguments; ++i) {
2339 statement[2 * i] = '0';
2340 statement[2 * i + 1] = ',';
2341 }
2342
2343 const char* statement_data[] = {
2344 statement,
2345 NULL
2346 };
2347
2348 // The test is quite slow, so run it with a reduced set of flags.
2349 static const ParserFlag empty_flags[] = {kAllowLazy};
2350 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
2351 CHECK(false);
2352 }
OLDNEW
« src/preparser.h ('K') | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698