| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/factory.h" // for i::Factory::NewExternalStringFrom*Byte | 5 #include "src/factory.h" // for i::Factory::NewExternalStringFrom*Byte |
| 6 #include "src/objects-inl.h" | 6 #include "src/objects-inl.h" |
| 7 #include "src/parsing/scanner-character-streams.h" | 7 #include "src/parsing/scanner-character-streams.h" |
| 8 #include "src/parsing/scanner.h" | 8 #include "src/parsing/scanner.h" |
| 9 #include "src/type-feedback-vector-inl.h" // for include "src/factory.h" | 9 #include "src/type-feedback-vector-inl.h" // for include "src/factory.h" |
| 10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 CHECK_EQ(unicode_ucs2[i], stream->Advance()); | 125 CHECK_EQ(unicode_ucs2[i], stream->Advance()); |
| 126 } | 126 } |
| 127 CHECK_EQ(v8::internal::Utf16CharacterStream::kEndOfInput, stream->Advance()); | 127 CHECK_EQ(v8::internal::Utf16CharacterStream::kEndOfInput, stream->Advance()); |
| 128 | 128 |
| 129 // Make sure seek works. | 129 // Make sure seek works. |
| 130 stream->Seek(0); | 130 stream->Seek(0); |
| 131 CHECK_EQ(unicode_ucs2[0], stream->Advance()); | 131 CHECK_EQ(unicode_ucs2[0], stream->Advance()); |
| 132 | 132 |
| 133 stream->Seek(5); | 133 stream->Seek(5); |
| 134 CHECK_EQ(unicode_ucs2[5], stream->Advance()); | 134 CHECK_EQ(unicode_ucs2[5], stream->Advance()); |
| 135 |
| 136 // Try again, but make sure we have to seek 'backwards'. |
| 137 while (v8::internal::Utf16CharacterStream::kEndOfInput != stream->Advance()) { |
| 138 // Do nothing. We merely advance the stream to the end of its input. |
| 139 } |
| 140 stream->Seek(5); |
| 141 CHECK_EQ(unicode_ucs2[5], stream->Advance()); |
| 135 } | 142 } |
| 136 | 143 |
| 137 TEST(Utf8SplitBOM) { | 144 TEST(Utf8SplitBOM) { |
| 138 // Construct chunks with a BOM split into two chunks. | 145 // Construct chunks with a BOM split into two chunks. |
| 139 char partial_bom[] = "\xef\xbb"; | 146 char partial_bom[] = "\xef\xbb"; |
| 140 char data[1 + arraysize(unicode_utf8)] = {"\xbf"}; | 147 char data[1 + arraysize(unicode_utf8)] = {"\xbf"}; |
| 141 strncpy(data + 1, unicode_utf8, arraysize(unicode_utf8)); | 148 strncpy(data + 1, unicode_utf8, arraysize(unicode_utf8)); |
| 142 | 149 |
| 143 { | 150 { |
| 144 const char* chunks[] = {partial_bom, data, "\0"}; | 151 const char* chunks[] = {partial_bom, data, "\0"}; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // 65533) instead of the incorrectly coded Latin1 char. | 447 // 65533) instead of the incorrectly coded Latin1 char. |
| 441 ChunkSource chunks(bytes, len, false); | 448 ChunkSource chunks(bytes, len, false); |
| 442 std::unique_ptr<i::Utf16CharacterStream> stream(i::ScannerStream::For( | 449 std::unique_ptr<i::Utf16CharacterStream> stream(i::ScannerStream::For( |
| 443 &chunks, v8::ScriptCompiler::StreamedSource::UTF8, nullptr)); | 450 &chunks, v8::ScriptCompiler::StreamedSource::UTF8, nullptr)); |
| 444 for (size_t i = 0; i < len; i++) { | 451 for (size_t i = 0; i < len; i++) { |
| 445 CHECK_EQ(unicode[i], stream->Advance()); | 452 CHECK_EQ(unicode[i], stream->Advance()); |
| 446 } | 453 } |
| 447 CHECK_EQ(i::Utf16CharacterStream::kEndOfInput, stream->Advance()); | 454 CHECK_EQ(i::Utf16CharacterStream::kEndOfInput, stream->Advance()); |
| 448 } | 455 } |
| 449 } | 456 } |
| OLD | NEW |