28 if (IsExternalOneByteString(
string)) {
29 resource_ = Cast<ExternalOneByteString>(
string)->resource();
31 DCHECK(IsExternalTwoByteString(
string));
32 resource_ = Cast<ExternalTwoByteString>(
string)->resource();
40 : resource_(other.resource_) {
55template <
typename Char>
62 return reinterpret_cast<intptr_t
>(
start) %
sizeof(Char) == 1;
67template <
typename Char>
98template <
typename Char>
106 data_(string->GetChars() + start_offset),
110 :
lock_(other.lock_),
131template <
typename Char>
152template <
typename Char>
167 size_t buffer_end = chunk.
length;
168 size_t buffer_pos = std::min(buffer_end,
pos - chunk.
position);
169 return {&chunk.
data.get()[buffer_pos], &chunk.
data.get()[buffer_end]};
179 std::unique_ptr<const Char[]>
data;
196 for (
auto reverse_it =
chunks_->rbegin(); reverse_it !=
chunks_->rend();
198 if (reverse_it->position <=
position)
return *reverse_it;
209 length /
sizeof(Char));
217 const uint8_t* data =
nullptr;
220 RCS_SCOPE(stats, RuntimeCallCounterId::kGetMoreDataCallback);
229 std::shared_ptr<std::vector<struct Chunk>>
chunks_;
235template <
template <
typename T>
class ByteStream>
238 template <
class... TArgs>
244 return ByteStream<uint16_t>::kCanBeCloned;
247 std::unique_ptr<Utf16CharacterStream>
Clone()
const override {
249 return std::unique_ptr<Utf16CharacterStream>(
262 if (range.length() == 0) {
267 size_t length = std::min({
kBufferSize, range.length()});
274 return ByteStream<uint8_t>::kCanAccessHeap;
288template <
template <
typename T>
class ByteStream>
291 template <
class... TArgs>
297 return ByteStream<uint16_t>::kCanAccessHeap;
301 return ByteStream<uint16_t>::kCanBeCloned;
304 std::unique_ptr<Utf16CharacterStream>
Clone()
const override {
305 return std::unique_ptr<Utf16CharacterStream>(
315 if (range.length() == 0) {
319 static const uint16_t empty_buffer[1] = {0};
329 DCHECK(!range.unaligned_start());
345 template <
class... TArgs>
426static const base::uc16 kWindows1252ToUC16[256] = {
427 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
428 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
429 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
430 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
431 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
432 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
433 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
434 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
435 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
436 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
437 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
438 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
439 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
440 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
441 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
442 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
443 0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
444 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F,
445 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
446 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178,
447 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
448 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
449 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
450 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
451 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
452 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
453 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
454 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
455 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
456 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
457 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
458 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
475 std::unique_ptr<Utf16CharacterStream>
Clone()
const override {
477 return std::unique_ptr<Utf16CharacterStream>(
490 if (range.length() == 0) {
495 size_t length = std::min({
kBufferSize, range.length()});
496 std::transform(range.start, range.start + length, &
buffer_[0],
497 [](uint8_t c) { return kWindows1252ToUC16[c]; });
531 current_({0, {0, 0, 0, unibrow::Utf8::State::kAccept}}),
539 std::unique_ptr<Utf16CharacterStream>
Clone()
const override {
540 return std::unique_ptr<Utf16CharacterStream>(
573 std::unique_ptr<const uint8_t[]>
data;
580 current_({0, {0, 0, 0, unibrow::Utf8::State::kAccept}}),
612 const uint8_t* cursor = &chunk.
data.get()[it];
618 while (cursor <
end) {
679 const uint8_t* cursor = chunk.
data.get() + it;
684 while (cursor <
end) {
692 }
else if (t == kUtf8Bom) {
695 *(output_cursor++) =
static_cast<base::uc16>(t);
705 while (cursor <
end && output_cursor + 1 < max_buffer_end) {
718 size_t remaining =
end - cursor;
719 size_t max_buffer = max_buffer_end - output_cursor;
720 int max_length =
static_cast<int>(std::min(remaining, max_buffer));
721 DCHECK_EQ(state, unibrow::Utf8::State::kAccept);
723 CopyChars(output_cursor, cursor, ascii_length);
724 cursor += ascii_length;
725 output_cursor += ascii_length;
750 const uint8_t* chunk =
nullptr;
773 size_t chunk_no =
chunks_->size() - 1;
781 if (
GetChunk(chunk_no).length == 0) {
787 if (chunk_no + 1 <
chunks_->size()) {
793 bool ascii_only_chunk =
798 if (ascii_only_chunk) {
803 unibrow::Utf8::State::kAccept}};
820 bool have_more_data =
true;
822 while (have_more_data && !found) {
845 if (out_of_data)
return 0;
872 int start_pos,
int end_pos) {
876 size_t start_offset = 0;
877 if (IsSlicedString(*data)) {
879 start_offset =
string->offset();
882 data =
handle(parent, isolate);
886 if (IsExternalOneByteString(*data)) {
889 start_offset,
static_cast<size_t>(end_pos));
890 }
else if (IsExternalTwoByteString(*data)) {
893 start_offset,
static_cast<size_t>(end_pos));
894 }
else if (IsSeqOneByteString(*data)) {
897 start_offset,
static_cast<size_t>(end_pos));
898 }
else if (IsSeqTwoByteString(*data)) {
901 start_offset,
static_cast<size_t>(end_pos));
913 const char* data,
size_t length) {
914 if (data ==
nullptr) {
920 static const char non_null_empty_string[1] = {0};
921 data = non_null_empty_string;
924 return std::unique_ptr<Utf16CharacterStream>(
926 0,
reinterpret_cast<const uint8_t*
>(data), length));
930 const uint16_t* data,
size_t length) {
931 if (data ==
nullptr) {
937 static const uint16_t non_null_empty_uint16_t_string[1] = {0};
938 data = non_null_empty_uint16_t_string;
941 return std::unique_ptr<Utf16CharacterStream>(
951 static_cast<size_t>(0), source_stream);
static uint16_t LeadSurrogate(uint32_t char_code)
static const uchar kMaxNonSurrogateCharCode
static uint16_t TrailSurrogate(uint32_t char_code)
static const uchar kBufferEmpty
static const uchar kBadChar
static const uchar kIncomplete
static uchar ValueOfIncrementalFinish(State *state)
Utf8DfaDecoder::State State
static uchar ValueOfIncremental(const uint8_t **cursor, State *state, Utf8IncrementalBuffer *buffer)
virtual size_t GetMoreData(const uint8_t **src)=0
std::unique_ptr< Utf16CharacterStream > Clone() const override
bool can_access_heap() const final
bool can_be_cloned() const final
BufferedCharacterStream(size_t pos, TArgs... args)
ByteStream< uint8_t > byte_stream_
bool ReadBlock(size_t position) final
static const size_t kBufferSize
BufferedCharacterStream(const BufferedCharacterStream< ByteStream > &other)
base::uc16 buffer_[kBufferSize]
base::uc16 buffer_[kBufferSize]
static const size_t kBufferSize
virtual size_t FillBuffer(size_t position)=0
bool ReadBlock(size_t position) final
BufferedUtf16CharacterStream()
ChunkedStream(ScriptCompiler::ExternalSourceStream *source)
Chunk & FindChunk(size_t position, RuntimeCallStats *stats)
std::shared_ptr< std::vector< struct Chunk > > chunks_
ScriptCompiler::ExternalSourceStream * source_
static const bool kCanBeCloned
static const bool kCanAccessHeap
void FetchChunk(size_t position, RuntimeCallStats *stats)
Range< Char > GetDataAt(size_t pos, RuntimeCallStats *stats, DisallowGarbageCollection *no_gc=nullptr)
virtual void ProcessChunk(const uint8_t *data, size_t position, size_t length)
ChunkedStream(const ChunkedStream &other) V8_NOEXCEPT
static const bool kCanAccessHeap
ExternalStringStream(Tagged< ExternalString > string, size_t start_offset, size_t length)
ExternalStringStream(const ExternalStringStream &other) V8_NOEXCEPT
ScopedExternalStringLock lock_
typename CharTraits< Char >::ExternalString ExternalString
Range< Char > GetDataAt(size_t pos, RuntimeCallStats *stats, DisallowGarbageCollection *no_gc=nullptr)
static const bool kCanBeCloned
LocalHeap * main_thread_local_heap()
void RemoveGCEpilogueCallback(GCEpilogueCallback *callback, void *data)
static const bool kCanBeCloned
Range< Char > GetDataAt(size_t pos, RuntimeCallStats *stats, DisallowGarbageCollection *no_gc)
OnHeapStream(Handle< String > string, size_t start_offset, size_t end)
typename CharTraits< Char >::String String
OnHeapStream(const OnHeapStream &) V8_NOEXCEPT
static const bool kCanAccessHeap
const size_t start_offset_
RelocatingCharacterStream(Isolate *isolate, size_t pos, TArgs... args)
~RelocatingCharacterStream() final
void UpdateBufferPointers()
static void UpdateBufferPointersCallback(void *stream)
static Utf16CharacterStream * For(Isolate *isolate, Handle< String > data)
static std::unique_ptr< Utf16CharacterStream > ForTesting(const char *data)
const v8::String::ExternalStringResourceBase * resource_
ScopedExternalStringLock(Tagged< ExternalString > string)
ScopedExternalStringLock(const ScopedExternalStringLock &other) V8_NOEXCEPT
~ScopedExternalStringLock()
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
static const bool kCanBeCloned
TestingStream(const Char *data, size_t length)
static const bool kCanAccessHeap
Range< Char > GetDataAt(size_t pos, RuntimeCallStats *stats, DisallowGarbageCollection *no_gc=nullptr)
bool ReadBlock(size_t position) final
bool can_be_cloned() const final
ByteStream< uint16_t > byte_stream_
bool can_access_heap() const final
UnbufferedCharacterStream(size_t pos, TArgs... args)
UnbufferedCharacterStream(const UnbufferedCharacterStream< ByteStream > &other)
std::unique_ptr< Utf16CharacterStream > Clone() const override
const uint16_t * buffer_end_
const uint16_t * buffer_start_
RuntimeCallStats * runtime_call_stats() const
const uint16_t * buffer_cursor_
Utf8ExternalStreamingStream(ScriptCompiler::ExternalSourceStream *source_stream)
ScriptCompiler::ExternalSourceStream * source_stream_
std::shared_ptr< std::vector< Chunk > > chunks_
Chunk & GetChunk(size_t chunk_no)
size_t FillBuffer(size_t position) final
bool can_access_heap() const final
Utf8ExternalStreamingStream(const Utf8ExternalStreamingStream &source_stream) V8_NOEXCEPT
void FillBufferFromCurrentChunk()
void SearchPosition(size_t position)
bool SkipToPosition(size_t position)
std::unique_ptr< Utf16CharacterStream > Clone() const override
~Utf8ExternalStreamingStream() final=default
bool can_be_cloned() const final
bool ReadBlock(size_t position) final
ChunkedStream< uint8_t > byte_stream_
bool can_be_cloned() const final
bool can_access_heap() const final
Windows1252CharacterStream(const Windows1252CharacterStream &other) V8_NOEXCEPT
std::unique_ptr< Utf16CharacterStream > Clone() const override
static const size_t kBufferSize
Windows1252CharacterStream(size_t pos, ScriptCompiler::ExternalSourceStream *source_stream)
base::uc16 buffer_[kBufferSize]
base::OwnedVector< uint8_t > buffer_
base::Vector< const DirectHandle< Object > > args
LiftoffAssembler::CacheState state
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
void CopyChars(DstType *dst, const SrcType *src, size_t count) V8_NONNULL(1
uint32_t NonAsciiStart(const uint8_t *chars, uint32_t length)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define DCHECK_LE(v1, v2)
#define CHECK_GE(lhs, rhs)
#define CHECK_LE(lhs, rhs)
#define DCHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
std::unique_ptr< const Char[]> data
size_t end_position() const
Chunk(const Char *const data, size_t position, size_t length)
bool unaligned_start() const
Chunk(const uint8_t *data, size_t length, StreamPosition start)
std::unique_ptr< const uint8_t[]> data
unibrow::Utf8::State state
#define V8_LIKELY(condition)
#define V8_UNLIKELY(condition)