| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Regression test. See: | 137 // Regression test. See: |
| 138 // http://code.google.com/p/chromium/issues/detail?id=53548 | 138 // http://code.google.com/p/chromium/issues/detail?id=53548 |
| 139 // Tests that --> is correctly interpreted as comment-to-end-of-line if there | 139 // 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 | 140 // is only whitespace before it on the line (with comments considered as |
| 141 // comment. This was not the case if it occurred before the first real token | 141 // whitespace, even a multiline-comment containing a newline). |
| 142 // This was not the case if it occurred before the first real token |
| 142 // in the input. | 143 // in the input. |
| 143 const char* tests[] = { | 144 const char* tests[] = { |
| 144 // Before first real token. | 145 // Before first real token. |
| 145 "--> is eol-comment\nvar y = 37;\n", | 146 "--> is eol-comment\nvar y = 37;\n", |
| 146 "\n --> is eol-comment\nvar y = 37;\n", | 147 "\n --> is eol-comment\nvar y = 37;\n", |
| 147 "/* precomment */ --> is eol-comment\nvar y = 37;\n", | 148 "/* precomment */ --> is eol-comment\nvar y = 37;\n", |
| 148 "\n/* precomment */ --> is eol-comment\nvar y = 37;\n", | 149 "\n/* precomment */ --> is eol-comment\nvar y = 37;\n", |
| 149 // After first real token. | 150 // After first real token. |
| 150 "var x = 42;\n--> is eol-comment\nvar y = 37;\n", | 151 "var x = 42;\n--> is eol-comment\nvar y = 37;\n", |
| 151 "var x = 42;\n/* precomment */ --> is eol-comment\nvar y = 37;\n", | 152 "var x = 42;\n/* precomment */ --> is eol-comment\nvar y = 37;\n", |
| 152 NULL | 153 NULL |
| 153 }; | 154 }; |
| 154 | 155 |
| 156 const char* fail_tests[] = { |
| 157 "x --> is eol-comment\nvar y = 37;\n", |
| 158 "\"\\n\" --> is eol-comment\nvar y = 37;\n", |
| 159 "x/* precomment */ --> is eol-comment\nvar y = 37;\n", |
| 160 "x/* precomment\n */ --> is eol-comment\nvar y = 37;\n", |
| 161 "var x = 42; --> is eol-comment\nvar y = 37;\n", |
| 162 "var x = 42; /* precomment\n */ --> is eol-comment\nvar y = 37;\n", |
| 163 NULL |
| 164 }; |
| 165 |
| 155 // Parser/Scanner needs a stack limit. | 166 // Parser/Scanner needs a stack limit. |
| 156 int marker; | 167 int marker; |
| 157 i::Isolate::Current()->stack_guard()->SetStackLimit( | 168 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 158 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 169 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 159 | 170 |
| 160 for (int i = 0; tests[i]; i++) { | 171 for (int i = 0; tests[i]; i++) { |
| 161 v8::ScriptData* data = | 172 v8::ScriptData* data = |
| 162 v8::ScriptData::PreCompile(tests[i], i::StrLength(tests[i])); | 173 v8::ScriptData::PreCompile(tests[i], i::StrLength(tests[i])); |
| 163 CHECK(data != NULL && !data->HasError()); | 174 CHECK(data != NULL && !data->HasError()); |
| 164 delete data; | 175 delete data; |
| 165 } | 176 } |
| 177 |
| 178 for (int i = 0; fail_tests[i]; i++) { |
| 179 v8::ScriptData* data = |
| 180 v8::ScriptData::PreCompile(fail_tests[i], i::StrLength(fail_tests[i])); |
| 181 CHECK(data == NULL || data->HasError()); |
| 182 delete data; |
| 183 } |
| 166 } | 184 } |
| 167 | 185 |
| 168 | 186 |
| 169 class ScriptResource : public v8::String::ExternalAsciiStringResource { | 187 class ScriptResource : public v8::String::ExternalAsciiStringResource { |
| 170 public: | 188 public: |
| 171 ScriptResource(const char* data, size_t length) | 189 ScriptResource(const char* data, size_t length) |
| 172 : data_(data), length_(length) { } | 190 : data_(data), length_(length) { } |
| 173 | 191 |
| 174 const char* data() const { return data_; } | 192 const char* data() const { return data_; } |
| 175 size_t length() const { return length_; } | 193 size_t length() const { return length_; } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 264 |
| 247 TEST(StandAlonePreParser) { | 265 TEST(StandAlonePreParser) { |
| 248 int marker; | 266 int marker; |
| 249 i::Isolate::Current()->stack_guard()->SetStackLimit( | 267 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 250 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 268 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 251 | 269 |
| 252 const char* programs[] = { | 270 const char* programs[] = { |
| 253 "{label: 42}", | 271 "{label: 42}", |
| 254 "var x = 42;", | 272 "var x = 42;", |
| 255 "function foo(x, y) { return x + y; }", | 273 "function foo(x, y) { return x + y; }", |
| 256 "native function foo(); return %ArgleBargle(glop);", | 274 "%ArgleBargle(glop);", |
| 257 "var x = new new Function('this.x = 42');", | 275 "var x = new new Function('this.x = 42');", |
| 258 NULL | 276 NULL |
| 259 }; | 277 }; |
| 260 | 278 |
| 261 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 279 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 262 for (int i = 0; programs[i]; i++) { | 280 for (int i = 0; programs[i]; i++) { |
| 263 const char* program = programs[i]; | 281 const char* program = programs[i]; |
| 264 i::Utf8ToUC16CharacterStream stream( | 282 i::Utf8ToUC16CharacterStream stream( |
| 265 reinterpret_cast<const i::byte*>(program), | 283 reinterpret_cast<const i::byte*>(program), |
| 266 static_cast<unsigned>(strlen(program))); | 284 static_cast<unsigned>(strlen(program))); |
| 267 i::CompleteParserRecorder log; | 285 i::CompleteParserRecorder log; |
| 268 i::V8JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 286 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 269 scanner.Initialize(&stream); | 287 scanner.Initialize(&stream); |
| 270 | 288 |
| 271 v8::preparser::PreParser::PreParseResult result = | 289 v8::preparser::PreParser::PreParseResult result = |
| 272 v8::preparser::PreParser::PreParseProgram(&scanner, | 290 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 273 &log, | 291 &log, |
| 274 true, | 292 true, |
| 275 stack_limit); | 293 stack_limit); |
| 276 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 294 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 277 i::ScriptDataImpl data(log.ExtractData()); | 295 i::ScriptDataImpl data(log.ExtractData()); |
| 278 CHECK(!data.has_error()); | 296 CHECK(!data.has_error()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 reinterpret_cast<char*>(malloc(kProgramSize + 1))); | 369 reinterpret_cast<char*>(malloc(kProgramSize + 1))); |
| 352 memset(*program, '(', kProgramSize); | 370 memset(*program, '(', kProgramSize); |
| 353 program[kProgramSize] = '\0'; | 371 program[kProgramSize] = '\0'; |
| 354 | 372 |
| 355 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 373 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 356 | 374 |
| 357 i::Utf8ToUC16CharacterStream stream( | 375 i::Utf8ToUC16CharacterStream stream( |
| 358 reinterpret_cast<const i::byte*>(*program), | 376 reinterpret_cast<const i::byte*>(*program), |
| 359 static_cast<unsigned>(kProgramSize)); | 377 static_cast<unsigned>(kProgramSize)); |
| 360 i::CompleteParserRecorder log; | 378 i::CompleteParserRecorder log; |
| 361 i::V8JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 379 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 362 scanner.Initialize(&stream); | 380 scanner.Initialize(&stream); |
| 363 | 381 |
| 364 | 382 |
| 365 v8::preparser::PreParser::PreParseResult result = | 383 v8::preparser::PreParser::PreParseResult result = |
| 366 v8::preparser::PreParser::PreParseProgram(&scanner, | 384 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 367 &log, | 385 &log, |
| 368 true, | 386 true, |
| 369 stack_limit); | 387 stack_limit); |
| 370 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); | 388 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); |
| 371 } | 389 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 CHECK_EQU(i, stream.pos()); | 587 CHECK_EQU(i, stream.pos()); |
| 570 } | 588 } |
| 571 } | 589 } |
| 572 | 590 |
| 573 #undef CHECK_EQU | 591 #undef CHECK_EQU |
| 574 | 592 |
| 575 void TestStreamScanner(i::UC16CharacterStream* stream, | 593 void TestStreamScanner(i::UC16CharacterStream* stream, |
| 576 i::Token::Value* expected_tokens, | 594 i::Token::Value* expected_tokens, |
| 577 int skip_pos = 0, // Zero means not skipping. | 595 int skip_pos = 0, // Zero means not skipping. |
| 578 int skip_to = 0) { | 596 int skip_to = 0) { |
| 579 i::V8JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 597 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 580 scanner.Initialize(stream); | 598 scanner.Initialize(stream); |
| 581 | 599 |
| 582 int i = 0; | 600 int i = 0; |
| 583 do { | 601 do { |
| 584 i::Token::Value expected = expected_tokens[i]; | 602 i::Token::Value expected = expected_tokens[i]; |
| 585 i::Token::Value actual = scanner.Next(); | 603 i::Token::Value actual = scanner.Next(); |
| 586 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); | 604 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); |
| 587 if (scanner.location().end_pos == skip_pos) { | 605 if (scanner.location().end_pos == skip_pos) { |
| 588 scanner.SeekForward(skip_to); | 606 scanner.SeekForward(skip_to); |
| 589 } | 607 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 static_cast<unsigned>(strlen(str3))); | 666 static_cast<unsigned>(strlen(str3))); |
| 649 TestStreamScanner(&stream3, expectations3, 1, 1 + i); | 667 TestStreamScanner(&stream3, expectations3, 1, 1 + i); |
| 650 } | 668 } |
| 651 } | 669 } |
| 652 | 670 |
| 653 | 671 |
| 654 void TestScanRegExp(const char* re_source, const char* expected) { | 672 void TestScanRegExp(const char* re_source, const char* expected) { |
| 655 i::Utf8ToUC16CharacterStream stream( | 673 i::Utf8ToUC16CharacterStream stream( |
| 656 reinterpret_cast<const i::byte*>(re_source), | 674 reinterpret_cast<const i::byte*>(re_source), |
| 657 static_cast<unsigned>(strlen(re_source))); | 675 static_cast<unsigned>(strlen(re_source))); |
| 658 i::V8JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 676 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 659 scanner.Initialize(&stream); | 677 scanner.Initialize(&stream); |
| 660 | 678 |
| 661 i::Token::Value start = scanner.peek(); | 679 i::Token::Value start = scanner.peek(); |
| 662 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); | 680 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); |
| 663 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); | 681 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); |
| 664 scanner.Next(); // Current token is now the regexp literal. | 682 scanner.Next(); // Current token is now the regexp literal. |
| 665 CHECK(scanner.is_literal_ascii()); | 683 CHECK(scanner.is_literal_ascii()); |
| 666 i::Vector<const char> actual = scanner.literal_ascii_string(); | 684 i::Vector<const char> actual = scanner.literal_ascii_string(); |
| 667 for (int i = 0; i < actual.length(); i++) { | 685 for (int i = 0; i < actual.length(); i++) { |
| 668 CHECK_NE('\0', expected[i]); | 686 CHECK_NE('\0', expected[i]); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 697 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); | 715 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); |
| 698 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); | 716 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); |
| 699 // Escaped ']'s wont end the character class. | 717 // Escaped ']'s wont end the character class. |
| 700 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); | 718 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); |
| 701 // Escaped slashes are not terminating. | 719 // Escaped slashes are not terminating. |
| 702 TestScanRegExp("/\\//flipperwald", "\\/"); | 720 TestScanRegExp("/\\//flipperwald", "\\/"); |
| 703 // Starting with '=' works too. | 721 // Starting with '=' works too. |
| 704 TestScanRegExp("/=/", "="); | 722 TestScanRegExp("/=/", "="); |
| 705 TestScanRegExp("/=?/", "=?"); | 723 TestScanRegExp("/=?/", "=?"); |
| 706 } | 724 } |
| OLD | NEW |