| OLD | NEW |
| 1 // Copyright 2006-2009 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 251 |
| 252 const char* programs[] = { | 252 const char* programs[] = { |
| 253 "{label: 42}", | 253 "{label: 42}", |
| 254 "var x = 42;", | 254 "var x = 42;", |
| 255 "function foo(x, y) { return x + y; }", | 255 "function foo(x, y) { return x + y; }", |
| 256 "native function foo(); return %ArgleBargle(glop);", | 256 "native function foo(); return %ArgleBargle(glop);", |
| 257 "var x = new new Function('this.x = 42');", | 257 "var x = new new Function('this.x = 42');", |
| 258 NULL | 258 NULL |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 uintptr_t stack_limit = ISOLATE->stack_guard()->real_climit(); | 261 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 262 for (int i = 0; programs[i]; i++) { | 262 for (int i = 0; programs[i]; i++) { |
| 263 const char* program = programs[i]; | 263 const char* program = programs[i]; |
| 264 i::Utf8ToUC16CharacterStream stream( | 264 i::Utf8ToUC16CharacterStream stream( |
| 265 reinterpret_cast<const i::byte*>(program), | 265 reinterpret_cast<const i::byte*>(program), |
| 266 static_cast<unsigned>(strlen(program))); | 266 static_cast<unsigned>(strlen(program))); |
| 267 i::CompleteParserRecorder log; | 267 i::CompleteParserRecorder log; |
| 268 i::V8JavaScriptScanner scanner(ISOLATE->scanner_constants()); | 268 i::V8JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 269 scanner.Initialize(&stream); | 269 scanner.Initialize(&stream); |
| 270 | 270 |
| 271 v8::preparser::PreParser::PreParseResult result = | 271 v8::preparser::PreParser::PreParseResult result = |
| 272 v8::preparser::PreParser::PreParseProgram(&scanner, | 272 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 273 &log, | 273 &log, |
| 274 true, | 274 true, |
| 275 stack_limit); | 275 stack_limit); |
| 276 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 276 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 277 i::ScriptDataImpl data(log.ExtractData()); | 277 i::ScriptDataImpl data(log.ExtractData()); |
| 278 CHECK(!data.has_error()); | 278 CHECK(!data.has_error()); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 | 282 |
| 283 TEST(RegressChromium62639) { | 283 TEST(RegressChromium62639) { |
| 284 int marker; | 284 int marker; |
| 285 ISOLATE->stack_guard()->SetStackLimit( | 285 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 286 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 286 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 287 | 287 |
| 288 const char* program = "var x = 'something';\n" | 288 const char* program = "var x = 'something';\n" |
| 289 "escape: function() {}"; | 289 "escape: function() {}"; |
| 290 // Fails parsing expecting an identifier after "function". | 290 // Fails parsing expecting an identifier after "function". |
| 291 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), | 291 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), |
| 292 // and then used the invalid currently scanned literal. This always | 292 // and then used the invalid currently scanned literal. This always |
| 293 // failed in debug mode, and sometimes crashed in release mode. | 293 // failed in debug mode, and sometimes crashed in release mode. |
| 294 | 294 |
| 295 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), | 295 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), |
| 296 static_cast<unsigned>(strlen(program))); | 296 static_cast<unsigned>(strlen(program))); |
| 297 i::ScriptDataImpl* data = | 297 i::ScriptDataImpl* data = |
| 298 i::ParserApi::PreParse(&stream, NULL); | 298 i::ParserApi::PreParse(&stream, NULL); |
| 299 CHECK(data->HasError()); | 299 CHECK(data->HasError()); |
| 300 delete data; | 300 delete data; |
| 301 } | 301 } |
| 302 | 302 |
| 303 | 303 |
| 304 TEST(Regress928) { | 304 TEST(Regress928) { |
| 305 // Preparsing didn't consider the catch clause of a try statement | 305 // Preparsing didn't consider the catch clause of a try statement |
| 306 // as with-content, which made it assume that a function inside | 306 // as with-content, which made it assume that a function inside |
| 307 // the block could be lazily compiled, and an extra, unexpected, | 307 // the block could be lazily compiled, and an extra, unexpected, |
| 308 // entry was added to the data. | 308 // entry was added to the data. |
| 309 int marker; | 309 int marker; |
| 310 ISOLATE->stack_guard()->SetStackLimit( | 310 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 311 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 311 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 312 | 312 |
| 313 const char* program = | 313 const char* program = |
| 314 "try { } catch (e) { var foo = function () { /* first */ } }" | 314 "try { } catch (e) { var foo = function () { /* first */ } }" |
| 315 "var bar = function () { /* second */ }"; | 315 "var bar = function () { /* second */ }"; |
| 316 | 316 |
| 317 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), | 317 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), |
| 318 static_cast<unsigned>(strlen(program))); | 318 static_cast<unsigned>(strlen(program))); |
| 319 i::ScriptDataImpl* data = | 319 i::ScriptDataImpl* data = |
| 320 i::ParserApi::PartialPreParse(&stream, NULL); | 320 i::ParserApi::PartialPreParse(&stream, NULL); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 336 CHECK_EQ('{', program[second_lbrace]); | 336 CHECK_EQ('{', program[second_lbrace]); |
| 337 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace); | 337 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace); |
| 338 CHECK(entry2.is_valid()); | 338 CHECK(entry2.is_valid()); |
| 339 CHECK_EQ('}', program[entry2.end_pos() - 1]); | 339 CHECK_EQ('}', program[entry2.end_pos() - 1]); |
| 340 delete data; | 340 delete data; |
| 341 } | 341 } |
| 342 | 342 |
| 343 | 343 |
| 344 TEST(PreParseOverflow) { | 344 TEST(PreParseOverflow) { |
| 345 int marker; | 345 int marker; |
| 346 ISOLATE->stack_guard()->SetStackLimit( | 346 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 347 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 347 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 348 | 348 |
| 349 size_t kProgramSize = 1024 * 1024; | 349 size_t kProgramSize = 1024 * 1024; |
| 350 i::SmartPointer<char> program( | 350 i::SmartPointer<char> program( |
| 351 reinterpret_cast<char*>(malloc(kProgramSize + 1))); | 351 reinterpret_cast<char*>(malloc(kProgramSize + 1))); |
| 352 memset(*program, '(', kProgramSize); | 352 memset(*program, '(', kProgramSize); |
| 353 program[kProgramSize] = '\0'; | 353 program[kProgramSize] = '\0'; |
| 354 | 354 |
| 355 uintptr_t stack_limit = ISOLATE->stack_guard()->real_climit(); | 355 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 356 | 356 |
| 357 i::Utf8ToUC16CharacterStream stream( | 357 i::Utf8ToUC16CharacterStream stream( |
| 358 reinterpret_cast<const i::byte*>(*program), | 358 reinterpret_cast<const i::byte*>(*program), |
| 359 static_cast<unsigned>(kProgramSize)); | 359 static_cast<unsigned>(kProgramSize)); |
| 360 i::CompleteParserRecorder log; | 360 i::CompleteParserRecorder log; |
| 361 i::V8JavaScriptScanner scanner(ISOLATE->scanner_constants()); | 361 i::V8JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 362 scanner.Initialize(&stream); | 362 scanner.Initialize(&stream); |
| 363 | 363 |
| 364 | 364 |
| 365 v8::preparser::PreParser::PreParseResult result = | 365 v8::preparser::PreParser::PreParseResult result = |
| 366 v8::preparser::PreParser::PreParseProgram(&scanner, | 366 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 367 &log, | 367 &log, |
| 368 true, | 368 true, |
| 369 stack_limit); | 369 stack_limit); |
| 370 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); | 370 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); |
| 371 } | 371 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 CHECK_EQU(i, stream.pos()); | 569 CHECK_EQU(i, stream.pos()); |
| 570 } | 570 } |
| 571 } | 571 } |
| 572 | 572 |
| 573 #undef CHECK_EQU | 573 #undef CHECK_EQU |
| 574 | 574 |
| 575 void TestStreamScanner(i::UC16CharacterStream* stream, | 575 void TestStreamScanner(i::UC16CharacterStream* stream, |
| 576 i::Token::Value* expected_tokens, | 576 i::Token::Value* expected_tokens, |
| 577 int skip_pos = 0, // Zero means not skipping. | 577 int skip_pos = 0, // Zero means not skipping. |
| 578 int skip_to = 0) { | 578 int skip_to = 0) { |
| 579 i::V8JavaScriptScanner scanner(ISOLATE->scanner_constants()); | 579 i::V8JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 580 scanner.Initialize(stream); | 580 scanner.Initialize(stream); |
| 581 | 581 |
| 582 int i = 0; | 582 int i = 0; |
| 583 do { | 583 do { |
| 584 i::Token::Value expected = expected_tokens[i]; | 584 i::Token::Value expected = expected_tokens[i]; |
| 585 i::Token::Value actual = scanner.Next(); | 585 i::Token::Value actual = scanner.Next(); |
| 586 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); | 586 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); |
| 587 if (scanner.location().end_pos == skip_pos) { | 587 if (scanner.location().end_pos == skip_pos) { |
| 588 scanner.SeekForward(skip_to); | 588 scanner.SeekForward(skip_to); |
| 589 } | 589 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 static_cast<unsigned>(strlen(str3))); | 648 static_cast<unsigned>(strlen(str3))); |
| 649 TestStreamScanner(&stream3, expectations3, 1, 1 + i); | 649 TestStreamScanner(&stream3, expectations3, 1, 1 + i); |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 | 652 |
| 653 | 653 |
| 654 void TestScanRegExp(const char* re_source, const char* expected) { | 654 void TestScanRegExp(const char* re_source, const char* expected) { |
| 655 i::Utf8ToUC16CharacterStream stream( | 655 i::Utf8ToUC16CharacterStream stream( |
| 656 reinterpret_cast<const i::byte*>(re_source), | 656 reinterpret_cast<const i::byte*>(re_source), |
| 657 static_cast<unsigned>(strlen(re_source))); | 657 static_cast<unsigned>(strlen(re_source))); |
| 658 i::V8JavaScriptScanner scanner(ISOLATE->scanner_constants()); | 658 i::V8JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 659 scanner.Initialize(&stream); | 659 scanner.Initialize(&stream); |
| 660 | 660 |
| 661 i::Token::Value start = scanner.peek(); | 661 i::Token::Value start = scanner.peek(); |
| 662 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); | 662 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); |
| 663 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); | 663 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); |
| 664 scanner.Next(); // Current token is now the regexp literal. | 664 scanner.Next(); // Current token is now the regexp literal. |
| 665 CHECK(scanner.is_literal_ascii()); | 665 CHECK(scanner.is_literal_ascii()); |
| 666 i::Vector<const char> actual = scanner.literal_ascii_string(); | 666 i::Vector<const char> actual = scanner.literal_ascii_string(); |
| 667 for (int i = 0; i < actual.length(); i++) { | 667 for (int i = 0; i < actual.length(); i++) { |
| 668 CHECK_NE('\0', expected[i]); | 668 CHECK_NE('\0', expected[i]); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 697 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); | 697 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); |
| 698 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); | 698 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); |
| 699 // Escaped ']'s wont end the character class. | 699 // Escaped ']'s wont end the character class. |
| 700 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); | 700 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); |
| 701 // Escaped slashes are not terminating. | 701 // Escaped slashes are not terminating. |
| 702 TestScanRegExp("/\\//flipperwald", "\\/"); | 702 TestScanRegExp("/\\//flipperwald", "\\/"); |
| 703 // Starting with '=' works too. | 703 // Starting with '=' works too. |
| 704 TestScanRegExp("/=/", "="); | 704 TestScanRegExp("/=/", "="); |
| 705 TestScanRegExp("/=?/", "=?"); | 705 TestScanRegExp("/=?/", "=?"); |
| 706 } | 706 } |
| OLD | NEW |