diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-09-12 14:18:53 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-09-12 14:18:53 -0700 |
commit | 97bee9986d71a28a964602af4c0e85b245822145 (patch) | |
tree | bd399038c1ace7fd05cecc5c780f12ef34de645a /tools/reproduceriter.py | |
parent | 29776fb77b125e56f0dcb6a6fd3c5cb28e0b46e7 (diff) |
fake timeouts in shell replay
Diffstat (limited to 'tools/reproduceriter.py')
-rwxr-xr-x | tools/reproduceriter.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/tools/reproduceriter.py b/tools/reproduceriter.py index 8b78e2d6..5f428fd6 100755 --- a/tools/reproduceriter.py +++ b/tools/reproduceriter.py @@ -137,20 +137,40 @@ if (typeof nagivator == 'undefined') { }, search: '%s', }, + fakeNow: 0, // we don't use Date.now() rafs: [], + timeouts: [], requestAnimationFrame: function(func) { window.rafs.push(func); }, + setTimeout: function(func, ms) { + window.timeouts.push({ + func: func, + when: window.fakeNow + ms + }); + window.timeouts.sort(function(x, y) { return y.when - x.when }); + }, runEventLoop: function() { - while (1) { // run forever until an exception stops this replay + // run forever until an exception stops this replay + while (1) { + // rafs var currRafs = window.rafs; window.rafs = []; for (var i = 0; i < currRafs.length; i++) { currRafs[i](); } + // timeouts + var now = window.fakeNow; + while (window.timeouts.length && window.timeouts[timeouts].when <= now) { + var timeout = window.timeouts.pop(); + timeout(); + } + // increment 'time' + window.fakeNow += 16.666; } }, }; + var setTimeout = window.setTimeout; var document = { getElementById: function(id) { switch(id) { @@ -189,7 +209,8 @@ if (typeof nagivator == 'undefined') { }; var performance = { now: function() { - return Date.now(); + print('performance.now!'); + return Date.now(); // XXX XXX XXX }, }; var XMLHttpRequest = function() { |