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

Side by Side Diff: src/dateparser-inl.h

Issue 2080183003: Only count legacy parser usage if legacy parser had effect. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add test Created 4 years, 6 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 | test/cctest/test-date.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef V8_DATEPARSER_INL_H_ 5 #ifndef V8_DATEPARSER_INL_H_
6 #define V8_DATEPARSER_INL_H_ 6 #define V8_DATEPARSER_INL_H_
7 7
8 #include "src/char-predicates-inl.h" 8 #include "src/char-predicates-inl.h"
9 #include "src/dateparser.h" 9 #include "src/dateparser.h"
10 #include "src/unicode-cache-inl.h" 10 #include "src/unicode-cache-inl.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // specification. 68 // specification.
69 // After a valid "T" has been read while scanning an ES5 datetime string, 69 // After a valid "T" has been read while scanning an ES5 datetime string,
70 // the input can no longer be a valid legacy date, since the "T" is a 70 // the input can no longer be a valid legacy date, since the "T" is a
71 // garbage string after a number has been read. 71 // garbage string after a number has been read.
72 72
73 // First try getting as far as possible with as ES5 Date Time String. 73 // First try getting as far as possible with as ES5 Date Time String.
74 DateToken next_unhandled_token = ParseES5DateTime(&scanner, &day, &time, &tz); 74 DateToken next_unhandled_token = ParseES5DateTime(&scanner, &day, &time, &tz);
75 if (next_unhandled_token.IsInvalid()) return false; 75 if (next_unhandled_token.IsInvalid()) return false;
76 bool has_read_number = !day.IsEmpty(); 76 bool has_read_number = !day.IsEmpty();
77 // If there's anything left, continue with the legacy parser. 77 // If there's anything left, continue with the legacy parser.
78 bool legacy_parser = !next_unhandled_token.IsEndOfInput(); 78 bool legacy_parser = false;
79 for (DateToken token = next_unhandled_token; 79 for (DateToken token = next_unhandled_token;
80 !token.IsEndOfInput(); 80 !token.IsEndOfInput();
81 token = scanner.Next()) { 81 token = scanner.Next()) {
82 if (token.IsNumber()) { 82 if (token.IsNumber()) {
83 legacy_parser = true;
83 has_read_number = true; 84 has_read_number = true;
84 int n = token.number(); 85 int n = token.number();
85 if (scanner.SkipSymbol(':')) { 86 if (scanner.SkipSymbol(':')) {
86 if (scanner.SkipSymbol(':')) { 87 if (scanner.SkipSymbol(':')) {
87 // n + "::" 88 // n + "::"
88 if (!time.IsEmpty()) return false; 89 if (!time.IsEmpty()) return false;
89 time.Add(n); 90 time.Add(n);
90 time.Add(0); 91 time.Add(0);
91 } else { 92 } else {
92 // n + ":" 93 // n + ":"
(...skipping 15 matching lines...) Expand all
108 DateToken peek = scanner.Peek(); 109 DateToken peek = scanner.Peek();
109 if (!peek.IsEndOfInput() && 110 if (!peek.IsEndOfInput() &&
110 !peek.IsWhiteSpace() && 111 !peek.IsWhiteSpace() &&
111 !peek.IsKeywordZ() && 112 !peek.IsKeywordZ() &&
112 !peek.IsAsciiSign()) return false; 113 !peek.IsAsciiSign()) return false;
113 } else { 114 } else {
114 if (!day.Add(n)) return false; 115 if (!day.Add(n)) return false;
115 scanner.SkipSymbol('-'); 116 scanner.SkipSymbol('-');
116 } 117 }
117 } else if (token.IsKeyword()) { 118 } else if (token.IsKeyword()) {
119 legacy_parser = true;
118 // Parse a "word" (sequence of chars. >= 'A'). 120 // Parse a "word" (sequence of chars. >= 'A').
119 KeywordType type = token.keyword_type(); 121 KeywordType type = token.keyword_type();
120 int value = token.keyword_value(); 122 int value = token.keyword_value();
121 if (type == AM_PM && !time.IsEmpty()) { 123 if (type == AM_PM && !time.IsEmpty()) {
122 time.SetHourOffset(value); 124 time.SetHourOffset(value);
123 } else if (type == MONTH_NAME) { 125 } else if (type == MONTH_NAME) {
124 day.SetNamedMonth(value); 126 day.SetNamedMonth(value);
125 scanner.SkipSymbol('-'); 127 scanner.SkipSymbol('-');
126 } else if (type == TIME_ZONE_NAME && has_read_number) { 128 } else if (type == TIME_ZONE_NAME && has_read_number) {
127 tz.Set(value); 129 tz.Set(value);
128 } else { 130 } else {
129 // Garbage words are illegal if a number has been read. 131 // Garbage words are illegal if a number has been read.
130 if (has_read_number) return false; 132 if (has_read_number) return false;
131 // The first number has to be separated from garbage words by 133 // The first number has to be separated from garbage words by
132 // whitespace or other separators. 134 // whitespace or other separators.
133 if (scanner.Peek().IsNumber()) return false; 135 if (scanner.Peek().IsNumber()) return false;
134 } 136 }
135 } else if (token.IsAsciiSign() && (tz.IsUTC() || !time.IsEmpty())) { 137 } else if (token.IsAsciiSign() && (tz.IsUTC() || !time.IsEmpty())) {
138 legacy_parser = true;
136 // Parse UTC offset (only after UTC or time). 139 // Parse UTC offset (only after UTC or time).
137 tz.SetSign(token.ascii_sign()); 140 tz.SetSign(token.ascii_sign());
138 // The following number may be empty. 141 // The following number may be empty.
139 int n = 0; 142 int n = 0;
140 int length = 0; 143 int length = 0;
141 if (scanner.Peek().IsNumber()) { 144 if (scanner.Peek().IsNumber()) {
142 DateToken token = scanner.Next(); 145 DateToken token = scanner.Next();
143 length = token.length(); 146 length = token.length();
144 n = token.number(); 147 n = token.number();
145 } 148 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (tz->IsEmpty()) tz->Set(0); 347 if (tz->IsEmpty()) tz->Set(0);
345 day->set_iso_date(); 348 day->set_iso_date();
346 return DateToken::EndOfInput(); 349 return DateToken::EndOfInput();
347 } 350 }
348 351
349 352
350 } // namespace internal 353 } // namespace internal
351 } // namespace v8 354 } // namespace v8
352 355
353 #endif // V8_DATEPARSER_INL_H_ 356 #endif // V8_DATEPARSER_INL_H_
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-date.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698