Reviewers: Kasper Lund, Description: Fix an ASSERT in the scanner.
The assert when performing a push back on a two byte string was wrong. Added a small regression test. Please review this at http://codereview.chromium.org/173116 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/scanner.h M src/scanner.cc M test/cctest/test-api.cc Index: src/scanner.cc =================================================================== --- src/scanner.cc (revision 2728) +++ src/scanner.cc (working copy) @@ -183,7 +183,8 @@ void TwoByteStringUTF16Buffer::PushBack(uc32 ch) { pos_--; - ASSERT(pos_ >= 0 && raw_data_[pos_] == ch); + ASSERT(pos_ >= Scanner::kCharacterLookaheadBufferSize); + ASSERT(raw_data_[pos_ - Scanner::kCharacterLookaheadBufferSize] == ch); } Index: src/scanner.h =================================================================== --- src/scanner.h (revision 2728) +++ src/scanner.h (working copy) @@ -212,6 +212,8 @@ static unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator; static unibrow::Predicate<unibrow::WhiteSpace, 128> kIsWhiteSpace; + static const int kCharacterLookaheadBufferSize = 1; + private: CharacterStreamUTF16Buffer char_stream_buffer_; TwoByteStringUTF16Buffer two_byte_string_buffer_; @@ -242,8 +244,6 @@ bool has_line_terminator_before_next_; bool is_pre_parsing_; - static const int kCharacterLookaheadBufferSize = 1; - // Literal buffer support void StartLiteral(); void AddChar(uc32 ch); Index: test/cctest/test-api.cc =================================================================== --- test/cctest/test-api.cc (revision 2728) +++ test/cctest/test-api.cc (working copy) @@ -7150,6 +7150,32 @@ } +TEST(CompileExternalTwoByteSource) { + v8::HandleScope scope; + LocalContext context; + + // This is a very short list of sources, which currently is to check for a + // regression caused by r2703. + const char *ascii_sources[] = { + "0.5", + "-0.5", // This mainly testes PushBack in the Scanner. + "--0.5", // This mainly testes PushBack in the Scanner. + NULL + }; + + // Compile the sources as external two byte strings. + int i = 0; + while (ascii_sources[i] != NULL) { + uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]); + UC16VectorResource uc16_resource( + i::Vector<const uint16_t>(two_byte_string, strlen(ascii_sources[i]))); + v8::Local<v8::String> source = v8::String::NewExternal(&uc16_resource); + v8::Script::Compile(source); + i++; + } +} + + class RegExpStringModificationTest { public: RegExpStringModificationTest() --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list v8-dev@googlegroups.com http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---