Chromium Code Reviews| 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 #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" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 template <typename Char> | 15 template <typename Char> |
| 16 bool DateParser::Parse(Vector<Char> str, | 16 bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray* out) { |
| 17 FixedArray* out, | 17 UnicodeCache* unicode_cache = isolate->unicode_cache(); |
| 18 UnicodeCache* unicode_cache) { | |
| 19 DCHECK(out->length() >= OUTPUT_SIZE); | 18 DCHECK(out->length() >= OUTPUT_SIZE); |
| 20 InputReader<Char> in(unicode_cache, str); | 19 InputReader<Char> in(unicode_cache, str); |
| 21 DateStringTokenizer<Char> scanner(&in); | 20 DateStringTokenizer<Char> scanner(&in); |
| 22 TimeZoneComposer tz; | 21 TimeZoneComposer tz; |
| 23 TimeComposer time; | 22 TimeComposer time; |
| 24 DayComposer day; | 23 DayComposer day; |
| 25 | 24 |
| 26 // Specification: | 25 // Specification: |
| 27 // Accept ES5 ISO 8601 date-time-strings or legacy dates compatible | 26 // Accept ES5 ISO 8601 date-time-strings or legacy dates compatible |
| 28 // with Safari. | 27 // with Safari. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 // specification. | 68 // specification. |
| 70 // 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, |
| 71 // 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 |
| 72 // garbage string after a number has been read. | 71 // garbage string after a number has been read. |
| 73 | 72 |
| 74 // 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. |
| 75 DateToken next_unhandled_token = ParseES5DateTime(&scanner, &day, &time, &tz); | 74 DateToken next_unhandled_token = ParseES5DateTime(&scanner, &day, &time, &tz); |
| 76 if (next_unhandled_token.IsInvalid()) return false; | 75 if (next_unhandled_token.IsInvalid()) return false; |
| 77 bool has_read_number = !day.IsEmpty(); | 76 bool has_read_number = !day.IsEmpty(); |
| 78 // 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(); | |
| 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 has_read_number = true; | 83 has_read_number = true; |
| 84 int n = token.number(); | 84 int n = token.number(); |
| 85 if (scanner.SkipSymbol(':')) { | 85 if (scanner.SkipSymbol(':')) { |
| 86 if (scanner.SkipSymbol(':')) { | 86 if (scanner.SkipSymbol(':')) { |
| 87 // n + "::" | 87 // n + "::" |
| 88 if (!time.IsEmpty()) return false; | 88 if (!time.IsEmpty()) return false; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 } | 163 } |
| 164 } else if ((token.IsAsciiSign() || token.IsSymbol(')')) && | 164 } else if ((token.IsAsciiSign() || token.IsSymbol(')')) && |
| 165 has_read_number) { | 165 has_read_number) { |
| 166 // Extra sign or ')' is illegal if a number has been read. | 166 // Extra sign or ')' is illegal if a number has been read. |
| 167 return false; | 167 return false; |
| 168 } else { | 168 } else { |
| 169 // Ignore other characters and whitespace. | 169 // Ignore other characters and whitespace. |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 return day.Write(out) && time.Write(out) && tz.Write(out); | 173 bool success = day.Write(out) && time.Write(out) && tz.Write(out); |
| 174 | |
| 175 if (legacy_parser && success) { | |
| 176 isolate->CountUsage(v8::Isolate::kLegacyDateParser); | |
|
Dan Ehrenberg
2016/06/09 12:16:32
I bet we'll find that this gets hit a significant
| |
| 177 } | |
| 178 | |
| 179 return success; | |
| 174 } | 180 } |
| 175 | 181 |
| 176 | 182 |
| 177 template<typename CharType> | 183 template<typename CharType> |
| 178 DateParser::DateToken DateParser::DateStringTokenizer<CharType>::Scan() { | 184 DateParser::DateToken DateParser::DateStringTokenizer<CharType>::Scan() { |
| 179 int pre_pos = in_->position(); | 185 int pre_pos = in_->position(); |
| 180 if (in_->IsEnd()) return DateToken::EndOfInput(); | 186 if (in_->IsEnd()) return DateToken::EndOfInput(); |
| 181 if (in_->IsAsciiDigit()) { | 187 if (in_->IsAsciiDigit()) { |
| 182 int n = in_->ReadUnsignedNumeral(); | 188 int n = in_->ReadUnsignedNumeral(); |
| 183 int length = in_->position() - pre_pos; | 189 int length = in_->position() - pre_pos; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 if (tz->IsEmpty()) tz->Set(0); | 344 if (tz->IsEmpty()) tz->Set(0); |
| 339 day->set_iso_date(); | 345 day->set_iso_date(); |
| 340 return DateToken::EndOfInput(); | 346 return DateToken::EndOfInput(); |
| 341 } | 347 } |
| 342 | 348 |
| 343 | 349 |
| 344 } // namespace internal | 350 } // namespace internal |
| 345 } // namespace v8 | 351 } // namespace v8 |
| 346 | 352 |
| 347 #endif // V8_DATEPARSER_INL_H_ | 353 #endif // V8_DATEPARSER_INL_H_ |
| OLD | NEW |