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" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Implement ExternalSourceStream based on const char**. | 14 // Implement ExternalSourceStream based on const char**. |
15 // This will take each string as one chunk. The last chunk must be empty. | 15 // This will take each string as one chunk. The last chunk must be empty. |
16 class ChunkSource : public v8::ScriptCompiler::ExternalSourceStream { | 16 class ChunkSource : public v8::ScriptCompiler::ExternalSourceStream { |
17 public: | 17 public: |
18 explicit ChunkSource(const char** chunks) : current_(0) { | 18 explicit ChunkSource(const char** chunks) : current_(0) { |
19 do { | 19 do { |
20 chunks_.push_back( | 20 chunks_.push_back( |
21 {reinterpret_cast<const uint8_t*>(*chunks), strlen(*chunks)}); | 21 {reinterpret_cast<const uint8_t*>(*chunks), strlen(*chunks)}); |
22 chunks++; | 22 chunks++; |
23 } while (chunks_.back().len > 0); | 23 } while (chunks_.back().len > 0); |
24 } | 24 } |
25 ChunkSource(const uint8_t* data, size_t len, bool extra_chunky) | 25 ChunkSource(const uint8_t* data, size_t len, bool extra_chunky) |
26 : current_(0) { | 26 : current_(0) { |
27 // If extra_chunky, we'll use increasingly large chunk sizes. | 27 // If extra_chunky, we'll use increasingly large chunk sizes. |
28 // If not, we'll have a single chunk of full length. | 28 // If not, we'll have a single chunk of full length. |
29 size_t chunk_size = extra_chunky ? 1 : len; | 29 size_t chunk_size = extra_chunky ? 1 : len; |
30 for (size_t i = 0; i < len; i += chunk_size, chunk_size *= 2) { | 30 for (size_t i = 0; i < len; i += chunk_size, chunk_size++) { |
31 chunks_.push_back({data + i, i::Min(chunk_size, len - i)}); | 31 chunks_.push_back({data + i, i::Min(chunk_size, len - i)}); |
32 } | 32 } |
33 chunks_.push_back({nullptr, 0}); | 33 chunks_.push_back({nullptr, 0}); |
34 } | 34 } |
35 ~ChunkSource() {} | 35 ~ChunkSource() {} |
36 bool SetBookmark() override { return false; } | 36 bool SetBookmark() override { return false; } |
37 void ResetToBookmark() override {} | 37 void ResetToBookmark() override {} |
38 size_t GetMoreData(const uint8_t** src) override { | 38 size_t GetMoreData(const uint8_t** src) override { |
39 DCHECK_LT(current_, chunks_.size()); | 39 DCHECK_LT(current_, chunks_.size()); |
40 Chunk& next = chunks_[current_++]; | 40 Chunk& next = chunks_[current_++]; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 // 65533) instead of the incorrectly coded Latin1 char. | 439 // 65533) instead of the incorrectly coded Latin1 char. |
440 ChunkSource chunks(bytes, len, false); | 440 ChunkSource chunks(bytes, len, false); |
441 std::unique_ptr<i::Utf16CharacterStream> stream(i::ScannerStream::For( | 441 std::unique_ptr<i::Utf16CharacterStream> stream(i::ScannerStream::For( |
442 &chunks, v8::ScriptCompiler::StreamedSource::UTF8)); | 442 &chunks, v8::ScriptCompiler::StreamedSource::UTF8)); |
443 for (size_t i = 0; i < len; i++) { | 443 for (size_t i = 0; i < len; i++) { |
444 CHECK_EQ(unicode[i], stream->Advance()); | 444 CHECK_EQ(unicode[i], stream->Advance()); |
445 } | 445 } |
446 CHECK_EQ(i::Utf16CharacterStream::kEndOfInput, stream->Advance()); | 446 CHECK_EQ(i::Utf16CharacterStream::kEndOfInput, stream->Advance()); |
447 } | 447 } |
448 } | 448 } |
OLD | NEW |