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

Side by Side Diff: test/cctest/test-date.cc

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 | « src/dateparser-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 CheckDST((august_20 + september_10) / 2); 161 CheckDST((august_20 + september_10) / 2);
162 CheckDST(september_10); 162 CheckDST(september_10);
163 CheckDST(september_10 + 2 * 3600); 163 CheckDST(september_10 + 2 * 3600);
164 CheckDST(september_10 + 2 * 3600 - 1000); 164 CheckDST(september_10 + 2 * 3600 - 1000);
165 CheckDST(august_20 + 2 * 3600); 165 CheckDST(august_20 + 2 * 3600);
166 CheckDST(august_20 + 2 * 3600 - 1000); 166 CheckDST(august_20 + 2 * 3600 - 1000);
167 CheckDST(august_20); 167 CheckDST(august_20);
168 } 168 }
169 169
170 namespace {
171 int legacy_parse_count = 0;
172 void DateParseLegacyCounterCallback(v8::Isolate* isolate,
173 v8::Isolate::UseCounterFeature feature) {
174 if (feature == v8::Isolate::kLegacyDateParser) legacy_parse_count++;
175 }
176 } // anonymous namespace
177
178 TEST(DateParseLegacyUseCounter) {
179 CcTest::InitializeVM();
180 v8::HandleScope scope(CcTest::isolate());
181 LocalContext context;
182 CcTest::isolate()->SetUseCounterCallback(DateParseLegacyCounterCallback);
183 CHECK_EQ(0, legacy_parse_count);
184 CompileRun("Date.parse('2015-02-31')");
185 CHECK_EQ(0, legacy_parse_count);
186 CompileRun("Date.parse('2015-02-31T11:22:33.444Z01:23')");
187 CHECK_EQ(0, legacy_parse_count);
188 CompileRun("Date.parse('2015-02-31T11:22:33.444')");
189 CHECK_EQ(0, legacy_parse_count);
190 CompileRun("Date.parse('2000 01 01')");
191 CHECK_EQ(1, legacy_parse_count);
192 CompileRun("Date.parse('2015-02-31T11:22:33.444 ')");
193 CHECK_EQ(1, legacy_parse_count);
194 }
195
170 #ifdef V8_I18N_SUPPORT 196 #ifdef V8_I18N_SUPPORT
171 TEST(DateCacheVersion) { 197 TEST(DateCacheVersion) {
172 FLAG_allow_natives_syntax = true; 198 FLAG_allow_natives_syntax = true;
173 v8::Isolate* isolate = CcTest::isolate(); 199 v8::Isolate* isolate = CcTest::isolate();
174 v8::Isolate::Scope isolate_scope(isolate); 200 v8::Isolate::Scope isolate_scope(isolate);
175 v8::HandleScope scope(isolate); 201 v8::HandleScope scope(isolate);
176 v8::Local<v8::Context> context = v8::Context::New(isolate); 202 v8::Local<v8::Context> context = v8::Context::New(isolate);
177 v8::Context::Scope context_scope(context); 203 v8::Context::Scope context_scope(context);
178 v8::Local<v8::Number> date_cache_version = 204 v8::Local<v8::Number> date_cache_version =
179 v8::Local<v8::Number>::Cast(CompileRun("%DateCacheVersion()")); 205 v8::Local<v8::Number>::Cast(CompileRun("%DateCacheVersion()"));
180 206
181 CHECK(date_cache_version->IsNumber()); 207 CHECK(date_cache_version->IsNumber());
182 CHECK_EQ(0.0, date_cache_version->NumberValue(context).FromMaybe(-1.0)); 208 CHECK_EQ(0.0, date_cache_version->NumberValue(context).FromMaybe(-1.0));
183 209
184 v8::Date::DateTimeConfigurationChangeNotification(isolate); 210 v8::Date::DateTimeConfigurationChangeNotification(isolate);
185 211
186 date_cache_version = 212 date_cache_version =
187 v8::Local<v8::Number>::Cast(CompileRun("%DateCacheVersion()")); 213 v8::Local<v8::Number>::Cast(CompileRun("%DateCacheVersion()"));
188 CHECK(date_cache_version->IsNumber()); 214 CHECK(date_cache_version->IsNumber());
189 CHECK_EQ(1.0, date_cache_version->NumberValue(context).FromMaybe(-1.0)); 215 CHECK_EQ(1.0, date_cache_version->NumberValue(context).FromMaybe(-1.0));
190 } 216 }
191 #endif // V8_I18N_SUPPORT 217 #endif // V8_I18N_SUPPORT
OLDNEW
« no previous file with comments | « src/dateparser-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698