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 {
kRegExpPrototypeSourceGetter = 30,
kRegExpPrototypeOldFlagGetter = 31,
kDecimalWithLeadingZeroInStrictMode = 32,
kLegacyDateParser = 33,
// If you add new values here, you'll also need to update Chromium's:
// UseCounter.h, V8PerIsolateData.cpp, histograms.xml
......
......@@ -3291,11 +3291,9 @@ double ParseDateTimeString(Handle<String> str) {
String::FlatContent str_content = str->GetFlatContent();
bool result;
if (str_content.IsOneByte()) {
result = DateParser::Parse(str_content.ToOneByteVector(), *tmp,
isolate->unicode_cache());
result = DateParser::Parse(isolate, str_content.ToOneByteVector(), *tmp);
} else {
result = DateParser::Parse(str_content.ToUC16Vector(), *tmp,
isolate->unicode_cache());
result = DateParser::Parse(isolate, str_content.ToUC16Vector(), *tmp);
}
if (!result) return std::numeric_limits<double>::quiet_NaN();
double const day = MakeDay(tmp->get(0)->Number(), tmp->get(1)->Number(),
......
......@@ -13,9 +13,8 @@ namespace v8 {
namespace internal {
template <typename Char>
bool DateParser::Parse(Vector<Char> str,
FixedArray* out,
UnicodeCache* unicode_cache) {
bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray* out) {
UnicodeCache* unicode_cache = isolate->unicode_cache();
DCHECK(out->length() >= OUTPUT_SIZE);
InputReader<Char> in(unicode_cache, str);
DateStringTokenizer<Char> scanner(&in);
......@@ -76,6 +75,7 @@ bool DateParser::Parse(Vector<Char> str,
if (next_unhandled_token.IsInvalid()) return false;
bool has_read_number = !day.IsEmpty();
// If there's anything left, continue with the legacy parser.
bool legacy_parser = !next_unhandled_token.IsEndOfInput();
for (DateToken token = next_unhandled_token;
!token.IsEndOfInput();
token = scanner.Next()) {
......@@ -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 {
// [7]: UTC offset in seconds, or null value if no timezone specified
// If parsing fails, return false (content of output array is not defined).
template <typename Char>
static bool Parse(Vector<Char> str, FixedArray* output, UnicodeCache* cache);
static bool Parse(Isolate* isolate, Vector<Char> str, FixedArray* output);
enum {
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