Reviewers: Jakob,

Description:
Introduce a flag to overwrite Date.now() with a fixed value

BUG=none
[email protected]
LOG=n

Please review this at https://codereview.chromium.org/1160143004/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+20, -1 lines):
  M src/flag-definitions.h
  M src/runtime/runtime-date.cc
  A test/mjsunit/fixed-date.js


Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index 3ea476ae77785dd909f00bcc52ab36d47b06493a..8720ec621c0f1f8c040d27f8d76c83b4cfa7cf58 100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -756,6 +756,11 @@ DEFINE_BOOL(serialization_statistics, false,
 // Regexp
 DEFINE_BOOL(regexp_optimization, true, "generate optimized regexp code")

+// Date
+DEFINE_INT(fixed_date, 0,
+ "Sets a fixed value for Date.now() if non-zero in seconds since the "
+           "Jan 1, 2014")
+
 // Testing flags test/cctest/test-{flags,api,serialization}.cc
 DEFINE_BOOL(testing_bool_flag, true, "testing_bool_flag")
 DEFINE_MAYBE_BOOL(testing_maybe_bool_flag, "testing_maybe_bool_flag")
Index: src/runtime/runtime-date.cc
diff --git a/src/runtime/runtime-date.cc b/src/runtime/runtime-date.cc
index d2b93f03684e9db5238865f7a55c4e8e85ca94e2..b53b7fa4c031e899fc65f68dcdf615bf70ef1324 100644
--- a/src/runtime/runtime-date.cc
+++ b/src/runtime/runtime-date.cc
@@ -78,7 +78,10 @@ RUNTIME_FUNCTION(Runtime_DateCurrentTime) {
   // time is milliseconds. Therefore, we floor the result of getting
   // the OS time.
   double millis;
-  if (FLAG_verify_predictable) {
+  if (FLAG_fixed_date > 0) {
+    millis = 1388534400000.0;  // Jan 1 2014 00:00:00 GMT+0000
+    millis += 1000.0 * FLAG_fixed_date;
+  } else if (FLAG_verify_predictable) {
     millis = 1388534400000.0;  // Jan 1 2014 00:00:00 GMT+0000
     millis += Floor(isolate->heap()->synthetic_time());
   } else {
Index: test/mjsunit/fixed-date.js
diff --git a/test/mjsunit/fixed-date.js b/test/mjsunit/fixed-date.js
new file mode 100644
index 0000000000000000000000000000000000000000..5a684b0605ced3c12e06a7b3af970a27c003a040
--- /dev/null
+++ b/test/mjsunit/fixed-date.js
@@ -0,0 +1,11 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --fixed-date=42940800
+
+var Jan1_2014_millis = 1388534400000;
+var fixed_date_secs = 42940800;
+assertEquals(Date.now(), Jan1_2014_millis + fixed_date_secs * 1000);
+assertEquals(Date.now(), Jan1_2014_millis + fixed_date_secs * 1000);
+assertEquals(new Date().valueOf(), Jan1_2014_millis + fixed_date_secs * 1000);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to