diff options
| author | Ben Murdoch <benm@google.com> | 2012-04-12 10:51:47 +0100 |
|---|---|---|
| committer | Ben Murdoch <benm@google.com> | 2012-04-16 16:41:38 +0100 |
| commit | 3ef787dbeca8a5fb1086949cda830dccee07bfbd (patch) | |
| tree | 0a22edd97aa148abffdd405c585b22213fccbc82 /src/preparser-api.cc | |
| parent | 85b71799222b55eb5dd74ea26efe0c64ab655c8c (diff) | |
| download | android_external_v8-3ef787dbeca8a5fb1086949cda830dccee07bfbd.tar.gz android_external_v8-3ef787dbeca8a5fb1086949cda830dccee07bfbd.tar.bz2 android_external_v8-3ef787dbeca8a5fb1086949cda830dccee07bfbd.zip | |
Merge V8 at 3.9.24.13
Bug: 5688872
Change-Id: Id0aa8d23375030494d3189c31774059c0f5398fc
Diffstat (limited to 'src/preparser-api.cc')
| -rw-r--r-- | src/preparser-api.cc | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/preparser-api.cc b/src/preparser-api.cc index 899489e2..6e8556aa 100644 --- a/src/preparser-api.cc +++ b/src/preparser-api.cc @@ -46,10 +46,10 @@ namespace v8 { namespace internal { // UTF16Buffer based on a v8::UnicodeInputStream. -class InputStreamUTF16Buffer : public UC16CharacterStream { +class InputStreamUtf16Buffer : public Utf16CharacterStream { public: - /* The InputStreamUTF16Buffer maintains an internal buffer - * that is filled in chunks from the UC16CharacterStream. + /* The InputStreamUtf16Buffer maintains an internal buffer + * that is filled in chunks from the Utf16CharacterStream. * It also maintains unlimited pushback capability, but optimized * for small pushbacks. * The pushback_buffer_ pointer points to the limit of pushbacks @@ -60,8 +60,8 @@ class InputStreamUTF16Buffer : public UC16CharacterStream { * new buffer. When this buffer is read to the end again, the cursor is * switched back to the internal buffer */ - explicit InputStreamUTF16Buffer(v8::UnicodeInputStream* stream) - : UC16CharacterStream(), + explicit InputStreamUtf16Buffer(v8::UnicodeInputStream* stream) + : Utf16CharacterStream(), stream_(stream), pushback_buffer_(buffer_), pushback_buffer_end_cache_(NULL), @@ -70,7 +70,7 @@ class InputStreamUTF16Buffer : public UC16CharacterStream { buffer_cursor_ = buffer_end_ = buffer_ + kPushBackSize; } - virtual ~InputStreamUTF16Buffer() { + virtual ~InputStreamUtf16Buffer() { if (pushback_buffer_backing_ != NULL) { DeleteArray(pushback_buffer_backing_); } @@ -127,12 +127,18 @@ class InputStreamUTF16Buffer : public UC16CharacterStream { uc16* buffer_start = buffer_ + kPushBackSize; buffer_cursor_ = buffer_end_ = buffer_start; while ((value = stream_->Next()) >= 0) { - if (value > static_cast<int32_t>(unibrow::Utf8::kMaxThreeByteChar)) { - value = unibrow::Utf8::kBadChar; + if (value > + static_cast<int32_t>(unibrow::Utf16::kMaxNonSurrogateCharCode)) { + buffer_start[buffer_end_++ - buffer_start] = + unibrow::Utf16::LeadSurrogate(value); + buffer_start[buffer_end_++ - buffer_start] = + unibrow::Utf16::TrailSurrogate(value); + } else { + // buffer_end_ is a const pointer, but buffer_ is writable. + buffer_start[buffer_end_++ - buffer_start] = static_cast<uc16>(value); } - // buffer_end_ is a const pointer, but buffer_ is writable. - buffer_start[buffer_end_++ - buffer_start] = static_cast<uc16>(value); - if (buffer_end_ == buffer_ + kPushBackSize + kBufferSize) break; + // Stop one before the end of the buffer in case we get a surrogate pair. + if (buffer_end_ <= buffer_ + 1 + kPushBackSize + kBufferSize) break; } return buffer_end_ > buffer_start; } @@ -179,16 +185,16 @@ UnicodeInputStream::~UnicodeInputStream() { } PreParserData Preparse(UnicodeInputStream* input, size_t max_stack) { - internal::InputStreamUTF16Buffer buffer(input); + internal::InputStreamUtf16Buffer buffer(input); uintptr_t stack_limit = reinterpret_cast<uintptr_t>(&buffer) - max_stack; internal::UnicodeCache unicode_cache; - internal::JavaScriptScanner scanner(&unicode_cache); + internal::Scanner scanner(&unicode_cache); scanner.Initialize(&buffer); internal::CompleteParserRecorder recorder; preparser::PreParser::PreParseResult result = preparser::PreParser::PreParseProgram(&scanner, &recorder, - true, + internal::kAllowLazy, stack_limit); if (result == preparser::PreParser::kPreParseStackOverflow) { return PreParserData::StackOverflow(); |
