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

Side by Side Diff: src/parsing/scanner.h

Issue 2724003006: [parser] Correctly handle invalid escapes in adjacent template tokens. (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
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 // Features shared by parsing and pre-parsing scanners. 5 // Features shared by parsing and pre-parsing scanners.
6 6
7 #ifndef V8_PARSING_SCANNER_H_ 7 #ifndef V8_PARSING_SCANNER_H_
8 #define V8_PARSING_SCANNER_H_ 8 #define V8_PARSING_SCANNER_H_
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // Returns the location information for the current token 208 // Returns the location information for the current token
209 // (the token last returned by Next()). 209 // (the token last returned by Next()).
210 Location location() const { return current_.location; } 210 Location location() const { return current_.location; }
211 211
212 // This error is specifically an invalid hex or unicode escape sequence. 212 // This error is specifically an invalid hex or unicode escape sequence.
213 bool has_error() const { return scanner_error_ != MessageTemplate::kNone; } 213 bool has_error() const { return scanner_error_ != MessageTemplate::kNone; }
214 MessageTemplate::Template error() const { return scanner_error_; } 214 MessageTemplate::Template error() const { return scanner_error_; }
215 Location error_location() const { return scanner_error_location_; } 215 Location error_location() const { return scanner_error_location_; }
216 216
217 bool has_invalid_template_escape() const { 217 bool has_invalid_template_escape() const {
218 return invalid_template_escape_message_ != MessageTemplate::kNone; 218 return current_.invalid_template_escape_message_ != MessageTemplate::kNone;
219 } 219 }
220 MessageTemplate::Template invalid_template_escape_message() const { 220 MessageTemplate::Template invalid_template_escape_message() const {
221 return invalid_template_escape_message_; 221 DCHECK(has_invalid_template_escape());
222 return current_.invalid_template_escape_message_;
222 } 223 }
223 Location invalid_template_escape_location() const { 224 Location invalid_template_escape_location() const {
224 return invalid_template_escape_location_;
225 }
226
227 void clear_invalid_template_escape() {
228 DCHECK(has_invalid_template_escape()); 225 DCHECK(has_invalid_template_escape());
229 invalid_template_escape_message_ = MessageTemplate::kNone; 226 return current_.invalid_template_escape_location_;
230 invalid_template_escape_location_ = Location::invalid();
231 } 227 }
232 228
233 // Similar functions for the upcoming token. 229 // Similar functions for the upcoming token.
234 230
235 // One token look-ahead (past the token returned by Next()). 231 // One token look-ahead (past the token returned by Next()).
236 Token::Value peek() const { return next_.token; } 232 Token::Value peek() const { return next_.token; }
237 233
238 Location peek_location() const { return next_.location; } 234 Location peek_location() const { return next_.location; }
239 235
240 bool literal_contains_escapes() const { 236 bool literal_contains_escapes() const {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 DISALLOW_COPY_AND_ASSIGN(LiteralBuffer); 446 DISALLOW_COPY_AND_ASSIGN(LiteralBuffer);
451 }; 447 };
452 448
453 // The current and look-ahead token. 449 // The current and look-ahead token.
454 struct TokenDesc { 450 struct TokenDesc {
455 Location location; 451 Location location;
456 LiteralBuffer* literal_chars; 452 LiteralBuffer* literal_chars;
457 LiteralBuffer* raw_literal_chars; 453 LiteralBuffer* raw_literal_chars;
458 uint32_t smi_value_; 454 uint32_t smi_value_;
459 Token::Value token; 455 Token::Value token;
456 MessageTemplate::Template invalid_template_escape_message_;
457 Location invalid_template_escape_location_;
vogelheim 2017/03/03 10:40:08 style nitpick: The style guide wants struct member
bakkot1 2017/03/03 20:50:17 Done.
460 }; 458 };
461 459
462 static const int kCharacterLookaheadBufferSize = 1; 460 static const int kCharacterLookaheadBufferSize = 1;
463 const int kMaxAscii = 127; 461 const int kMaxAscii = 127;
464 462
465 // Scans octal escape sequence. Also accepts "\0" decimal escape sequence. 463 // Scans octal escape sequence. Also accepts "\0" decimal escape sequence.
466 template <bool capture_raw> 464 template <bool capture_raw>
467 uc32 ScanOctalEscape(uc32 c, int length); 465 uc32 ScanOctalEscape(uc32 c, int length);
468 466
469 // Call this after setting source_ to the input. 467 // Call this after setting source_ to the input.
470 void Init() { 468 void Init() {
471 // Set c0_ (one character ahead) 469 // Set c0_ (one character ahead)
472 STATIC_ASSERT(kCharacterLookaheadBufferSize == 1); 470 STATIC_ASSERT(kCharacterLookaheadBufferSize == 1);
473 Advance(); 471 Advance();
474 // Initialize current_ to not refer to a literal. 472 // Initialize current_ to not refer to a literal.
475 current_.token = Token::UNINITIALIZED; 473 current_.token = Token::UNINITIALIZED;
476 current_.literal_chars = NULL; 474 current_.literal_chars = NULL;
477 current_.raw_literal_chars = NULL; 475 current_.raw_literal_chars = NULL;
476 current_.invalid_template_escape_message_ = MessageTemplate::kNone;
478 next_.token = Token::UNINITIALIZED; 477 next_.token = Token::UNINITIALIZED;
479 next_.literal_chars = NULL; 478 next_.literal_chars = NULL;
480 next_.raw_literal_chars = NULL; 479 next_.raw_literal_chars = NULL;
480 next_.invalid_template_escape_message_ = MessageTemplate::kNone;
481 next_next_.token = Token::UNINITIALIZED; 481 next_next_.token = Token::UNINITIALIZED;
482 next_next_.literal_chars = NULL; 482 next_next_.literal_chars = NULL;
483 next_next_.raw_literal_chars = NULL; 483 next_next_.raw_literal_chars = NULL;
484 next_next_.invalid_template_escape_message_ = MessageTemplate::kNone;
484 found_html_comment_ = false; 485 found_html_comment_ = false;
485 scanner_error_ = MessageTemplate::kNone; 486 scanner_error_ = MessageTemplate::kNone;
486 invalid_template_escape_message_ = MessageTemplate::kNone;
487 } 487 }
488 488
489 void ReportScannerError(const Location& location, 489 void ReportScannerError(const Location& location,
490 MessageTemplate::Template error) { 490 MessageTemplate::Template error) {
491 if (has_error()) return; 491 if (has_error()) return;
492 scanner_error_ = error; 492 scanner_error_ = error;
493 scanner_error_location_ = location; 493 scanner_error_location_ = location;
494 } 494 }
495 495
496 void ReportScannerError(int pos, MessageTemplate::Template error) { 496 void ReportScannerError(int pos, MessageTemplate::Template error) {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 // Whether there is a multi-line comment that contains a 767 // Whether there is a multi-line comment that contains a
768 // line-terminator after the current token, and before the next. 768 // line-terminator after the current token, and before the next.
769 bool has_multiline_comment_before_next_; 769 bool has_multiline_comment_before_next_;
770 bool has_line_terminator_after_next_; 770 bool has_line_terminator_after_next_;
771 771
772 // Whether this scanner encountered an HTML comment. 772 // Whether this scanner encountered an HTML comment.
773 bool found_html_comment_; 773 bool found_html_comment_;
774 774
775 MessageTemplate::Template scanner_error_; 775 MessageTemplate::Template scanner_error_;
776 Location scanner_error_location_; 776 Location scanner_error_location_;
777
778 MessageTemplate::Template invalid_template_escape_message_;
779 Location invalid_template_escape_location_;
780 }; 777 };
781 778
782 } // namespace internal 779 } // namespace internal
783 } // namespace v8 780 } // namespace v8
784 781
785 #endif // V8_PARSING_SCANNER_H_ 782 #endif // V8_PARSING_SCANNER_H_
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/scanner.cc » ('j') | src/parsing/scanner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698