OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/scanner-character-streams.h" | 7 #include "src/scanner-character-streams.h" |
8 | 8 |
9 #include "include/v8.h" | 9 #include "include/v8.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
(...skipping 370 matching lines...) Loading... | |
381 // Did we use all the data in the data chunk? | 381 // Did we use all the data in the data chunk? |
382 if (current_data_offset_ == current_data_length_) { | 382 if (current_data_offset_ == current_data_length_) { |
383 FlushCurrent(); | 383 FlushCurrent(); |
384 } | 384 } |
385 } | 385 } |
386 return data_in_buffer; | 386 return data_in_buffer; |
387 } | 387 } |
388 | 388 |
389 | 389 |
390 bool ExternalStreamingStream::SetBookmark() { | 390 bool ExternalStreamingStream::SetBookmark() { |
391 DCHECK(utf8_split_char_buffer_length_ == 0); // We can't be within a char. | |
392 | |
393 // Bookmarking for this stream is a bit more complex than expected, since | 391 // Bookmarking for this stream is a bit more complex than expected, since |
394 // the stream state is distributed over several places: | 392 // the stream state is distributed over several places: |
395 // - pos_ (inherited from Utf16CharacterStream) | 393 // - pos_ (inherited from Utf16CharacterStream) |
396 // - buffer_cursor_ and buffer_end_ (also from Utf16CharacterStream) | 394 // - buffer_cursor_ and buffer_end_ (also from Utf16CharacterStream) |
397 // - buffer_ (from BufferedUtf16CharacterStream) | 395 // - buffer_ (from BufferedUtf16CharacterStream) |
398 // - current_data_ (+ .._offset_ and .._length) (this class) | 396 // - current_data_ (+ .._offset_ and .._length) (this class) |
397 // - utf8_split_char_buffer_* (a partial utf8 symbol at the block boundary) | |
399 // | 398 // |
400 // The underlying source_stream_ instance likely could re-construct this | 399 // The underlying source_stream_ instance likely could re-construct this |
401 // local data for us, but with the given interfaces we have no way of | 400 // local data for us, but with the given interfaces we have no way of |
402 // accomplishing this. Thus, we'll have to save all data locally. | 401 // accomplishing this. Thus, we'll have to save all data locally. |
403 // | 402 // |
404 // What gets saved where: | 403 // What gets saved where: |
405 // - pos_ => bookmark_ | 404 // - pos_ => bookmark_ |
406 // - buffer_[buffer_cursor_ .. buffer_end_] => bookmark_buffer_ | 405 // - buffer_[buffer_cursor_ .. buffer_end_] => bookmark_buffer_ |
407 // - current_data_[.._offset_ .. .._length_] => bookmark_data_ | 406 // - current_data_[.._offset_ .. .._length_] => bookmark_data_ |
407 // - utf8_split_char_buffer_* => bookmark_utf8_split... | |
408 | 408 |
409 bookmark_ = pos_; | 409 bookmark_ = pos_; |
410 | 410 |
411 size_t buffer_length = buffer_end_ - buffer_cursor_; | 411 size_t buffer_length = buffer_end_ - buffer_cursor_; |
412 bookmark_buffer_.Dispose(); | 412 bookmark_buffer_.Dispose(); |
413 bookmark_buffer_ = Vector<uint16_t>::New(static_cast<int>(buffer_length)); | 413 bookmark_buffer_ = Vector<uint16_t>::New(static_cast<int>(buffer_length)); |
414 CopyCharsUnsigned(bookmark_buffer_.start(), buffer_cursor_, buffer_length); | 414 CopyCharsUnsigned(bookmark_buffer_.start(), buffer_cursor_, buffer_length); |
415 | 415 |
416 size_t data_length = current_data_length_ - current_data_offset_; | 416 size_t data_length = current_data_length_ - current_data_offset_; |
417 bookmark_data_.Dispose(); | 417 bookmark_data_.Dispose(); |
418 bookmark_data_ = Vector<uint8_t>::New(static_cast<int>(data_length)); | 418 bookmark_data_ = Vector<uint8_t>::New(static_cast<int>(data_length)); |
419 CopyBytes(bookmark_data_.start(), current_data_ + current_data_offset_, | 419 CopyBytes(bookmark_data_.start(), current_data_ + current_data_offset_, |
420 data_length); | 420 data_length); |
421 | 421 |
422 bookmark_utf8_split_char_buffer_length_ = utf8_split_char_buffer_length_; | |
423 for (size_t i = 0; i < utf8_split_char_buffer_length_; i++) | |
424 bookmark_utf8_split_char_buffer_[i] = utf8_split_char_buffer_[i]; | |
Jakob Kummerow
2015/05/27 15:10:40
nit: V8 wants {} (unless header and body fit on th
vogelheim
2015/05/27 15:17:55
Done.
| |
425 | |
422 return source_stream_->SetBookmark(); | 426 return source_stream_->SetBookmark(); |
423 } | 427 } |
424 | 428 |
425 | 429 |
426 void ExternalStreamingStream::ResetToBookmark() { | 430 void ExternalStreamingStream::ResetToBookmark() { |
427 source_stream_->ResetToBookmark(); | 431 source_stream_->ResetToBookmark(); |
428 FlushCurrent(); | 432 FlushCurrent(); |
429 | 433 |
430 pos_ = bookmark_; | 434 pos_ = bookmark_; |
431 | 435 |
432 // current_data_ can point to bookmark_data_'s buffer. | 436 // current_data_ can point to bookmark_data_'s buffer. |
433 current_data_ = bookmark_data_.start(); | 437 current_data_ = bookmark_data_.start(); |
434 current_data_offset_ = 0; | 438 current_data_offset_ = 0; |
435 current_data_length_ = bookmark_data_.length(); | 439 current_data_length_ = bookmark_data_.length(); |
436 | 440 |
437 // bookmark_buffer_ needs to be copied to buffer_. | 441 // bookmark_buffer_ needs to be copied to buffer_. |
438 CopyCharsUnsigned(buffer_, bookmark_buffer_.begin(), | 442 CopyCharsUnsigned(buffer_, bookmark_buffer_.begin(), |
439 bookmark_buffer_.length()); | 443 bookmark_buffer_.length()); |
440 buffer_cursor_ = buffer_; | 444 buffer_cursor_ = buffer_; |
441 buffer_end_ = buffer_ + bookmark_buffer_.length(); | 445 buffer_end_ = buffer_ + bookmark_buffer_.length(); |
446 | |
447 // utf8 split char buffer | |
448 utf8_split_char_buffer_length_ = bookmark_utf8_split_char_buffer_length_; | |
449 for (size_t i = 0; i < bookmark_utf8_split_char_buffer_length_; i++) | |
450 utf8_split_char_buffer_[i] = bookmark_utf8_split_char_buffer_[i]; | |
442 } | 451 } |
443 | 452 |
444 | 453 |
445 void ExternalStreamingStream::FlushCurrent() { | 454 void ExternalStreamingStream::FlushCurrent() { |
446 delete[] current_data_; | 455 delete[] current_data_; |
447 current_data_ = NULL; | 456 current_data_ = NULL; |
448 current_data_length_ = 0; | 457 current_data_length_ = 0; |
449 current_data_offset_ = 0; | 458 current_data_offset_ = 0; |
450 } | 459 } |
451 | 460 |
(...skipping 86 matching lines...) Loading... | |
538 return true; | 547 return true; |
539 } | 548 } |
540 | 549 |
541 | 550 |
542 void ExternalTwoByteStringUtf16CharacterStream::ResetToBookmark() { | 551 void ExternalTwoByteStringUtf16CharacterStream::ResetToBookmark() { |
543 DCHECK(bookmark_ != kNoBookmark); | 552 DCHECK(bookmark_ != kNoBookmark); |
544 pos_ = bookmark_; | 553 pos_ = bookmark_; |
545 buffer_cursor_ = raw_data_ + bookmark_; | 554 buffer_cursor_ = raw_data_ + bookmark_; |
546 } | 555 } |
547 } } // namespace v8::internal | 556 } } // namespace v8::internal |
OLD | NEW |