| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 KeywordToken key_token; | 56 KeywordToken key_token; |
| 57 i::UnicodeCache unicode_cache; | 57 i::UnicodeCache unicode_cache; |
| 58 i::byte buffer[32]; | 58 i::byte buffer[32]; |
| 59 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { | 59 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { |
| 60 const i::byte* keyword = | 60 const i::byte* keyword = |
| 61 reinterpret_cast<const i::byte*>(key_token.keyword); | 61 reinterpret_cast<const i::byte*>(key_token.keyword); |
| 62 int length = i::StrLength(key_token.keyword); | 62 int length = i::StrLength(key_token.keyword); |
| 63 CHECK(static_cast<int>(sizeof(buffer)) >= length); | 63 CHECK(static_cast<int>(sizeof(buffer)) >= length); |
| 64 { | 64 { |
| 65 i::Utf8ToUC16CharacterStream stream(keyword, length); | 65 i::Utf8ToUC16CharacterStream stream(keyword, length); |
| 66 i::JavaScriptScanner scanner(&unicode_cache); | 66 i::Scanner scanner(&unicode_cache); |
| 67 // The scanner should parse 'let' as Token::LET for this test. | 67 // The scanner should parse 'let' as Token::LET for this test. |
| 68 scanner.SetHarmonyScoping(true); | 68 scanner.SetHarmonyScoping(true); |
| 69 scanner.Initialize(&stream); | 69 scanner.Initialize(&stream); |
| 70 CHECK_EQ(key_token.token, scanner.Next()); | 70 CHECK_EQ(key_token.token, scanner.Next()); |
| 71 CHECK_EQ(i::Token::EOS, scanner.Next()); | 71 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 72 } | 72 } |
| 73 // Removing characters will make keyword matching fail. | 73 // Removing characters will make keyword matching fail. |
| 74 { | 74 { |
| 75 i::Utf8ToUC16CharacterStream stream(keyword, length - 1); | 75 i::Utf8ToUC16CharacterStream stream(keyword, length - 1); |
| 76 i::JavaScriptScanner scanner(&unicode_cache); | 76 i::Scanner scanner(&unicode_cache); |
| 77 scanner.Initialize(&stream); | 77 scanner.Initialize(&stream); |
| 78 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 78 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
| 79 CHECK_EQ(i::Token::EOS, scanner.Next()); | 79 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 80 } | 80 } |
| 81 // Adding characters will make keyword matching fail. | 81 // Adding characters will make keyword matching fail. |
| 82 static const char chars_to_append[] = { 'z', '0', '_' }; | 82 static const char chars_to_append[] = { 'z', '0', '_' }; |
| 83 for (int j = 0; j < static_cast<int>(ARRAY_SIZE(chars_to_append)); ++j) { | 83 for (int j = 0; j < static_cast<int>(ARRAY_SIZE(chars_to_append)); ++j) { |
| 84 memmove(buffer, keyword, length); | 84 memmove(buffer, keyword, length); |
| 85 buffer[length] = chars_to_append[j]; | 85 buffer[length] = chars_to_append[j]; |
| 86 i::Utf8ToUC16CharacterStream stream(buffer, length + 1); | 86 i::Utf8ToUC16CharacterStream stream(buffer, length + 1); |
| 87 i::JavaScriptScanner scanner(&unicode_cache); | 87 i::Scanner scanner(&unicode_cache); |
| 88 scanner.Initialize(&stream); | 88 scanner.Initialize(&stream); |
| 89 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 89 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
| 90 CHECK_EQ(i::Token::EOS, scanner.Next()); | 90 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 91 } | 91 } |
| 92 // Replacing characters will make keyword matching fail. | 92 // Replacing characters will make keyword matching fail. |
| 93 { | 93 { |
| 94 memmove(buffer, keyword, length); | 94 memmove(buffer, keyword, length); |
| 95 buffer[length - 1] = '_'; | 95 buffer[length - 1] = '_'; |
| 96 i::Utf8ToUC16CharacterStream stream(buffer, length); | 96 i::Utf8ToUC16CharacterStream stream(buffer, length); |
| 97 i::JavaScriptScanner scanner(&unicode_cache); | 97 i::Scanner scanner(&unicode_cache); |
| 98 scanner.Initialize(&stream); | 98 scanner.Initialize(&stream); |
| 99 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 99 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
| 100 CHECK_EQ(i::Token::EOS, scanner.Next()); | 100 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 | 105 |
| 106 TEST(ScanHTMLEndComments) { | 106 TEST(ScanHTMLEndComments) { |
| 107 v8::V8::Initialize(); | 107 v8::V8::Initialize(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 NULL | 250 NULL |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 253 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 254 for (int i = 0; programs[i]; i++) { | 254 for (int i = 0; programs[i]; i++) { |
| 255 const char* program = programs[i]; | 255 const char* program = programs[i]; |
| 256 i::Utf8ToUC16CharacterStream stream( | 256 i::Utf8ToUC16CharacterStream stream( |
| 257 reinterpret_cast<const i::byte*>(program), | 257 reinterpret_cast<const i::byte*>(program), |
| 258 static_cast<unsigned>(strlen(program))); | 258 static_cast<unsigned>(strlen(program))); |
| 259 i::CompleteParserRecorder log; | 259 i::CompleteParserRecorder log; |
| 260 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 260 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 261 scanner.Initialize(&stream); | 261 scanner.Initialize(&stream); |
| 262 | 262 |
| 263 int flags = i::kAllowLazy | i::kAllowNativesSyntax; | 263 int flags = i::kAllowLazy | i::kAllowNativesSyntax; |
| 264 v8::preparser::PreParser::PreParseResult result = | 264 v8::preparser::PreParser::PreParseResult result = |
| 265 v8::preparser::PreParser::PreParseProgram(&scanner, | 265 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 266 &log, | 266 &log, |
| 267 flags, | 267 flags, |
| 268 stack_limit); | 268 stack_limit); |
| 269 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 269 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 270 i::ScriptDataImpl data(log.ExtractData()); | 270 i::ScriptDataImpl data(log.ExtractData()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 286 NULL | 286 NULL |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 289 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 290 for (int i = 0; programs[i]; i++) { | 290 for (int i = 0; programs[i]; i++) { |
| 291 const char* program = programs[i]; | 291 const char* program = programs[i]; |
| 292 i::Utf8ToUC16CharacterStream stream( | 292 i::Utf8ToUC16CharacterStream stream( |
| 293 reinterpret_cast<const i::byte*>(program), | 293 reinterpret_cast<const i::byte*>(program), |
| 294 static_cast<unsigned>(strlen(program))); | 294 static_cast<unsigned>(strlen(program))); |
| 295 i::CompleteParserRecorder log; | 295 i::CompleteParserRecorder log; |
| 296 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 296 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 297 scanner.Initialize(&stream); | 297 scanner.Initialize(&stream); |
| 298 | 298 |
| 299 // Flags don't allow natives syntax. | 299 // Flags don't allow natives syntax. |
| 300 v8::preparser::PreParser::PreParseResult result = | 300 v8::preparser::PreParser::PreParseResult result = |
| 301 v8::preparser::PreParser::PreParseProgram(&scanner, | 301 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 302 &log, | 302 &log, |
| 303 i::kAllowLazy, | 303 i::kAllowLazy, |
| 304 stack_limit); | 304 stack_limit); |
| 305 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 305 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 306 i::ScriptDataImpl data(log.ExtractData()); | 306 i::ScriptDataImpl data(log.ExtractData()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 reinterpret_cast<char*>(malloc(kProgramSize + 1))); | 387 reinterpret_cast<char*>(malloc(kProgramSize + 1))); |
| 388 memset(*program, '(', kProgramSize); | 388 memset(*program, '(', kProgramSize); |
| 389 program[kProgramSize] = '\0'; | 389 program[kProgramSize] = '\0'; |
| 390 | 390 |
| 391 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 391 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 392 | 392 |
| 393 i::Utf8ToUC16CharacterStream stream( | 393 i::Utf8ToUC16CharacterStream stream( |
| 394 reinterpret_cast<const i::byte*>(*program), | 394 reinterpret_cast<const i::byte*>(*program), |
| 395 static_cast<unsigned>(kProgramSize)); | 395 static_cast<unsigned>(kProgramSize)); |
| 396 i::CompleteParserRecorder log; | 396 i::CompleteParserRecorder log; |
| 397 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 397 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 398 scanner.Initialize(&stream); | 398 scanner.Initialize(&stream); |
| 399 | 399 |
| 400 | 400 |
| 401 v8::preparser::PreParser::PreParseResult result = | 401 v8::preparser::PreParser::PreParseResult result = |
| 402 v8::preparser::PreParser::PreParseProgram(&scanner, | 402 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 403 &log, | 403 &log, |
| 404 true, | 404 true, |
| 405 stack_limit); | 405 stack_limit); |
| 406 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); | 406 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); |
| 407 } | 407 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 CHECK_EQU(i, stream.pos()); | 605 CHECK_EQU(i, stream.pos()); |
| 606 } | 606 } |
| 607 } | 607 } |
| 608 | 608 |
| 609 #undef CHECK_EQU | 609 #undef CHECK_EQU |
| 610 | 610 |
| 611 void TestStreamScanner(i::UC16CharacterStream* stream, | 611 void TestStreamScanner(i::UC16CharacterStream* stream, |
| 612 i::Token::Value* expected_tokens, | 612 i::Token::Value* expected_tokens, |
| 613 int skip_pos = 0, // Zero means not skipping. | 613 int skip_pos = 0, // Zero means not skipping. |
| 614 int skip_to = 0) { | 614 int skip_to = 0) { |
| 615 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 615 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 616 scanner.Initialize(stream); | 616 scanner.Initialize(stream); |
| 617 | 617 |
| 618 int i = 0; | 618 int i = 0; |
| 619 do { | 619 do { |
| 620 i::Token::Value expected = expected_tokens[i]; | 620 i::Token::Value expected = expected_tokens[i]; |
| 621 i::Token::Value actual = scanner.Next(); | 621 i::Token::Value actual = scanner.Next(); |
| 622 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); | 622 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); |
| 623 if (scanner.location().end_pos == skip_pos) { | 623 if (scanner.location().end_pos == skip_pos) { |
| 624 scanner.SeekForward(skip_to); | 624 scanner.SeekForward(skip_to); |
| 625 } | 625 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 static_cast<unsigned>(strlen(str3))); | 686 static_cast<unsigned>(strlen(str3))); |
| 687 TestStreamScanner(&stream3, expectations3, 1, 1 + i); | 687 TestStreamScanner(&stream3, expectations3, 1, 1 + i); |
| 688 } | 688 } |
| 689 } | 689 } |
| 690 | 690 |
| 691 | 691 |
| 692 void TestScanRegExp(const char* re_source, const char* expected) { | 692 void TestScanRegExp(const char* re_source, const char* expected) { |
| 693 i::Utf8ToUC16CharacterStream stream( | 693 i::Utf8ToUC16CharacterStream stream( |
| 694 reinterpret_cast<const i::byte*>(re_source), | 694 reinterpret_cast<const i::byte*>(re_source), |
| 695 static_cast<unsigned>(strlen(re_source))); | 695 static_cast<unsigned>(strlen(re_source))); |
| 696 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 696 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
| 697 scanner.Initialize(&stream); | 697 scanner.Initialize(&stream); |
| 698 | 698 |
| 699 i::Token::Value start = scanner.peek(); | 699 i::Token::Value start = scanner.peek(); |
| 700 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); | 700 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); |
| 701 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); | 701 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); |
| 702 scanner.Next(); // Current token is now the regexp literal. | 702 scanner.Next(); // Current token is now the regexp literal. |
| 703 CHECK(scanner.is_literal_ascii()); | 703 CHECK(scanner.is_literal_ascii()); |
| 704 i::Vector<const char> actual = scanner.literal_ascii_string(); | 704 i::Vector<const char> actual = scanner.literal_ascii_string(); |
| 705 for (int i = 0; i < actual.length(); i++) { | 705 for (int i = 0; i < actual.length(); i++) { |
| 706 CHECK_NE('\0', expected[i]); | 706 CHECK_NE('\0', expected[i]); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 CHECK_EQ(scope->inner_scopes()->length(), 1); | 869 CHECK_EQ(scope->inner_scopes()->length(), 1); |
| 870 | 870 |
| 871 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 871 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| 872 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); | 872 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); |
| 873 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 873 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
| 874 // The end position of a token is one position after the last | 874 // The end position of a token is one position after the last |
| 875 // character belonging to that token. | 875 // character belonging to that token. |
| 876 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 876 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
| 877 } | 877 } |
| 878 } | 878 } |
| OLD | NEW |