V8 Project
v8::internal::ExternalStreamingStream Class Reference

#include <scanner-character-streams.h>

+ Inheritance diagram for v8::internal::ExternalStreamingStream:
+ Collaboration diagram for v8::internal::ExternalStreamingStream:

Public Member Functions

 ExternalStreamingStream (ScriptCompiler::ExternalSourceStream *source_stream, v8::ScriptCompiler::StreamedSource::Encoding encoding)
 
virtual ~ExternalStreamingStream ()
 
virtual unsigned BufferSeekForward (unsigned delta) OVERRIDE
 
virtual unsigned FillBuffer (unsigned position)
 
- Public Member Functions inherited from v8::internal::BufferedUtf16CharacterStream
 BufferedUtf16CharacterStream ()
 
virtual ~BufferedUtf16CharacterStream ()
 
virtual void PushBack (uc32 character)
 
- Public Member Functions inherited from v8::internal::Utf16CharacterStream
 Utf16CharacterStream ()
 
virtual ~Utf16CharacterStream ()
 
uc32 Advance ()
 
unsigned pos () const
 
unsigned SeekForward (unsigned code_unit_count)
 

Private Member Functions

void HandleUtf8SplitCharacters (unsigned *data_in_buffer)
 

Private Attributes

ScriptCompiler::ExternalSourceStreamsource_stream_
 
v8::ScriptCompiler::StreamedSource::Encoding encoding_
 
const uint8_t * current_data_
 
unsigned current_data_offset_
 
unsigned current_data_length_
 
uint8_t utf8_split_char_buffer_ [4]
 
unsigned utf8_split_char_buffer_length_
 

Additional Inherited Members

- Protected Member Functions inherited from v8::internal::BufferedUtf16CharacterStream
virtual unsigned SlowSeekForward (unsigned delta)
 
virtual bool ReadBlock ()
 
virtual void SlowPushBack (uc16 character)
 
- Protected Attributes inherited from v8::internal::BufferedUtf16CharacterStream
const uc16pushback_limit_
 
uc16 buffer_ [kBufferSize]
 
- Protected Attributes inherited from v8::internal::Utf16CharacterStream
const uint16_t * buffer_cursor_
 
const uint16_t * buffer_end_
 
unsigned pos_
 
- Static Protected Attributes inherited from v8::internal::BufferedUtf16CharacterStream
static const unsigned kBufferSize = 512
 
static const unsigned kPushBackStepSize = 16
 
- Static Protected Attributes inherited from v8::internal::Utf16CharacterStream
static const uc32 kEndOfInput = -1
 

Detailed Description

Definition at line 81 of file scanner-character-streams.h.

Constructor & Destructor Documentation

◆ ExternalStreamingStream()

v8::internal::ExternalStreamingStream::ExternalStreamingStream ( ScriptCompiler::ExternalSourceStream source_stream,
v8::ScriptCompiler::StreamedSource::Encoding  encoding 
)
inline

Definition at line 83 of file scanner-character-streams.h.

85  : source_stream_(source_stream),
86  encoding_(encoding),
ScriptCompiler::ExternalSourceStream * source_stream_
v8::ScriptCompiler::StreamedSource::Encoding encoding_
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

◆ ~ExternalStreamingStream()

virtual v8::internal::ExternalStreamingStream::~ExternalStreamingStream ( )
inlinevirtual

Definition at line 92 of file scanner-character-streams.h.

92 { delete[] current_data_; }

References current_data_.

Member Function Documentation

◆ BufferSeekForward()

virtual unsigned v8::internal::ExternalStreamingStream::BufferSeekForward ( unsigned  delta)
inlinevirtual

Implements v8::internal::BufferedUtf16CharacterStream.

Definition at line 94 of file scanner-character-streams.h.

94  {
95  // We never need to seek forward when streaming scripts. We only seek
96  // forward when we want to parse a function whose location we already know,
97  // and when streaming, we don't know the locations of anything we haven't
98  // seen yet.
99  UNREACHABLE();
100  return 0;
101  }
#define UNREACHABLE()
Definition: logging.h:30

References UNREACHABLE.

◆ FillBuffer()

unsigned v8::internal::ExternalStreamingStream::FillBuffer ( unsigned  position)
virtual

Implements v8::internal::BufferedUtf16CharacterStream.

Definition at line 319 of file scanner-character-streams.cc.

319  {
320  // Ignore "position" which is the position in the decoded data. Instead,
321  // ExternalStreamingStream keeps track of the position in the raw data.
322  unsigned data_in_buffer = 0;
323  // Note that the UTF-8 decoder might not be able to fill the buffer
324  // completely; it will typically leave the last character empty (see
325  // Utf8ToUtf16CharacterStream::CopyChars).
326  while (data_in_buffer < kBufferSize - 1) {
327  if (current_data_ == NULL) {
328  // GetSomeData will wait until the embedder has enough data. Here's an
329  // interface between the API which uses size_t (which is the correct type
330  // here) and the internal parts which use unsigned. TODO(marja): make the
331  // internal parts use size_t too.
333  static_cast<unsigned>(source_stream_->GetMoreData(&current_data_));
335  bool data_ends = current_data_length_ == 0;
336 
337  // A caveat: a data chunk might end with bytes from an incomplete UTF-8
338  // character (the rest of the bytes will be in the next chunk).
340  HandleUtf8SplitCharacters(&data_in_buffer);
341  if (!data_ends && current_data_offset_ == current_data_length_) {
342  // The data stream didn't end, but we used all the data in the
343  // chunk. This will only happen when the chunk was really small. We
344  // don't handle the case where a UTF-8 character is split over several
345  // chunks; in that case V8 won't crash, but it will be a parse error.
346  delete[] current_data_;
350  continue; // Request a new chunk.
351  }
352  }
353 
354  // Did the data stream end?
355  if (data_ends) {
357  return data_in_buffer;
358  }
359  }
360 
361  // Fill the buffer from current_data_.
362  unsigned new_offset = 0;
363  unsigned new_chars_in_buffer =
364  CopyCharsHelper(buffer_ + data_in_buffer, kBufferSize - data_in_buffer,
365  current_data_ + current_data_offset_, &new_offset,
367  data_in_buffer += new_chars_in_buffer;
368  current_data_offset_ += new_offset;
369  DCHECK(data_in_buffer <= kBufferSize);
370 
371  // Did we use all the data in the data chunk?
373  delete[] current_data_;
377  }
378  }
379  return data_in_buffer;
380 }
virtual size_t GetMoreData(const uint8_t **src)=0
V8 calls this to request the next chunk of data from the embedder.
void HandleUtf8SplitCharacters(unsigned *data_in_buffer)
#define DCHECK(condition)
Definition: logging.h:205
unsigned CopyCharsHelper(uint16_t *dest, unsigned length, const uint8_t *src, unsigned *src_pos, unsigned src_length, ScriptCompiler::StreamedSource::Encoding encoding)

References v8::internal::BufferedUtf16CharacterStream::buffer_, v8::internal::anonymous_namespace{scanner-character-streams.cc}::CopyCharsHelper(), current_data_, current_data_length_, current_data_offset_, DCHECK, encoding_, v8::ScriptCompiler::ExternalSourceStream::GetMoreData(), HandleUtf8SplitCharacters(), v8::internal::BufferedUtf16CharacterStream::kBufferSize, NULL, source_stream_, v8::ScriptCompiler::StreamedSource::UTF8, and utf8_split_char_buffer_length_.

+ Here is the call graph for this function:

◆ HandleUtf8SplitCharacters()

void v8::internal::ExternalStreamingStream::HandleUtf8SplitCharacters ( unsigned *  data_in_buffer)
private

Definition at line 382 of file scanner-character-streams.cc.

383  {
384  // First check if we have leftover data from the last chunk.
385  unibrow::uchar c;
387  // Move the bytes which are part of the split character (which started in
388  // the previous chunk) into utf8_split_char_buffer_.
396  }
397 
398  // Convert the data in utf8_split_char_buffer_.
399  unsigned new_offset = 0;
400  unsigned new_chars_in_buffer =
401  CopyCharsHelper(buffer_ + *data_in_buffer,
402  kBufferSize - *data_in_buffer, utf8_split_char_buffer_,
404  *data_in_buffer += new_chars_in_buffer;
405  // Make sure we used all the data.
406  DCHECK(new_offset == utf8_split_char_buffer_length_);
407  DCHECK(*data_in_buffer <= kBufferSize);
408 
410  }
411 
412  // Move bytes which are part of an incomplete character from the end of the
413  // current chunk to utf8_split_char_buffer_. They will be converted when the
414  // next data chunk arrives. Note that all valid UTF-8 characters are at most 4
415  // bytes long, but if the data is invalid, we can have character values bigger
416  // than unibrow::Utf8::kMaxOneByteChar for more than 4 consecutive bytes.
423  }
425  for (unsigned i = 0; i < utf8_split_char_buffer_length_; ++i) {
427  }
428 }
static const unsigned kMaxOneByteChar
Definition: unicode.h:141
#define CHECK(condition)
Definition: logging.h:36
unsigned int uchar
Definition: unicode.h:17

References v8::internal::BufferedUtf16CharacterStream::buffer_, CHECK, v8::internal::anonymous_namespace{scanner-character-streams.cc}::CopyCharsHelper(), current_data_, current_data_length_, current_data_offset_, DCHECK, encoding_, v8::internal::BufferedUtf16CharacterStream::kBufferSize, unibrow::Utf8::kMaxOneByteChar, utf8_split_char_buffer_, and utf8_split_char_buffer_length_.

Referenced by FillBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ current_data_

const uint8_t* v8::internal::ExternalStreamingStream::current_data_
private

◆ current_data_length_

unsigned v8::internal::ExternalStreamingStream::current_data_length_
private

Definition at line 112 of file scanner-character-streams.h.

Referenced by FillBuffer(), and HandleUtf8SplitCharacters().

◆ current_data_offset_

unsigned v8::internal::ExternalStreamingStream::current_data_offset_
private

Definition at line 111 of file scanner-character-streams.h.

Referenced by FillBuffer(), and HandleUtf8SplitCharacters().

◆ encoding_

v8::ScriptCompiler::StreamedSource::Encoding v8::internal::ExternalStreamingStream::encoding_
private

Definition at line 109 of file scanner-character-streams.h.

Referenced by FillBuffer(), and HandleUtf8SplitCharacters().

◆ source_stream_

ScriptCompiler::ExternalSourceStream* v8::internal::ExternalStreamingStream::source_stream_
private

Definition at line 108 of file scanner-character-streams.h.

Referenced by FillBuffer().

◆ utf8_split_char_buffer_

uint8_t v8::internal::ExternalStreamingStream::utf8_split_char_buffer_[4]
private

Definition at line 114 of file scanner-character-streams.h.

Referenced by HandleUtf8SplitCharacters().

◆ utf8_split_char_buffer_length_

unsigned v8::internal::ExternalStreamingStream::utf8_split_char_buffer_length_
private

Definition at line 115 of file scanner-character-streams.h.

Referenced by FillBuffer(), and HandleUtf8SplitCharacters().


The documentation for this class was generated from the following files: