Commit d77963fe authored by yangguo's avatar yangguo Committed by Commit bot

Add UseCounter for Date.parse's legacy parse heuristics.

R=adamk@chromium.org, jochen@chromium.org
BUG=chromium:618595

Review-Url: https://codereview.chromium.org/2050733004
Cr-Commit-Position: refs/heads/master@{#36846}
parent b4475fff
...@@ -5681,6 +5681,7 @@ class V8_EXPORT Isolate { ...@@ -5681,6 +5681,7 @@ class V8_EXPORT Isolate {
kRegExpPrototypeSourceGetter = 30, kRegExpPrototypeSourceGetter = 30,
kRegExpPrototypeOldFlagGetter = 31, kRegExpPrototypeOldFlagGetter = 31,
kDecimalWithLeadingZeroInStrictMode = 32, kDecimalWithLeadingZeroInStrictMode = 32,
kLegacyDateParser = 33,
// If you add new values here, you'll also need to update Chromium's: // If you add new values here, you'll also need to update Chromium's:
// UseCounter.h, V8PerIsolateData.cpp, histograms.xml // UseCounter.h, V8PerIsolateData.cpp, histograms.xml
......
...@@ -3291,11 +3291,9 @@ double ParseDateTimeString(Handle<String> str) { ...@@ -3291,11 +3291,9 @@ double ParseDateTimeString(Handle<String> str) {
String::FlatContent str_content = str->GetFlatContent(); String::FlatContent str_content = str->GetFlatContent();
bool result; bool result;
if (str_content.IsOneByte()) { if (str_content.IsOneByte()) {
result = DateParser::Parse(str_content.ToOneByteVector(), *tmp, result = DateParser::Parse(isolate, str_content.ToOneByteVector(), *tmp);
isolate->unicode_cache());
} else { } else {
result = DateParser::Parse(str_content.ToUC16Vector(), *tmp, result = DateParser::Parse(isolate, str_content.ToUC16Vector(), *tmp);
isolate->unicode_cache());
} }
if (!result) return std::numeric_limits<double>::quiet_NaN(); if (!result) return std::numeric_limits<double>::quiet_NaN();
double const day = MakeDay(tmp->get(0)->Number(), tmp->get(1)->Number(), double const day = MakeDay(tmp->get(0)->Number(), tmp->get(1)->Number(),
......
...@@ -13,9 +13,8 @@ namespace v8 { ...@@ -13,9 +13,8 @@ namespace v8 {
namespace internal { namespace internal {
template <typename Char> template <typename Char>
bool DateParser::Parse(Vector<Char> str, bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray* out) {
FixedArray* out, UnicodeCache* unicode_cache = isolate->unicode_cache();
UnicodeCache* unicode_cache) {
DCHECK(out->length() >= OUTPUT_SIZE); DCHECK(out->length() >= OUTPUT_SIZE);
InputReader<Char> in(unicode_cache, str); InputReader<Char> in(unicode_cache, str);
DateStringTokenizer<Char> scanner(&in); DateStringTokenizer<Char> scanner(&in);
...@@ -76,6 +75,7 @@ bool DateParser::Parse(Vector<Char> str, ...@@ -76,6 +75,7 @@ bool DateParser::Parse(Vector<Char> str,
if (next_unhandled_token.IsInvalid()) return false; if (next_unhandled_token.IsInvalid()) return false;
bool has_read_number = !day.IsEmpty(); bool has_read_number = !day.IsEmpty();
// If there's anything left, continue with the legacy parser. // If there's anything left, continue with the legacy parser.
bool legacy_parser = !next_unhandled_token.IsEndOfInput();
for (DateToken token = next_unhandled_token; for (DateToken token = next_unhandled_token;
!token.IsEndOfInput(); !token.IsEndOfInput();
token = scanner.Next()) { token = scanner.Next()) {
...@@ -170,7 +170,13 @@ bool DateParser::Parse(Vector<Char> str, ...@@ -170,7 +170,13 @@ bool DateParser::Parse(Vector<Char> str,
} }
} }
return day.Write(out) && time.Write(out) && tz.Write(out); bool success = day.Write(out) && time.Write(out) && tz.Write(out);
if (legacy_parser && success) {
isolate->CountUsage(v8::Isolate::kLegacyDateParser);
}
return success;
} }
......
...@@ -26,7 +26,7 @@ class DateParser : public AllStatic { ...@@ -26,7 +26,7 @@ class DateParser : public AllStatic {
// [7]: UTC offset in seconds, or null value if no timezone specified // [7]: UTC offset in seconds, or null value if no timezone specified
// If parsing fails, return false (content of output array is not defined). // If parsing fails, return false (content of output array is not defined).
template <typename Char> template <typename Char>
static bool Parse(Vector<Char> str, FixedArray* output, UnicodeCache* cache); static bool Parse(Isolate* isolate, Vector<Char> str, FixedArray* output);
enum { enum {
YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, UTC_OFFSET, OUTPUT_SIZE YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, UTC_OFFSET, OUTPUT_SIZE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment