Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/preparser-api.cc

Issue 6246004: Fix bug when the scanner does a pushback at the end of input. (Closed)
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/scanner.h » ('j') | src/scanner-base.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 pushback_buffer_backing_size_(0) { 62 pushback_buffer_backing_size_(0) {
63 buffer_cursor_ = buffer_end_ = buffer_ + kPushBackSize; 63 buffer_cursor_ = buffer_end_ = buffer_ + kPushBackSize;
64 } 64 }
65 65
66 virtual ~InputStreamUTF16Buffer() { 66 virtual ~InputStreamUTF16Buffer() {
67 if (pushback_buffer_backing_ != NULL) { 67 if (pushback_buffer_backing_ != NULL) {
68 DeleteArray(pushback_buffer_backing_); 68 DeleteArray(pushback_buffer_backing_);
69 } 69 }
70 } 70 }
71 71
72 virtual void PushBack(uc16 ch) { 72 virtual void PushBack(uc32 ch) {
73 ASSERT(pos_ > 0); 73 ASSERT(pos_ > 0);
74 if (ch == kEndOfInput) {
75 pos_--;
76 return;
77 }
74 if (buffer_cursor_ <= pushback_buffer_) { 78 if (buffer_cursor_ <= pushback_buffer_) {
75 // No more room in the current buffer to do pushbacks. 79 // No more room in the current buffer to do pushbacks.
76 if (pushback_buffer_end_cache_ == NULL) { 80 if (pushback_buffer_end_cache_ == NULL) {
77 // We have overflowed the pushback space at the beginning of buffer_. 81 // We have overflowed the pushback space at the beginning of buffer_.
78 // Switch to using a separate allocated pushback buffer. 82 // Switch to using a separate allocated pushback buffer.
79 if (pushback_buffer_backing_ == NULL) { 83 if (pushback_buffer_backing_ == NULL) {
80 // Allocate a buffer the first time we need it. 84 // Allocate a buffer the first time we need it.
81 pushback_buffer_backing_ = NewArray<uc16>(kPushBackSize); 85 pushback_buffer_backing_ = NewArray<uc16>(kPushBackSize);
82 pushback_buffer_backing_size_ = kPushBackSize; 86 pushback_buffer_backing_size_ = kPushBackSize;
83 } 87 }
84 pushback_buffer_ = pushback_buffer_backing_; 88 pushback_buffer_ = pushback_buffer_backing_;
85 pushback_buffer_end_cache_ = buffer_end_; 89 pushback_buffer_end_cache_ = buffer_end_;
86 buffer_end_ = pushback_buffer_backing_ + pushback_buffer_backing_size_; 90 buffer_end_ = pushback_buffer_backing_ + pushback_buffer_backing_size_;
87 buffer_cursor_ = buffer_end_ - 1; 91 buffer_cursor_ = buffer_end_ - 1;
88 } else { 92 } else {
89 // Hit the bottom of the allocated pushback buffer. 93 // Hit the bottom of the allocated pushback buffer.
90 // Double the buffer and continue. 94 // Double the buffer and continue.
91 uc16* new_buffer = NewArray<uc16>(pushback_buffer_backing_size_ * 2); 95 uc16* new_buffer = NewArray<uc16>(pushback_buffer_backing_size_ * 2);
92 memcpy(new_buffer + pushback_buffer_backing_size_, 96 memcpy(new_buffer + pushback_buffer_backing_size_,
93 pushback_buffer_backing_, 97 pushback_buffer_backing_,
94 pushback_buffer_backing_size_); 98 pushback_buffer_backing_size_);
95 DeleteArray(pushback_buffer_backing_); 99 DeleteArray(pushback_buffer_backing_);
96 buffer_cursor_ = new_buffer + pushback_buffer_backing_size_; 100 buffer_cursor_ = new_buffer + pushback_buffer_backing_size_;
97 pushback_buffer_backing_ = pushback_buffer_ = new_buffer; 101 pushback_buffer_backing_ = pushback_buffer_ = new_buffer;
98 buffer_end_ = pushback_buffer_backing_ + pushback_buffer_backing_size_; 102 buffer_end_ = pushback_buffer_backing_ + pushback_buffer_backing_size_;
99 } 103 }
100 } 104 }
101 pushback_buffer_[buffer_cursor_ - pushback_buffer_- 1] = ch; 105 pushback_buffer_[buffer_cursor_ - pushback_buffer_- 1] =
106 static_cast<uc16>(ch);
102 pos_--; 107 pos_--;
103 } 108 }
104 109
105 protected: 110 protected:
106 virtual bool ReadBlock() { 111 virtual bool ReadBlock() {
107 if (pushback_buffer_end_cache_ != NULL) { 112 if (pushback_buffer_end_cache_ != NULL) {
108 buffer_cursor_ = buffer_; 113 buffer_cursor_ = buffer_;
109 buffer_end_ = pushback_buffer_end_cache_; 114 buffer_end_ = pushback_buffer_end_cache_;
110 pushback_buffer_end_cache_ = NULL; 115 pushback_buffer_end_cache_ = NULL;
111 return buffer_end_ > buffer_cursor_; 116 return buffer_end_ > buffer_cursor_;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return PreParserData(size, data); 204 return PreParserData(size, data);
200 } 205 }
201 206
202 } // namespace v8. 207 } // namespace v8.
203 208
204 209
205 // Used by ASSERT macros and other immediate exits. 210 // Used by ASSERT macros and other immediate exits.
206 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { 211 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
207 exit(EXIT_FAILURE); 212 exit(EXIT_FAILURE);
208 } 213 }
OLDNEW
« no previous file with comments | « no previous file | src/scanner.h » ('j') | src/scanner-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698