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

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: oops 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
« no previous file with comments | « 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 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script)); 1457 v8::Script::Compile(v8::String::NewFromUtf8(CcTest::isolate(), script));
1457 CHECK(try_catch.HasCaught()); 1458 CHECK(try_catch.HasCaught());
1458 v8::String::Utf8Value exception(try_catch.Exception()); 1459 v8::String::Utf8Value exception(try_catch.Exception());
1459 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.", 1460 CHECK_EQ("SyntaxError: Octal literals are not allowed in strict mode.",
1460 *exception); 1461 *exception);
1461 } 1462 }
1462 1463
1463 1464
1464 void RunParserSyncTest(const char* context_data[][2], 1465 void RunParserSyncTest(const char* context_data[][2],
1465 const char* statement_data[], 1466 const char* statement_data[],
1466 ParserSyncTestResult result) { 1467 ParserSyncTestResult result,
1468 const ParserFlag* flags = NULL,
1469 int flags_len = 0) {
1467 v8::HandleScope handles(CcTest::isolate()); 1470 v8::HandleScope handles(CcTest::isolate());
1468 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1471 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1469 v8::Context::Scope context_scope(context); 1472 v8::Context::Scope context_scope(context);
1470 1473
1471 int marker; 1474 int marker;
1472 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1475 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1473 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1476 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1474 1477
1475 static const ParserFlag flags[] = { 1478 static const ParserFlag default_flags[] = {
1476 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1479 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1477 kAllowForOf, kAllowNativesSyntax 1480 kAllowForOf, kAllowNativesSyntax
1478 }; 1481 };
1482 if (!flags) {
1483 flags = default_flags;
1484 flags_len = ARRAY_SIZE(default_flags);
1485 }
1479 for (int i = 0; context_data[i][0] != NULL; ++i) { 1486 for (int i = 0; context_data[i][0] != NULL; ++i) {
1480 for (int j = 0; statement_data[j] != NULL; ++j) { 1487 for (int j = 0; statement_data[j] != NULL; ++j) {
1481 int kPrefixLen = i::StrLength(context_data[i][0]); 1488 int kPrefixLen = i::StrLength(context_data[i][0]);
1482 int kStatementLen = i::StrLength(statement_data[j]); 1489 int kStatementLen = i::StrLength(statement_data[j]);
1483 int kSuffixLen = i::StrLength(context_data[i][1]); 1490 int kSuffixLen = i::StrLength(context_data[i][1]);
1484 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen; 1491 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen;
1485 1492
1486 // Plug the source code pieces together. 1493 // Plug the source code pieces together.
1487 i::ScopedVector<char> program(kProgramSize + 1); 1494 i::ScopedVector<char> program(kProgramSize + 1);
1488 int length = i::OS::SNPrintF(program, 1495 int length = i::OS::SNPrintF(program,
1489 "%s%s%s", 1496 "%s%s%s",
1490 context_data[i][0], 1497 context_data[i][0],
1491 statement_data[j], 1498 statement_data[j],
1492 context_data[i][1]); 1499 context_data[i][1]);
1493 CHECK(length == kProgramSize); 1500 CHECK(length == kProgramSize);
1494 TestParserSync(program.start(), 1501 TestParserSync(program.start(),
1495 flags, 1502 flags,
1496 ARRAY_SIZE(flags), 1503 flags_len,
1497 result); 1504 result);
1498 } 1505 }
1499 } 1506 }
1500 } 1507 }
1501 1508
1502 1509
1503 TEST(ErrorsEvalAndArguments) { 1510 TEST(ErrorsEvalAndArguments) {
1504 // Tests that both preparsing and parsing produce the right kind of errors for 1511 // Tests that both preparsing and parsing produce the right kind of errors for
1505 // using "eval" and "arguments" as identifiers. Without the strict mode, it's 1512 // using "eval" and "arguments" as identifiers. Without the strict mode, it's
1506 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it 1513 // 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
2313 "if: 4", 2320 "if: 4",
2314 "interface: 5", 2321 "interface: 5",
2315 "super: 6", 2322 "super: 6",
2316 "eval: 7", 2323 "eval: 7",
2317 "arguments: 8", 2324 "arguments: 8",
2318 NULL 2325 NULL
2319 }; 2326 };
2320 2327
2321 RunParserSyncTest(context_data, statement_data, kSuccess); 2328 RunParserSyncTest(context_data, statement_data, kSuccess);
2322 } 2329 }
2330
2331
2332 TEST(TooManyArguments) {
2333 const char* context_data[][2] = {
2334 {"foo(", "0)"},
2335 { NULL, NULL }
2336 };
2337
2338 using v8::internal::Code;
2339 char statement[Code::kMaxArguments * 2];
2340 for (int i = 0; i < Code::kMaxArguments; ++i) {
2341 statement[2 * i] = '0';
2342 statement[2 * i + 1] = ',';
2343 }
2344
2345 const char* statement_data[] = {
2346 statement,
2347 NULL
2348 };
2349
2350 // The test is quite slow, so run it with a reduced set of flags.
2351 static const ParserFlag empty_flags[] = {kAllowLazy};
2352 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
2353 }
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698