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

Side by Side Diff: src/runtime/runtime-date.cc

Issue 1160143004: Introduce a flag to overwrite Date.now() with a fixed value (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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/flag-definitions.h ('k') | test/mjsunit/fixed-date.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/date.h" 8 #include "src/date.h"
9 #include "src/dateparser-inl.h" 9 #include "src/dateparser-inl.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 RUNTIME_FUNCTION(Runtime_DateCurrentTime) { 71 RUNTIME_FUNCTION(Runtime_DateCurrentTime) {
72 HandleScope scope(isolate); 72 HandleScope scope(isolate);
73 DCHECK(args.length() == 0); 73 DCHECK(args.length() == 0);
74 if (FLAG_log_timer_events || FLAG_prof_cpp) LOG(isolate, CurrentTimeEvent()); 74 if (FLAG_log_timer_events || FLAG_prof_cpp) LOG(isolate, CurrentTimeEvent());
75 75
76 // According to ECMA-262, section 15.9.1, page 117, the precision of 76 // According to ECMA-262, section 15.9.1, page 117, the precision of
77 // the number in a Date object representing a particular instant in 77 // the number in a Date object representing a particular instant in
78 // time is milliseconds. Therefore, we floor the result of getting 78 // time is milliseconds. Therefore, we floor the result of getting
79 // the OS time. 79 // the OS time.
80 double millis; 80 double millis;
81 if (FLAG_verify_predictable) { 81 if (FLAG_fixed_date > 0) {
82 millis = 1388534400000.0; // Jan 1 2014 00:00:00 GMT+0000
83 millis += 1000.0 * FLAG_fixed_date;
84 } else if (FLAG_verify_predictable) {
82 millis = 1388534400000.0; // Jan 1 2014 00:00:00 GMT+0000 85 millis = 1388534400000.0; // Jan 1 2014 00:00:00 GMT+0000
83 millis += Floor(isolate->heap()->synthetic_time()); 86 millis += Floor(isolate->heap()->synthetic_time());
84 } else { 87 } else {
85 millis = Floor(base::OS::TimeCurrentMillis()); 88 millis = Floor(base::OS::TimeCurrentMillis());
86 } 89 }
87 return *isolate->factory()->NewNumber(millis); 90 return *isolate->factory()->NewNumber(millis);
88 } 91 }
89 92
90 93
91 RUNTIME_FUNCTION(Runtime_DateParseString) { 94 RUNTIME_FUNCTION(Runtime_DateParseString) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 HandleScope scope(isolate); 184 HandleScope scope(isolate);
182 THROW_NEW_ERROR_RETURN_FAILURE( 185 THROW_NEW_ERROR_RETURN_FAILURE(
183 isolate, NewTypeError(MessageTemplate::kNotDateObject)); 186 isolate, NewTypeError(MessageTemplate::kNotDateObject));
184 } 187 }
185 JSDate* date = JSDate::cast(obj); 188 JSDate* date = JSDate::cast(obj);
186 if (index == 0) return date->value(); 189 if (index == 0) return date->value();
187 return JSDate::GetField(date, Smi::FromInt(index)); 190 return JSDate::GetField(date, Smi::FromInt(index));
188 } 191 }
189 } // namespace internal 192 } // namespace internal
190 } // namespace v8 193 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/fixed-date.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698