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

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

Issue 7572018: Minimize malloc heap allocation on process startup. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 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 | « test/cctest/test-heap.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 full_stop.AddChar('i'); 127 full_stop.AddChar('i');
128 CHECK_EQ(i::Token::IDENTIFIER, full_stop.token()); 128 CHECK_EQ(i::Token::IDENTIFIER, full_stop.token());
129 full_stop.Fail(); 129 full_stop.Fail();
130 CHECK_EQ(i::Token::IDENTIFIER, full_stop.token()); 130 CHECK_EQ(i::Token::IDENTIFIER, full_stop.token());
131 full_stop.AddChar('f'); 131 full_stop.AddChar('f');
132 CHECK_EQ(i::Token::IDENTIFIER, full_stop.token()); 132 CHECK_EQ(i::Token::IDENTIFIER, full_stop.token());
133 } 133 }
134 134
135 135
136 TEST(ScanHTMLEndComments) { 136 TEST(ScanHTMLEndComments) {
137 v8::V8::Initialize();
138
137 // Regression test. See: 139 // Regression test. See:
138 // http://code.google.com/p/chromium/issues/detail?id=53548 140 // http://code.google.com/p/chromium/issues/detail?id=53548
139 // Tests that --> is correctly interpreted as comment-to-end-of-line if there 141 // Tests that --> is correctly interpreted as comment-to-end-of-line if there
140 // is only whitespace before it on the line (with comments considered as 142 // is only whitespace before it on the line (with comments considered as
141 // whitespace, even a multiline-comment containing a newline). 143 // whitespace, even a multiline-comment containing a newline).
142 // This was not the case if it occurred before the first real token 144 // This was not the case if it occurred before the first real token
143 // in the input. 145 // in the input.
144 const char* tests[] = { 146 const char* tests[] = {
145 // Before first real token. 147 // Before first real token.
146 "--> is eol-comment\nvar y = 37;\n", 148 "--> is eol-comment\nvar y = 37;\n",
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 CHECK_EQ(10, error_location.beg_pos); 258 CHECK_EQ(10, error_location.beg_pos);
257 CHECK_EQ(11, error_location.end_pos); 259 CHECK_EQ(11, error_location.end_pos);
258 // Should not crash. 260 // Should not crash.
259 const char* message = pre_impl->BuildMessage(); 261 const char* message = pre_impl->BuildMessage();
260 i::Vector<const char*> args = pre_impl->BuildArgs(); 262 i::Vector<const char*> args = pre_impl->BuildArgs();
261 CHECK_GT(strlen(message), 0); 263 CHECK_GT(strlen(message), 0);
262 } 264 }
263 265
264 266
265 TEST(StandAlonePreParser) { 267 TEST(StandAlonePreParser) {
268 v8::V8::Initialize();
269
266 int marker; 270 int marker;
267 i::Isolate::Current()->stack_guard()->SetStackLimit( 271 i::Isolate::Current()->stack_guard()->SetStackLimit(
268 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 272 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
269 273
270 const char* programs[] = { 274 const char* programs[] = {
271 "{label: 42}", 275 "{label: 42}",
272 "var x = 42;", 276 "var x = 42;",
273 "function foo(x, y) { return x + y; }", 277 "function foo(x, y) { return x + y; }",
274 "%ArgleBargle(glop);", 278 "%ArgleBargle(glop);",
275 "var x = new new Function('this.x = 42');", 279 "var x = new new Function('this.x = 42');",
(...skipping 16 matching lines...) Expand all
292 true, 296 true,
293 stack_limit); 297 stack_limit);
294 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); 298 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result);
295 i::ScriptDataImpl data(log.ExtractData()); 299 i::ScriptDataImpl data(log.ExtractData());
296 CHECK(!data.has_error()); 300 CHECK(!data.has_error());
297 } 301 }
298 } 302 }
299 303
300 304
301 TEST(RegressChromium62639) { 305 TEST(RegressChromium62639) {
306 v8::V8::Initialize();
307
302 int marker; 308 int marker;
303 i::Isolate::Current()->stack_guard()->SetStackLimit( 309 i::Isolate::Current()->stack_guard()->SetStackLimit(
304 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 310 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
305 311
306 const char* program = "var x = 'something';\n" 312 const char* program = "var x = 'something';\n"
307 "escape: function() {}"; 313 "escape: function() {}";
308 // Fails parsing expecting an identifier after "function". 314 // Fails parsing expecting an identifier after "function".
309 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), 315 // Before fix, didn't check *ok after Expect(Token::Identifier, ok),
310 // and then used the invalid currently scanned literal. This always 316 // and then used the invalid currently scanned literal. This always
311 // failed in debug mode, and sometimes crashed in release mode. 317 // failed in debug mode, and sometimes crashed in release mode.
312 318
313 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), 319 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program),
314 static_cast<unsigned>(strlen(program))); 320 static_cast<unsigned>(strlen(program)));
315 i::ScriptDataImpl* data = 321 i::ScriptDataImpl* data =
316 i::ParserApi::PreParse(&stream, NULL); 322 i::ParserApi::PreParse(&stream, NULL);
317 CHECK(data->HasError()); 323 CHECK(data->HasError());
318 delete data; 324 delete data;
319 } 325 }
320 326
321 327
322 TEST(Regress928) { 328 TEST(Regress928) {
329 v8::V8::Initialize();
330
323 // Preparsing didn't consider the catch clause of a try statement 331 // Preparsing didn't consider the catch clause of a try statement
324 // as with-content, which made it assume that a function inside 332 // as with-content, which made it assume that a function inside
325 // the block could be lazily compiled, and an extra, unexpected, 333 // the block could be lazily compiled, and an extra, unexpected,
326 // entry was added to the data. 334 // entry was added to the data.
327 int marker; 335 int marker;
328 i::Isolate::Current()->stack_guard()->SetStackLimit( 336 i::Isolate::Current()->stack_guard()->SetStackLimit(
329 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 337 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
330 338
331 const char* program = 339 const char* program =
332 "try { } catch (e) { var foo = function () { /* first */ } }" 340 "try { } catch (e) { var foo = function () { /* first */ } }"
(...skipping 20 matching lines...) Expand all
353 second_function + static_cast<int>(strlen("function () ")); 361 second_function + static_cast<int>(strlen("function () "));
354 CHECK_EQ('{', program[second_lbrace]); 362 CHECK_EQ('{', program[second_lbrace]);
355 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace); 363 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace);
356 CHECK(entry2.is_valid()); 364 CHECK(entry2.is_valid());
357 CHECK_EQ('}', program[entry2.end_pos() - 1]); 365 CHECK_EQ('}', program[entry2.end_pos() - 1]);
358 delete data; 366 delete data;
359 } 367 }
360 368
361 369
362 TEST(PreParseOverflow) { 370 TEST(PreParseOverflow) {
371 v8::V8::Initialize();
372
363 int marker; 373 int marker;
364 i::Isolate::Current()->stack_guard()->SetStackLimit( 374 i::Isolate::Current()->stack_guard()->SetStackLimit(
365 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 375 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
366 376
367 size_t kProgramSize = 1024 * 1024; 377 size_t kProgramSize = 1024 * 1024;
368 i::SmartPointer<char> program( 378 i::SmartPointer<char> program(
369 reinterpret_cast<char*>(malloc(kProgramSize + 1))); 379 reinterpret_cast<char*>(malloc(kProgramSize + 1)));
370 memset(*program, '(', kProgramSize); 380 memset(*program, '(', kProgramSize);
371 program[kProgramSize] = '\0'; 381 program[kProgramSize] = '\0';
372 382
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 i::Token::Value actual = scanner.Next(); 613 i::Token::Value actual = scanner.Next();
604 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); 614 CHECK_EQ(i::Token::String(expected), i::Token::String(actual));
605 if (scanner.location().end_pos == skip_pos) { 615 if (scanner.location().end_pos == skip_pos) {
606 scanner.SeekForward(skip_to); 616 scanner.SeekForward(skip_to);
607 } 617 }
608 i++; 618 i++;
609 } while (expected_tokens[i] != i::Token::ILLEGAL); 619 } while (expected_tokens[i] != i::Token::ILLEGAL);
610 } 620 }
611 621
612 TEST(StreamScanner) { 622 TEST(StreamScanner) {
623 v8::V8::Initialize();
624
613 const char* str1 = "{ foo get for : */ <- \n\n /*foo*/ bib"; 625 const char* str1 = "{ foo get for : */ <- \n\n /*foo*/ bib";
614 i::Utf8ToUC16CharacterStream stream1(reinterpret_cast<const i::byte*>(str1), 626 i::Utf8ToUC16CharacterStream stream1(reinterpret_cast<const i::byte*>(str1),
615 static_cast<unsigned>(strlen(str1))); 627 static_cast<unsigned>(strlen(str1)));
616 i::Token::Value expectations1[] = { 628 i::Token::Value expectations1[] = {
617 i::Token::LBRACE, 629 i::Token::LBRACE,
618 i::Token::IDENTIFIER, 630 i::Token::IDENTIFIER,
619 i::Token::IDENTIFIER, 631 i::Token::IDENTIFIER,
620 i::Token::FOR, 632 i::Token::FOR,
621 i::Token::COLON, 633 i::Token::COLON,
622 i::Token::MUL, 634 i::Token::MUL,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 CHECK(scanner.is_literal_ascii()); 695 CHECK(scanner.is_literal_ascii());
684 i::Vector<const char> actual = scanner.literal_ascii_string(); 696 i::Vector<const char> actual = scanner.literal_ascii_string();
685 for (int i = 0; i < actual.length(); i++) { 697 for (int i = 0; i < actual.length(); i++) {
686 CHECK_NE('\0', expected[i]); 698 CHECK_NE('\0', expected[i]);
687 CHECK_EQ(expected[i], actual[i]); 699 CHECK_EQ(expected[i], actual[i]);
688 } 700 }
689 } 701 }
690 702
691 703
692 TEST(RegExpScanning) { 704 TEST(RegExpScanning) {
705 v8::V8::Initialize();
706
693 // RegExp token with added garbage at the end. The scanner should only 707 // RegExp token with added garbage at the end. The scanner should only
694 // scan the RegExp until the terminating slash just before "flipperwald". 708 // scan the RegExp until the terminating slash just before "flipperwald".
695 TestScanRegExp("/b/flipperwald", "b"); 709 TestScanRegExp("/b/flipperwald", "b");
696 // Incomplete escape sequences doesn't hide the terminating slash. 710 // Incomplete escape sequences doesn't hide the terminating slash.
697 TestScanRegExp("/\\x/flipperwald", "\\x"); 711 TestScanRegExp("/\\x/flipperwald", "\\x");
698 TestScanRegExp("/\\u/flipperwald", "\\u"); 712 TestScanRegExp("/\\u/flipperwald", "\\u");
699 TestScanRegExp("/\\u1/flipperwald", "\\u1"); 713 TestScanRegExp("/\\u1/flipperwald", "\\u1");
700 TestScanRegExp("/\\u12/flipperwald", "\\u12"); 714 TestScanRegExp("/\\u12/flipperwald", "\\u12");
701 TestScanRegExp("/\\u123/flipperwald", "\\u123"); 715 TestScanRegExp("/\\u123/flipperwald", "\\u123");
702 TestScanRegExp("/\\c/flipperwald", "\\c"); 716 TestScanRegExp("/\\c/flipperwald", "\\c");
(...skipping 12 matching lines...) Expand all
715 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); 729 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]");
716 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); 730 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]");
717 // Escaped ']'s wont end the character class. 731 // Escaped ']'s wont end the character class.
718 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); 732 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]");
719 // Escaped slashes are not terminating. 733 // Escaped slashes are not terminating.
720 TestScanRegExp("/\\//flipperwald", "\\/"); 734 TestScanRegExp("/\\//flipperwald", "\\/");
721 // Starting with '=' works too. 735 // Starting with '=' works too.
722 TestScanRegExp("/=/", "="); 736 TestScanRegExp("/=/", "=");
723 TestScanRegExp("/=?/", "=?"); 737 TestScanRegExp("/=?/", "=?");
724 } 738 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698