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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 | 416 |
417 // 4k large buffer. | 417 // 4k large buffer. |
418 char buffer[4096 + 1]; | 418 char buffer[4096 + 1]; |
419 for (unsigned i = 0; i < arraysize(buffer); i++) { | 419 for (unsigned i = 0; i < arraysize(buffer); i++) { |
420 buffer[i] = static_cast<char>(i & 0x7F); | 420 buffer[i] = static_cast<char>(i & 0x7F); |
421 } | 421 } |
422 buffer[arraysize(buffer) - 1] = '\0'; | 422 buffer[arraysize(buffer) - 1] = '\0'; |
423 TestCharacterStreams(buffer, arraysize(buffer) - 1); | 423 TestCharacterStreams(buffer, arraysize(buffer) - 1); |
424 TestCharacterStreams(buffer, arraysize(buffer) - 1, 576, 3298); | 424 TestCharacterStreams(buffer, arraysize(buffer) - 1, 576, 3298); |
425 } | 425 } |
| 426 |
| 427 // Regression test for crbug.com/651333. Read invalid utf-8. |
| 428 TEST(Regress651333) { |
| 429 const uint8_t bytes[] = |
| 430 "A\xf1" |
| 431 "ad"; // Anad, with n == n-with-tilde. |
| 432 const uint16_t unicode[] = {65, 65533, 97, 100}; |
| 433 |
| 434 // Run the test for all sub-strings 0..N of bytes, to make sure we hit the |
| 435 // error condition in and at chunk boundaries. |
| 436 for (size_t len = 0; len < arraysize(bytes); len++) { |
| 437 // Read len bytes from bytes, and compare against the expected unicode |
| 438 // characters. Expect kBadChar ( == Unicode replacement char == code point |
| 439 // 65533) instead of the incorrectly coded Latin1 char. |
| 440 ChunkSource chunks(bytes, len, false); |
| 441 std::unique_ptr<i::Utf16CharacterStream> stream(i::ScannerStream::For( |
| 442 &chunks, v8::ScriptCompiler::StreamedSource::UTF8)); |
| 443 for (size_t i = 0; i < len; i++) { |
| 444 CHECK_EQ(unicode[i], stream->Advance()); |
| 445 } |
| 446 CHECK_EQ(i::Utf16CharacterStream::kEndOfInput, stream->Advance()); |
| 447 } |
| 448 } |
OLD | NEW |