Commit 8b67a002 authored by yangguo's avatar yangguo Committed by Commit bot

Only count legacy parser usage if legacy parser had effect.

We would otherwise also count if its just trimming whitespaces.

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

Review-Url: https://codereview.chromium.org/2080183003
Cr-Commit-Position: refs/heads/master@{#37197}
parent b9f682ba
......@@ -75,11 +75,12 @@ bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray* out) {
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();
bool legacy_parser = false;
for (DateToken token = next_unhandled_token;
!token.IsEndOfInput();
token = scanner.Next()) {
if (token.IsNumber()) {
legacy_parser = true;
has_read_number = true;
int n = token.number();
if (scanner.SkipSymbol(':')) {
......@@ -115,6 +116,7 @@ bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray* out) {
scanner.SkipSymbol('-');
}
} else if (token.IsKeyword()) {
legacy_parser = true;
// Parse a "word" (sequence of chars. >= 'A').
KeywordType type = token.keyword_type();
int value = token.keyword_value();
......@@ -133,6 +135,7 @@ bool DateParser::Parse(Isolate* isolate, Vector<Char> str, FixedArray* out) {
if (scanner.Peek().IsNumber()) return false;
}
} else if (token.IsAsciiSign() && (tz.IsUTC() || !time.IsEmpty())) {
legacy_parser = true;
// Parse UTC offset (only after UTC or time).
tz.SetSign(token.ascii_sign());
// The following number may be empty.
......
......@@ -167,6 +167,32 @@ TEST(DaylightSavingsTime) {
CheckDST(august_20);
}
namespace {
int legacy_parse_count = 0;
void DateParseLegacyCounterCallback(v8::Isolate* isolate,
v8::Isolate::UseCounterFeature feature) {
if (feature == v8::Isolate::kLegacyDateParser) legacy_parse_count++;
}
} // anonymous namespace
TEST(DateParseLegacyUseCounter) {
CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate());
LocalContext context;
CcTest::isolate()->SetUseCounterCallback(DateParseLegacyCounterCallback);
CHECK_EQ(0, legacy_parse_count);
CompileRun("Date.parse('2015-02-31')");
CHECK_EQ(0, legacy_parse_count);
CompileRun("Date.parse('2015-02-31T11:22:33.444Z01:23')");
CHECK_EQ(0, legacy_parse_count);
CompileRun("Date.parse('2015-02-31T11:22:33.444')");
CHECK_EQ(0, legacy_parse_count);
CompileRun("Date.parse('2000 01 01')");
CHECK_EQ(1, legacy_parse_count);
CompileRun("Date.parse('2015-02-31T11:22:33.444 ')");
CHECK_EQ(1, legacy_parse_count);
}
#ifdef V8_I18N_SUPPORT
TEST(DateCacheVersion) {
FLAG_allow_natives_syntax = true;
......
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