Commit ce63eb08 authored by verwaest's avatar verwaest Committed by Commit bot

[counters] Move waiting for more data from background-parsing into callbacks

BUG=

Review-Url: https://codereview.chromium.org/2549083002
Cr-Commit-Position: refs/heads/master@{#41492}
parent eb6a8ada
...@@ -702,6 +702,7 @@ class RuntimeCallTimer final { ...@@ -702,6 +702,7 @@ class RuntimeCallTimer final {
V(GenericNamedPropertyDescriptorCallback) \ V(GenericNamedPropertyDescriptorCallback) \
V(GenericNamedPropertyQueryCallback) \ V(GenericNamedPropertyQueryCallback) \
V(GenericNamedPropertySetterCallback) \ V(GenericNamedPropertySetterCallback) \
V(GetMoreDataCallback) \
V(IndexedPropertyDefinerCallback) \ V(IndexedPropertyDefinerCallback) \
V(IndexedPropertyDeleterCallback) \ V(IndexedPropertyDeleterCallback) \
V(IndexedPropertyDescriptorCallback) \ V(IndexedPropertyDescriptorCallback) \
......
...@@ -3847,7 +3847,8 @@ void Parser::ParseOnBackground(ParseInfo* info) { ...@@ -3847,7 +3847,8 @@ void Parser::ParseOnBackground(ParseInfo* info) {
} else { } else {
DCHECK(info->character_stream() == nullptr); DCHECK(info->character_stream() == nullptr);
stream.reset(ScannerStream::For(info->source_stream(), stream.reset(ScannerStream::For(info->source_stream(),
info->source_stream_encoding())); info->source_stream_encoding(),
runtime_call_stats_));
stream_ptr = stream.get(); stream_ptr = stream.get();
} }
DCHECK(info->maybe_outer_scope_info().is_null()); DCHECK(info->maybe_outer_scope_info().is_null());
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "src/parsing/scanner-character-streams.h" #include "src/parsing/scanner-character-streams.h"
#include "include/v8.h" #include "include/v8.h"
#include "src/counters.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/handles.h" #include "src/handles.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
...@@ -190,9 +191,11 @@ size_t ExternalOneByteStringUtf16CharacterStream::FillBuffer(size_t from_pos) { ...@@ -190,9 +191,11 @@ size_t ExternalOneByteStringUtf16CharacterStream::FillBuffer(size_t from_pos) {
class Utf8ExternalStreamingStream : public BufferedUtf16CharacterStream { class Utf8ExternalStreamingStream : public BufferedUtf16CharacterStream {
public: public:
Utf8ExternalStreamingStream( Utf8ExternalStreamingStream(
ScriptCompiler::ExternalSourceStream* source_stream) ScriptCompiler::ExternalSourceStream* source_stream,
RuntimeCallStats* stats)
: current_({0, {0, 0, unibrow::Utf8::Utf8IncrementalBuffer(0)}}), : current_({0, {0, 0, unibrow::Utf8::Utf8IncrementalBuffer(0)}}),
source_stream_(source_stream) {} source_stream_(source_stream),
stats_(stats) {}
~Utf8ExternalStreamingStream() override { ~Utf8ExternalStreamingStream() override {
for (size_t i = 0; i < chunks_.size(); i++) delete[] chunks_[i].data; for (size_t i = 0; i < chunks_.size(); i++) delete[] chunks_[i].data;
} }
...@@ -241,6 +244,7 @@ class Utf8ExternalStreamingStream : public BufferedUtf16CharacterStream { ...@@ -241,6 +244,7 @@ class Utf8ExternalStreamingStream : public BufferedUtf16CharacterStream {
std::vector<Chunk> chunks_; std::vector<Chunk> chunks_;
Position current_; Position current_;
ScriptCompiler::ExternalSourceStream* source_stream_; ScriptCompiler::ExternalSourceStream* source_stream_;
RuntimeCallStats* stats_;
}; };
bool Utf8ExternalStreamingStream::SkipToPosition(size_t position) { bool Utf8ExternalStreamingStream::SkipToPosition(size_t position) {
...@@ -331,6 +335,7 @@ void Utf8ExternalStreamingStream::FillBufferFromCurrentChunk() { ...@@ -331,6 +335,7 @@ void Utf8ExternalStreamingStream::FillBufferFromCurrentChunk() {
} }
bool Utf8ExternalStreamingStream::FetchChunk() { bool Utf8ExternalStreamingStream::FetchChunk() {
RuntimeCallTimerScope scope(stats_, &RuntimeCallStats::GetMoreDataCallback);
DCHECK_EQ(current_.chunk_no, chunks_.size()); DCHECK_EQ(current_.chunk_no, chunks_.size());
DCHECK(chunks_.empty() || chunks_.back().length != 0); DCHECK(chunks_.empty() || chunks_.back().length != 0);
...@@ -462,20 +467,23 @@ void DeleteChunks(Chunks& chunks) { ...@@ -462,20 +467,23 @@ void DeleteChunks(Chunks& chunks) {
// Return the chunk index for the chunk containing position. // Return the chunk index for the chunk containing position.
// If position is behind the end of the stream, the index of the last, // If position is behind the end of the stream, the index of the last,
// zero-length chunk is returned. // zero-length chunk is returned.
size_t FindChunk(Chunks& chunks, ScriptCompiler::ExternalSourceStream* source_, size_t FindChunk(Chunks& chunks, ScriptCompiler::ExternalSourceStream* source,
size_t position) { size_t position, RuntimeCallStats* stats) {
size_t end_pos = size_t end_pos =
chunks.empty() ? 0 : (chunks.back().byte_pos + chunks.back().byte_length); chunks.empty() ? 0 : (chunks.back().byte_pos + chunks.back().byte_length);
// Get more data if needed. We usually won't enter the loop body. // Get more data if needed. We usually won't enter the loop body.
bool out_of_data = !chunks.empty() && chunks.back().byte_length == 0; bool out_of_data = !chunks.empty() && chunks.back().byte_length == 0;
while (!out_of_data && end_pos <= position + 1) { {
const uint8_t* chunk = nullptr; RuntimeCallTimerScope scope(stats, &RuntimeCallStats::GetMoreDataCallback);
size_t len = source_->GetMoreData(&chunk); while (!out_of_data && end_pos <= position + 1) {
const uint8_t* chunk = nullptr;
chunks.push_back({chunk, len, end_pos}); size_t len = source->GetMoreData(&chunk);
end_pos += len;
out_of_data = (len == 0); chunks.push_back({chunk, len, end_pos});
end_pos += len;
out_of_data = (len == 0);
}
} }
// Here, we should always have at least one chunk, and we either have the // Here, we should always have at least one chunk, and we either have the
...@@ -516,8 +524,8 @@ size_t FindChunk(Chunks& chunks, ScriptCompiler::ExternalSourceStream* source_, ...@@ -516,8 +524,8 @@ size_t FindChunk(Chunks& chunks, ScriptCompiler::ExternalSourceStream* source_,
class OneByteExternalStreamingStream : public BufferedUtf16CharacterStream { class OneByteExternalStreamingStream : public BufferedUtf16CharacterStream {
public: public:
explicit OneByteExternalStreamingStream( explicit OneByteExternalStreamingStream(
ScriptCompiler::ExternalSourceStream* source) ScriptCompiler::ExternalSourceStream* source, RuntimeCallStats* stats)
: source_(source) {} : source_(source), stats_(stats) {}
~OneByteExternalStreamingStream() override { DeleteChunks(chunks_); } ~OneByteExternalStreamingStream() override { DeleteChunks(chunks_); }
protected: protected:
...@@ -526,10 +534,11 @@ class OneByteExternalStreamingStream : public BufferedUtf16CharacterStream { ...@@ -526,10 +534,11 @@ class OneByteExternalStreamingStream : public BufferedUtf16CharacterStream {
private: private:
Chunks chunks_; Chunks chunks_;
ScriptCompiler::ExternalSourceStream* source_; ScriptCompiler::ExternalSourceStream* source_;
RuntimeCallStats* stats_;
}; };
size_t OneByteExternalStreamingStream::FillBuffer(size_t position) { size_t OneByteExternalStreamingStream::FillBuffer(size_t position) {
const Chunk& chunk = chunks_[FindChunk(chunks_, source_, position)]; const Chunk& chunk = chunks_[FindChunk(chunks_, source_, position, stats_)];
if (chunk.byte_length == 0) return 0; if (chunk.byte_length == 0) return 0;
size_t start_pos = position - chunk.byte_pos; size_t start_pos = position - chunk.byte_pos;
...@@ -550,7 +559,7 @@ size_t OneByteExternalStreamingStream::FillBuffer(size_t position) { ...@@ -550,7 +559,7 @@ size_t OneByteExternalStreamingStream::FillBuffer(size_t position) {
class TwoByteExternalStreamingStream : public Utf16CharacterStream { class TwoByteExternalStreamingStream : public Utf16CharacterStream {
public: public:
explicit TwoByteExternalStreamingStream( explicit TwoByteExternalStreamingStream(
ScriptCompiler::ExternalSourceStream* source); ScriptCompiler::ExternalSourceStream* source, RuntimeCallStats* stats);
~TwoByteExternalStreamingStream() override; ~TwoByteExternalStreamingStream() override;
protected: protected:
...@@ -558,14 +567,16 @@ class TwoByteExternalStreamingStream : public Utf16CharacterStream { ...@@ -558,14 +567,16 @@ class TwoByteExternalStreamingStream : public Utf16CharacterStream {
Chunks chunks_; Chunks chunks_;
ScriptCompiler::ExternalSourceStream* source_; ScriptCompiler::ExternalSourceStream* source_;
RuntimeCallStats* stats_;
uc16 one_char_buffer_; uc16 one_char_buffer_;
}; };
TwoByteExternalStreamingStream::TwoByteExternalStreamingStream( TwoByteExternalStreamingStream::TwoByteExternalStreamingStream(
ScriptCompiler::ExternalSourceStream* source) ScriptCompiler::ExternalSourceStream* source, RuntimeCallStats* stats)
: Utf16CharacterStream(&one_char_buffer_, &one_char_buffer_, : Utf16CharacterStream(&one_char_buffer_, &one_char_buffer_,
&one_char_buffer_, 0), &one_char_buffer_, 0),
source_(source), source_(source),
stats_(stats),
one_char_buffer_(0) {} one_char_buffer_(0) {}
TwoByteExternalStreamingStream::~TwoByteExternalStreamingStream() { TwoByteExternalStreamingStream::~TwoByteExternalStreamingStream() {
...@@ -577,7 +588,7 @@ bool TwoByteExternalStreamingStream::ReadBlock() { ...@@ -577,7 +588,7 @@ bool TwoByteExternalStreamingStream::ReadBlock() {
// We'll search for the 2nd byte of our character, to make sure we // We'll search for the 2nd byte of our character, to make sure we
// have enough data for at least one character. // have enough data for at least one character.
size_t chunk_no = FindChunk(chunks_, source_, 2 * position + 1); size_t chunk_no = FindChunk(chunks_, source_, 2 * position + 1, stats_);
// Out of data? Return 0. // Out of data? Return 0.
if (chunks_[chunk_no].byte_length == 0) { if (chunks_[chunk_no].byte_length == 0) {
...@@ -645,7 +656,7 @@ bool TwoByteExternalStreamingStream::ReadBlock() { ...@@ -645,7 +656,7 @@ bool TwoByteExternalStreamingStream::ReadBlock() {
class TwoByteExternalBufferedStream : public Utf16CharacterStream { class TwoByteExternalBufferedStream : public Utf16CharacterStream {
public: public:
explicit TwoByteExternalBufferedStream( explicit TwoByteExternalBufferedStream(
ScriptCompiler::ExternalSourceStream* source); ScriptCompiler::ExternalSourceStream* source, RuntimeCallStats* stats);
~TwoByteExternalBufferedStream(); ~TwoByteExternalBufferedStream();
protected: protected:
...@@ -663,11 +674,14 @@ class TwoByteExternalBufferedStream : public Utf16CharacterStream { ...@@ -663,11 +674,14 @@ class TwoByteExternalBufferedStream : public Utf16CharacterStream {
Chunks chunks_; Chunks chunks_;
ScriptCompiler::ExternalSourceStream* source_; ScriptCompiler::ExternalSourceStream* source_;
RuntimeCallStats* stats_;
}; };
TwoByteExternalBufferedStream::TwoByteExternalBufferedStream( TwoByteExternalBufferedStream::TwoByteExternalBufferedStream(
ScriptCompiler::ExternalSourceStream* source) ScriptCompiler::ExternalSourceStream* source, RuntimeCallStats* stats)
: Utf16CharacterStream(buffer_, buffer_, buffer_, 0), source_(source) {} : Utf16CharacterStream(buffer_, buffer_, buffer_, 0),
source_(source),
stats_(stats) {}
TwoByteExternalBufferedStream::~TwoByteExternalBufferedStream() { TwoByteExternalBufferedStream::~TwoByteExternalBufferedStream() {
DeleteChunks(chunks_); DeleteChunks(chunks_);
...@@ -676,7 +690,7 @@ TwoByteExternalBufferedStream::~TwoByteExternalBufferedStream() { ...@@ -676,7 +690,7 @@ TwoByteExternalBufferedStream::~TwoByteExternalBufferedStream() {
bool TwoByteExternalBufferedStream::ReadBlock() { bool TwoByteExternalBufferedStream::ReadBlock() {
size_t position = pos(); size_t position = pos();
// Find chunk in which the position belongs // Find chunk in which the position belongs
size_t chunk_no = FindChunk(chunks_, source_, 2 * position + 1); size_t chunk_no = FindChunk(chunks_, source_, 2 * position + 1, stats_);
// Out of data? Return 0. // Out of data? Return 0.
if (chunks_[chunk_no].byte_length == 0) { if (chunks_[chunk_no].byte_length == 0) {
...@@ -722,7 +736,7 @@ size_t TwoByteExternalBufferedStream::FillBuffer(size_t position, ...@@ -722,7 +736,7 @@ size_t TwoByteExternalBufferedStream::FillBuffer(size_t position,
{ {
size_t new_pos = position / kBufferSize * kBufferSize; size_t new_pos = position / kBufferSize * kBufferSize;
if (new_pos != position) { if (new_pos != position) {
chunk_no = FindChunk(chunks_, source_, 2 * new_pos + 1); chunk_no = FindChunk(chunks_, source_, 2 * new_pos + 1, stats_);
buffer_pos_ = new_pos; buffer_pos_ = new_pos;
buffer_cursor_ = buffer_start_ + (position - buffer_pos_); buffer_cursor_ = buffer_start_ + (position - buffer_pos_);
position = new_pos; position = new_pos;
...@@ -764,7 +778,7 @@ size_t TwoByteExternalBufferedStream::FillBuffer(size_t position, ...@@ -764,7 +778,7 @@ size_t TwoByteExternalBufferedStream::FillBuffer(size_t position,
totalLength += bytes_to_move; totalLength += bytes_to_move;
position = (current->byte_pos + current->byte_length) / 2; position = (current->byte_pos + current->byte_length) / 2;
if (position - buffer_pos_ < kBufferSize) { if (position - buffer_pos_ < kBufferSize) {
chunk_no = FindChunk(chunks_, source_, 2 * position + 1); chunk_no = FindChunk(chunks_, source_, 2 * position + 1, stats_);
current = &chunks_[chunk_no]; current = &chunks_[chunk_no];
odd_start = current->byte_pos % 2; odd_start = current->byte_pos % 2;
bytes_to_move = i::Min(2 * kBufferSize - totalLength, current->byte_length); bytes_to_move = i::Min(2 * kBufferSize - totalLength, current->byte_length);
...@@ -777,7 +791,7 @@ size_t TwoByteExternalBufferedStream::FillBuffer(size_t position, ...@@ -777,7 +791,7 @@ size_t TwoByteExternalBufferedStream::FillBuffer(size_t position,
current->data, bytes_to_move); current->data, bytes_to_move);
totalLength += bytes_to_move; totalLength += bytes_to_move;
position = (current->byte_pos + current->byte_length) / 2; position = (current->byte_pos + current->byte_length) / 2;
chunk_no = FindChunk(chunks_, source_, 2 * position + 1); chunk_no = FindChunk(chunks_, source_, 2 * position + 1, stats_);
current = &chunks_[chunk_no]; current = &chunks_[chunk_no];
odd_start = current->byte_pos % 2; odd_start = current->byte_pos % 2;
bytes_to_move = bytes_to_move =
...@@ -824,18 +838,19 @@ std::unique_ptr<Utf16CharacterStream> ScannerStream::ForTesting( ...@@ -824,18 +838,19 @@ std::unique_ptr<Utf16CharacterStream> ScannerStream::ForTesting(
Utf16CharacterStream* ScannerStream::For( Utf16CharacterStream* ScannerStream::For(
ScriptCompiler::ExternalSourceStream* source_stream, ScriptCompiler::ExternalSourceStream* source_stream,
v8::ScriptCompiler::StreamedSource::Encoding encoding) { v8::ScriptCompiler::StreamedSource::Encoding encoding,
RuntimeCallStats* stats) {
switch (encoding) { switch (encoding) {
case v8::ScriptCompiler::StreamedSource::TWO_BYTE: case v8::ScriptCompiler::StreamedSource::TWO_BYTE:
#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64) #if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64)
return new TwoByteExternalStreamingStream(source_stream); return new TwoByteExternalStreamingStream(source_stream, stats);
#else #else
return new TwoByteExternalBufferedStream(source_stream); return new TwoByteExternalBufferedStream(source_stream, stats);
#endif #endif
case v8::ScriptCompiler::StreamedSource::ONE_BYTE: case v8::ScriptCompiler::StreamedSource::ONE_BYTE:
return new OneByteExternalStreamingStream(source_stream); return new OneByteExternalStreamingStream(source_stream, stats);
case v8::ScriptCompiler::StreamedSource::UTF8: case v8::ScriptCompiler::StreamedSource::UTF8:
return new Utf8ExternalStreamingStream(source_stream); return new Utf8ExternalStreamingStream(source_stream, stats);
} }
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
......
...@@ -12,6 +12,7 @@ namespace v8 { ...@@ -12,6 +12,7 @@ namespace v8 {
namespace internal { namespace internal {
class Utf16CharacterStream; class Utf16CharacterStream;
class RuntimeCallStats;
class ScannerStream { class ScannerStream {
public: public:
...@@ -20,7 +21,8 @@ class ScannerStream { ...@@ -20,7 +21,8 @@ class ScannerStream {
int end_pos); int end_pos);
static Utf16CharacterStream* For( static Utf16CharacterStream* For(
ScriptCompiler::ExternalSourceStream* source_stream, ScriptCompiler::ExternalSourceStream* source_stream,
ScriptCompiler::StreamedSource::Encoding encoding); ScriptCompiler::StreamedSource::Encoding encoding,
RuntimeCallStats* stats);
// For testing: // For testing:
static std::unique_ptr<Utf16CharacterStream> ForTesting(const char* data); static std::unique_ptr<Utf16CharacterStream> ForTesting(const char* data);
......
...@@ -100,7 +100,7 @@ TEST(Utf8StreamAsciiOnly) { ...@@ -100,7 +100,7 @@ TEST(Utf8StreamAsciiOnly) {
ChunkSource chunk_source(chunks); ChunkSource chunk_source(chunks);
std::unique_ptr<v8::internal::Utf16CharacterStream> stream( std::unique_ptr<v8::internal::Utf16CharacterStream> stream(
v8::internal::ScannerStream::For( v8::internal::ScannerStream::For(
&chunk_source, v8::ScriptCompiler::StreamedSource::UTF8)); &chunk_source, v8::ScriptCompiler::StreamedSource::UTF8, nullptr));
// Read the data without dying. // Read the data without dying.
v8::internal::uc32 c; v8::internal::uc32 c;
...@@ -118,7 +118,7 @@ TEST(Utf8StreamBOM) { ...@@ -118,7 +118,7 @@ TEST(Utf8StreamBOM) {
ChunkSource chunk_source(chunks); ChunkSource chunk_source(chunks);
std::unique_ptr<v8::internal::Utf16CharacterStream> stream( std::unique_ptr<v8::internal::Utf16CharacterStream> stream(
v8::internal::ScannerStream::For( v8::internal::ScannerStream::For(
&chunk_source, v8::ScriptCompiler::StreamedSource::UTF8)); &chunk_source, v8::ScriptCompiler::StreamedSource::UTF8, nullptr));
// Read the data without tripping over the BOM. // Read the data without tripping over the BOM.
for (size_t i = 0; unicode_ucs2[i]; i++) { for (size_t i = 0; unicode_ucs2[i]; i++) {
...@@ -145,7 +145,7 @@ TEST(Utf8SplitBOM) { ...@@ -145,7 +145,7 @@ TEST(Utf8SplitBOM) {
ChunkSource chunk_source(chunks); ChunkSource chunk_source(chunks);
std::unique_ptr<v8::internal::Utf16CharacterStream> stream( std::unique_ptr<v8::internal::Utf16CharacterStream> stream(
v8::internal::ScannerStream::For( v8::internal::ScannerStream::For(
&chunk_source, v8::ScriptCompiler::StreamedSource::UTF8)); &chunk_source, v8::ScriptCompiler::StreamedSource::UTF8, nullptr));
// Read the data without tripping over the BOM. // Read the data without tripping over the BOM.
for (size_t i = 0; unicode_ucs2[i]; i++) { for (size_t i = 0; unicode_ucs2[i]; i++) {
...@@ -161,7 +161,7 @@ TEST(Utf8SplitBOM) { ...@@ -161,7 +161,7 @@ TEST(Utf8SplitBOM) {
ChunkSource chunk_source(chunks); ChunkSource chunk_source(chunks);
std::unique_ptr<v8::internal::Utf16CharacterStream> stream( std::unique_ptr<v8::internal::Utf16CharacterStream> stream(
v8::internal::ScannerStream::For( v8::internal::ScannerStream::For(
&chunk_source, v8::ScriptCompiler::StreamedSource::UTF8)); &chunk_source, v8::ScriptCompiler::StreamedSource::UTF8, nullptr));
// Read the data without tripping over the BOM. // Read the data without tripping over the BOM.
for (size_t i = 0; unicode_ucs2[i]; i++) { for (size_t i = 0; unicode_ucs2[i]; i++) {
...@@ -190,7 +190,7 @@ TEST(Utf8ChunkBoundaries) { ...@@ -190,7 +190,7 @@ TEST(Utf8ChunkBoundaries) {
ChunkSource chunk_source(chunks); ChunkSource chunk_source(chunks);
std::unique_ptr<v8::internal::Utf16CharacterStream> stream( std::unique_ptr<v8::internal::Utf16CharacterStream> stream(
v8::internal::ScannerStream::For( v8::internal::ScannerStream::For(
&chunk_source, v8::ScriptCompiler::StreamedSource::UTF8)); &chunk_source, v8::ScriptCompiler::StreamedSource::UTF8, nullptr));
for (size_t i = 0; unicode_ucs2[i]; i++) { for (size_t i = 0; unicode_ucs2[i]; i++) {
CHECK_EQ(unicode_ucs2[i], stream->Advance()); CHECK_EQ(unicode_ucs2[i], stream->Advance());
...@@ -219,7 +219,7 @@ TEST(Utf8SingleByteChunks) { ...@@ -219,7 +219,7 @@ TEST(Utf8SingleByteChunks) {
ChunkSource chunk_source(chunks); ChunkSource chunk_source(chunks);
std::unique_ptr<v8::internal::Utf16CharacterStream> stream( std::unique_ptr<v8::internal::Utf16CharacterStream> stream(
v8::internal::ScannerStream::For( v8::internal::ScannerStream::For(
&chunk_source, v8::ScriptCompiler::StreamedSource::UTF8)); &chunk_source, v8::ScriptCompiler::StreamedSource::UTF8, nullptr));
for (size_t j = 0; unicode_ucs2[j]; j++) { for (size_t j = 0; unicode_ucs2[j]; j++) {
CHECK_EQ(unicode_ucs2[j], stream->Advance()); CHECK_EQ(unicode_ucs2[j], stream->Advance());
...@@ -351,13 +351,14 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length, ...@@ -351,13 +351,14 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length,
ChunkSource single_chunk(data, data_end - data, false); ChunkSource single_chunk(data, data_end - data, false);
std::unique_ptr<i::Utf16CharacterStream> one_byte_streaming_stream( std::unique_ptr<i::Utf16CharacterStream> one_byte_streaming_stream(
i::ScannerStream::For(&single_chunk, i::ScannerStream::For(&single_chunk,
v8::ScriptCompiler::StreamedSource::ONE_BYTE)); v8::ScriptCompiler::StreamedSource::ONE_BYTE,
nullptr));
TestCharacterStream(one_byte_source, one_byte_streaming_stream.get(), TestCharacterStream(one_byte_source, one_byte_streaming_stream.get(),
length, start, end); length, start, end);
ChunkSource many_chunks(data, data_end - data, true); ChunkSource many_chunks(data, data_end - data, true);
one_byte_streaming_stream.reset(i::ScannerStream::For( one_byte_streaming_stream.reset(i::ScannerStream::For(
&many_chunks, v8::ScriptCompiler::StreamedSource::ONE_BYTE)); &many_chunks, v8::ScriptCompiler::StreamedSource::ONE_BYTE, nullptr));
TestCharacterStream(one_byte_source, one_byte_streaming_stream.get(), TestCharacterStream(one_byte_source, one_byte_streaming_stream.get(),
length, start, end); length, start, end);
} }
...@@ -370,14 +371,14 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length, ...@@ -370,14 +371,14 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length,
reinterpret_cast<const uint8_t*>(one_byte_vector.end()); reinterpret_cast<const uint8_t*>(one_byte_vector.end());
ChunkSource chunks(data, data_end - data, false); ChunkSource chunks(data, data_end - data, false);
std::unique_ptr<i::Utf16CharacterStream> utf8_streaming_stream( std::unique_ptr<i::Utf16CharacterStream> utf8_streaming_stream(
i::ScannerStream::For(&chunks, i::ScannerStream::For(&chunks, v8::ScriptCompiler::StreamedSource::UTF8,
v8::ScriptCompiler::StreamedSource::UTF8)); nullptr));
TestCharacterStream(one_byte_source, utf8_streaming_stream.get(), length, TestCharacterStream(one_byte_source, utf8_streaming_stream.get(), length,
start, end); start, end);
ChunkSource many_chunks(data, data_end - data, true); ChunkSource many_chunks(data, data_end - data, true);
utf8_streaming_stream.reset(i::ScannerStream::For( utf8_streaming_stream.reset(i::ScannerStream::For(
&many_chunks, v8::ScriptCompiler::StreamedSource::UTF8)); &many_chunks, v8::ScriptCompiler::StreamedSource::UTF8, nullptr));
TestCharacterStream(one_byte_source, utf8_streaming_stream.get(), length, TestCharacterStream(one_byte_source, utf8_streaming_stream.get(), length,
start, end); start, end);
} }
...@@ -390,14 +391,14 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length, ...@@ -390,14 +391,14 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length,
reinterpret_cast<const uint8_t*>(two_byte_vector.end()); reinterpret_cast<const uint8_t*>(two_byte_vector.end());
ChunkSource chunks(data, data_end - data, false); ChunkSource chunks(data, data_end - data, false);
std::unique_ptr<i::Utf16CharacterStream> two_byte_streaming_stream( std::unique_ptr<i::Utf16CharacterStream> two_byte_streaming_stream(
i::ScannerStream::For(&chunks, i::ScannerStream::For(
v8::ScriptCompiler::StreamedSource::TWO_BYTE)); &chunks, v8::ScriptCompiler::StreamedSource::TWO_BYTE, nullptr));
TestCharacterStream(one_byte_source, two_byte_streaming_stream.get(), TestCharacterStream(one_byte_source, two_byte_streaming_stream.get(),
length, start, end); length, start, end);
ChunkSource many_chunks(data, data_end - data, true); ChunkSource many_chunks(data, data_end - data, true);
two_byte_streaming_stream.reset(i::ScannerStream::For( two_byte_streaming_stream.reset(i::ScannerStream::For(
&many_chunks, v8::ScriptCompiler::StreamedSource::TWO_BYTE)); &many_chunks, v8::ScriptCompiler::StreamedSource::TWO_BYTE, nullptr));
TestCharacterStream(one_byte_source, two_byte_streaming_stream.get(), TestCharacterStream(one_byte_source, two_byte_streaming_stream.get(),
length, start, end); length, start, end);
} }
...@@ -439,7 +440,7 @@ TEST(Regress651333) { ...@@ -439,7 +440,7 @@ TEST(Regress651333) {
// 65533) instead of the incorrectly coded Latin1 char. // 65533) instead of the incorrectly coded Latin1 char.
ChunkSource chunks(bytes, len, false); ChunkSource chunks(bytes, len, false);
std::unique_ptr<i::Utf16CharacterStream> stream(i::ScannerStream::For( std::unique_ptr<i::Utf16CharacterStream> stream(i::ScannerStream::For(
&chunks, v8::ScriptCompiler::StreamedSource::UTF8)); &chunks, v8::ScriptCompiler::StreamedSource::UTF8, nullptr));
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
CHECK_EQ(unicode[i], stream->Advance()); CHECK_EQ(unicode[i], stream->Advance());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment