| OLD | NEW |
| 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 Loading... |
| 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, even after a multiline-comment | 142 // is only whitespace before it on the line, even after a multiline-comment |
| 141 // comment. This was not the case if it occurred before the first real token | 143 // comment. This was not the case if it occurred before the first real token |
| 142 // in the input. | 144 // in the input. |
| 143 const char* tests[] = { | 145 const char* tests[] = { |
| 144 // Before first real token. | 146 // Before first real token. |
| 145 "--> is eol-comment\nvar y = 37;\n", | 147 "--> is eol-comment\nvar y = 37;\n", |
| 146 "\n --> is eol-comment\nvar y = 37;\n", | 148 "\n --> is eol-comment\nvar y = 37;\n", |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 CHECK_EQ(10, error_location.beg_pos); | 240 CHECK_EQ(10, error_location.beg_pos); |
| 239 CHECK_EQ(11, error_location.end_pos); | 241 CHECK_EQ(11, error_location.end_pos); |
| 240 // Should not crash. | 242 // Should not crash. |
| 241 const char* message = pre_impl->BuildMessage(); | 243 const char* message = pre_impl->BuildMessage(); |
| 242 i::Vector<const char*> args = pre_impl->BuildArgs(); | 244 i::Vector<const char*> args = pre_impl->BuildArgs(); |
| 243 CHECK_GT(strlen(message), 0); | 245 CHECK_GT(strlen(message), 0); |
| 244 } | 246 } |
| 245 | 247 |
| 246 | 248 |
| 247 TEST(StandAlonePreParser) { | 249 TEST(StandAlonePreParser) { |
| 250 v8::V8::Initialize(); |
| 251 |
| 248 int marker; | 252 int marker; |
| 249 i::Isolate::Current()->stack_guard()->SetStackLimit( | 253 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 250 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 254 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 251 | 255 |
| 252 const char* programs[] = { | 256 const char* programs[] = { |
| 253 "{label: 42}", | 257 "{label: 42}", |
| 254 "var x = 42;", | 258 "var x = 42;", |
| 255 "function foo(x, y) { return x + y; }", | 259 "function foo(x, y) { return x + y; }", |
| 256 "native function foo(); return %ArgleBargle(glop);", | 260 "native function foo(); return %ArgleBargle(glop);", |
| 257 "var x = new new Function('this.x = 42');", | 261 "var x = new new Function('this.x = 42');", |
| (...skipping 16 matching lines...) Expand all Loading... |
| 274 true, | 278 true, |
| 275 stack_limit); | 279 stack_limit); |
| 276 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 280 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 277 i::ScriptDataImpl data(log.ExtractData()); | 281 i::ScriptDataImpl data(log.ExtractData()); |
| 278 CHECK(!data.has_error()); | 282 CHECK(!data.has_error()); |
| 279 } | 283 } |
| 280 } | 284 } |
| 281 | 285 |
| 282 | 286 |
| 283 TEST(RegressChromium62639) { | 287 TEST(RegressChromium62639) { |
| 288 v8::V8::Initialize(); |
| 289 |
| 284 int marker; | 290 int marker; |
| 285 i::Isolate::Current()->stack_guard()->SetStackLimit( | 291 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 286 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 292 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 287 | 293 |
| 288 const char* program = "var x = 'something';\n" | 294 const char* program = "var x = 'something';\n" |
| 289 "escape: function() {}"; | 295 "escape: function() {}"; |
| 290 // Fails parsing expecting an identifier after "function". | 296 // Fails parsing expecting an identifier after "function". |
| 291 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), | 297 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), |
| 292 // and then used the invalid currently scanned literal. This always | 298 // and then used the invalid currently scanned literal. This always |
| 293 // failed in debug mode, and sometimes crashed in release mode. | 299 // failed in debug mode, and sometimes crashed in release mode. |
| 294 | 300 |
| 295 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), | 301 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), |
| 296 static_cast<unsigned>(strlen(program))); | 302 static_cast<unsigned>(strlen(program))); |
| 297 i::ScriptDataImpl* data = | 303 i::ScriptDataImpl* data = |
| 298 i::ParserApi::PreParse(&stream, NULL); | 304 i::ParserApi::PreParse(&stream, NULL); |
| 299 CHECK(data->HasError()); | 305 CHECK(data->HasError()); |
| 300 delete data; | 306 delete data; |
| 301 } | 307 } |
| 302 | 308 |
| 303 | 309 |
| 304 TEST(Regress928) { | 310 TEST(Regress928) { |
| 311 v8::V8::Initialize(); |
| 312 |
| 305 // Preparsing didn't consider the catch clause of a try statement | 313 // Preparsing didn't consider the catch clause of a try statement |
| 306 // as with-content, which made it assume that a function inside | 314 // as with-content, which made it assume that a function inside |
| 307 // the block could be lazily compiled, and an extra, unexpected, | 315 // the block could be lazily compiled, and an extra, unexpected, |
| 308 // entry was added to the data. | 316 // entry was added to the data. |
| 309 int marker; | 317 int marker; |
| 310 i::Isolate::Current()->stack_guard()->SetStackLimit( | 318 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 311 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 319 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 312 | 320 |
| 313 const char* program = | 321 const char* program = |
| 314 "try { } catch (e) { var foo = function () { /* first */ } }" | 322 "try { } catch (e) { var foo = function () { /* first */ } }" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 335 second_function + static_cast<int>(strlen("function () ")); | 343 second_function + static_cast<int>(strlen("function () ")); |
| 336 CHECK_EQ('{', program[second_lbrace]); | 344 CHECK_EQ('{', program[second_lbrace]); |
| 337 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace); | 345 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace); |
| 338 CHECK(entry2.is_valid()); | 346 CHECK(entry2.is_valid()); |
| 339 CHECK_EQ('}', program[entry2.end_pos() - 1]); | 347 CHECK_EQ('}', program[entry2.end_pos() - 1]); |
| 340 delete data; | 348 delete data; |
| 341 } | 349 } |
| 342 | 350 |
| 343 | 351 |
| 344 TEST(PreParseOverflow) { | 352 TEST(PreParseOverflow) { |
| 353 v8::V8::Initialize(); |
| 354 |
| 345 int marker; | 355 int marker; |
| 346 i::Isolate::Current()->stack_guard()->SetStackLimit( | 356 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 347 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 357 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 348 | 358 |
| 349 size_t kProgramSize = 1024 * 1024; | 359 size_t kProgramSize = 1024 * 1024; |
| 350 i::SmartPointer<char> program( | 360 i::SmartPointer<char> program( |
| 351 reinterpret_cast<char*>(malloc(kProgramSize + 1))); | 361 reinterpret_cast<char*>(malloc(kProgramSize + 1))); |
| 352 memset(*program, '(', kProgramSize); | 362 memset(*program, '(', kProgramSize); |
| 353 program[kProgramSize] = '\0'; | 363 program[kProgramSize] = '\0'; |
| 354 | 364 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 i::Token::Value actual = scanner.Next(); | 595 i::Token::Value actual = scanner.Next(); |
| 586 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); | 596 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); |
| 587 if (scanner.location().end_pos == skip_pos) { | 597 if (scanner.location().end_pos == skip_pos) { |
| 588 scanner.SeekForward(skip_to); | 598 scanner.SeekForward(skip_to); |
| 589 } | 599 } |
| 590 i++; | 600 i++; |
| 591 } while (expected_tokens[i] != i::Token::ILLEGAL); | 601 } while (expected_tokens[i] != i::Token::ILLEGAL); |
| 592 } | 602 } |
| 593 | 603 |
| 594 TEST(StreamScanner) { | 604 TEST(StreamScanner) { |
| 605 v8::V8::Initialize(); |
| 606 |
| 595 const char* str1 = "{ foo get for : */ <- \n\n /*foo*/ bib"; | 607 const char* str1 = "{ foo get for : */ <- \n\n /*foo*/ bib"; |
| 596 i::Utf8ToUC16CharacterStream stream1(reinterpret_cast<const i::byte*>(str1), | 608 i::Utf8ToUC16CharacterStream stream1(reinterpret_cast<const i::byte*>(str1), |
| 597 static_cast<unsigned>(strlen(str1))); | 609 static_cast<unsigned>(strlen(str1))); |
| 598 i::Token::Value expectations1[] = { | 610 i::Token::Value expectations1[] = { |
| 599 i::Token::LBRACE, | 611 i::Token::LBRACE, |
| 600 i::Token::IDENTIFIER, | 612 i::Token::IDENTIFIER, |
| 601 i::Token::IDENTIFIER, | 613 i::Token::IDENTIFIER, |
| 602 i::Token::FOR, | 614 i::Token::FOR, |
| 603 i::Token::COLON, | 615 i::Token::COLON, |
| 604 i::Token::MUL, | 616 i::Token::MUL, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 CHECK(scanner.is_literal_ascii()); | 677 CHECK(scanner.is_literal_ascii()); |
| 666 i::Vector<const char> actual = scanner.literal_ascii_string(); | 678 i::Vector<const char> actual = scanner.literal_ascii_string(); |
| 667 for (int i = 0; i < actual.length(); i++) { | 679 for (int i = 0; i < actual.length(); i++) { |
| 668 CHECK_NE('\0', expected[i]); | 680 CHECK_NE('\0', expected[i]); |
| 669 CHECK_EQ(expected[i], actual[i]); | 681 CHECK_EQ(expected[i], actual[i]); |
| 670 } | 682 } |
| 671 } | 683 } |
| 672 | 684 |
| 673 | 685 |
| 674 TEST(RegExpScanning) { | 686 TEST(RegExpScanning) { |
| 687 v8::V8::Initialize(); |
| 688 |
| 675 // RegExp token with added garbage at the end. The scanner should only | 689 // RegExp token with added garbage at the end. The scanner should only |
| 676 // scan the RegExp until the terminating slash just before "flipperwald". | 690 // scan the RegExp until the terminating slash just before "flipperwald". |
| 677 TestScanRegExp("/b/flipperwald", "b"); | 691 TestScanRegExp("/b/flipperwald", "b"); |
| 678 // Incomplete escape sequences doesn't hide the terminating slash. | 692 // Incomplete escape sequences doesn't hide the terminating slash. |
| 679 TestScanRegExp("/\\x/flipperwald", "\\x"); | 693 TestScanRegExp("/\\x/flipperwald", "\\x"); |
| 680 TestScanRegExp("/\\u/flipperwald", "\\u"); | 694 TestScanRegExp("/\\u/flipperwald", "\\u"); |
| 681 TestScanRegExp("/\\u1/flipperwald", "\\u1"); | 695 TestScanRegExp("/\\u1/flipperwald", "\\u1"); |
| 682 TestScanRegExp("/\\u12/flipperwald", "\\u12"); | 696 TestScanRegExp("/\\u12/flipperwald", "\\u12"); |
| 683 TestScanRegExp("/\\u123/flipperwald", "\\u123"); | 697 TestScanRegExp("/\\u123/flipperwald", "\\u123"); |
| 684 TestScanRegExp("/\\c/flipperwald", "\\c"); | 698 TestScanRegExp("/\\c/flipperwald", "\\c"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 697 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); | 711 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); |
| 698 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); | 712 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); |
| 699 // Escaped ']'s wont end the character class. | 713 // Escaped ']'s wont end the character class. |
| 700 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); | 714 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); |
| 701 // Escaped slashes are not terminating. | 715 // Escaped slashes are not terminating. |
| 702 TestScanRegExp("/\\//flipperwald", "\\/"); | 716 TestScanRegExp("/\\//flipperwald", "\\/"); |
| 703 // Starting with '=' works too. | 717 // Starting with '=' works too. |
| 704 TestScanRegExp("/=/", "="); | 718 TestScanRegExp("/=/", "="); |
| 705 TestScanRegExp("/=?/", "=?"); | 719 TestScanRegExp("/=?/", "=?"); |
| 706 } | 720 } |
| OLD | NEW |