Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 'use strict'; | |
| 6 | |
| 7 (function () { | |
| 8 var random_count = 0; | |
| 9 var random_count_threshold = 25; | |
| 10 var random_seed = 0.462; | |
| 11 Math.random = function() { | |
| 12 random_count++; | |
| 13 if (random_count > random_count_threshold){ | |
| 14 random_seed += 0.1; | |
| 15 random_count = 1; | |
| 16 } | |
| 17 return (random_seed % 1); | |
| 18 }; | |
| 19 if (typeof(crypto) == 'object' && | |
| 20 typeof(crypto.getRandomValues) == 'function') { | |
| 21 crypto.getRandomValues = function(arr) { | |
| 22 var scale = Math.pow(256, arr.BYTES_PER_ELEMENT); | |
| 23 for (var i = 0; i < arr.length; i++) { | |
| 24 arr[i] = Math.floor(Math.random() * scale); | |
| 25 } | |
| 26 return arr; | |
| 27 }; | |
| 28 } | |
| 29 })(); | |
| 30 (function () { | |
| 31 var date_count = 0; | |
| 32 var date_count_threshold = 25; | |
| 33 var orig_date = Date; | |
| 34 var time_seed = 1204251968254; | |
|
nednguyen
2017/06/16 17:13:05
at some point we should fix the time_see here to b
| |
| 35 Date = function() { | |
| 36 if (this instanceof Date) { | |
| 37 date_count++; | |
| 38 if (date_count > date_count_threshold){ | |
| 39 time_seed += 50; | |
| 40 date_count = 1; | |
| 41 } | |
| 42 switch (arguments.length) { | |
| 43 case 0: return new orig_date(time_seed); | |
| 44 case 1: return new orig_date(arguments[0]); | |
| 45 default: return new orig_date(arguments[0], arguments[1], | |
| 46 arguments.length >= 3 ? arguments[2] : 1, | |
| 47 arguments.length >= 4 ? arguments[3] : 0, | |
| 48 arguments.length >= 5 ? arguments[4] : 0, | |
| 49 arguments.length >= 6 ? arguments[5] : 0, | |
| 50 arguments.length >= 7 ? arguments[6] : 0); | |
| 51 } | |
| 52 } | |
| 53 return new Date().toString(); | |
| 54 }; | |
| 55 Date.__proto__ = orig_date; | |
| 56 Date.prototype = orig_date.prototype; | |
| 57 Date.prototype.constructor = Date; | |
| 58 orig_date.now = function() { | |
| 59 return new Date().getTime(); | |
| 60 }; | |
| 61 orig_date.prototype.getTimezoneOffset = function() { | |
| 62 var dst2010Start = 1268560800000; | |
| 63 var dst2010End = 1289120400000; | |
| 64 if (this.getTime() >= dst2010Start && this.getTime() < dst2010End) | |
| 65 return 420; | |
| 66 return 480; | |
| 67 }; | |
| 68 })(); | |
| OLD | NEW |