on master help sign in
Merge pull request #691 from michaelbjames/debugger
93a9d61Evan Czaplicki
libraries/Native/Signal/Signal.js+1−1
@@ -138,7 +138,7 @@ Elm.Native.Signal.make = function(elm) {
138 }
138 }
139
139
140 function timestamp(a) {
140 function timestamp(a) {
141− function update() { return Utils.Tuple2(Date.now(), a.value); }
141+ function update() { return Utils.Tuple2(elm.timer.now(), a.value); }
142 return new LiftN(update, [a]);
142 return new LiftN(update, [a]);
143 }
143 }
144
144
libraries/Native/Signal/Time.js+4−4
@@ -12,10 +12,10 @@ Elm.Native.Time.make = function(elm) {
12
12
13 function fpsWhen(desiredFPS, isOn) {
13 function fpsWhen(desiredFPS, isOn) {
14 var msPerFrame = 1000 / desiredFPS;
14 var msPerFrame = 1000 / desiredFPS;
15− var prev = Date.now(), curr = prev, diff = 0, wasOn = true;
15+ var prev = elm.timer.now(), curr = prev, diff = 0, wasOn = true;
16 var ticker = NS.input(diff);
16 var ticker = NS.input(diff);
17 function tick(zero) { return function() {
17 function tick(zero) { return function() {
18− curr = Date.now();
18+ curr = elm.timer.now();
19 diff = zero ? 0 : curr - prev;
19 diff = zero ? 0 : curr - prev;
20 prev = curr;
20 prev = curr;
21 elm.notify(ticker.id, diff);
21 elm.notify(ticker.id, diff);
@@ -35,9 +35,9 @@ Elm.Native.Time.make = function(elm) {
35 }
35 }
36
36
37 function every(t) {
37 function every(t) {
38− var clock = NS.input(Date.now());
38+ var clock = NS.input(elm.timer.now());
39 function tellTime() {
39 function tellTime() {
40− elm.notify(clock.id, Date.now());
40+ elm.notify(clock.id, elm.timer.now());
41 elm.runDelayed(tellTime, t);
41 elm.runDelayed(tellTime, t);
42 }
42 }
43 elm.runDelayed(tellTime, t);
43 elm.runDelayed(tellTime, t);
libraries/Native/Signal/Touch.js+2−2
@@ -61,11 +61,11 @@ Elm.Native.Touch.make = function(elm) {
61 dict.insert(e.identifier,
61 dict.insert(e.identifier,
62 {x: point._0,
62 {x: point._0,
63 y: point._1,
63 y: point._1,
64− t: Date.now()});
64+ t: elm.timer.now()});
65 }
65 }
66 function end(e) {
66 function end(e) {
67 var t = dict.remove(e.identifier);
67 var t = dict.remove(e.identifier);
68− if (Date.now() - t.t < tapTime) {
68+ if (elm.timer.now() - t.t < tapTime) {
69 hasTap = true;
69 hasTap = true;
70 tap = {_:{}, x:t.x, y:t.y};
70 tap = {_:{}, x:t.x, y:t.y};
71 }
71 }
runtime/Debugger.js+4
@@ -40,6 +40,7 @@ function debugModule(module, runtime) {
40 var recordedEvents = [];
40 var recordedEvents = [];
41 var asyncCallbacks = [];
41 var asyncCallbacks = [];
42 var watchTracker = Elm.Native.Debug.make(runtime).watchTracker;
42 var watchTracker = Elm.Native.Debug.make(runtime).watchTracker;
43+ var now = 0;
43
44
44 function wrapNotify(id, v) {
45 function wrapNotify(id, v) {
45 var timestep = Date.now();
46 var timestep = Date.now();
@@ -112,9 +113,12 @@ function debugModule(module, runtime) {
112 programPaused = true;
113 programPaused = true;
113 clearAsyncCallbacks();
114 clearAsyncCallbacks();
114 tracePath.stopRecording();
115 tracePath.stopRecording();
116+ now = Date.now();
115 }
117 }
116
118
117 function setContinue(position) {
119 function setContinue(position) {
120+ var timerDelay = Date.now() - now;
121+ runtime.timer.addDelay(timerDelay);
118 programPaused = false;
122 programPaused = false;
119 if (position > 0) {
123 if (position > 0) {
120 // If we're not unpausing at the head, then we need to dump the
124 // If we're not unpausing at the head, then we need to dump the
runtime/Init.js+28−1
@@ -31,6 +31,32 @@ function init(display, container, module, ports, moduleToReplace) {
31 // defining state needed for an instance of the Elm RTS
31 // defining state needed for an instance of the Elm RTS
32 var inputs = [];
32 var inputs = [];
33
33
34+ /* OFFSET
35+ * Elm's time traveling debugger lets you interrupt the smooth flow of time
36+ * by pausing and continuing program execution. To ensure the user sees a
37+ * program that moves smoothly through the pause/continue time gap,
38+ * we need to adjsut the value of Date.now().
39+ */
40+ var timer = function() {
41+ var inducedDelay = 0;
42+
43+ var now = function() {
44+ return Date.now() - inducedDelay;
45+ };
46+
47+ var addDelay = function(d) {
48+ if (typeof d !== "number") {
49+ throw "addDelay must take a number (preferably an int), not: " + d
50+ }
51+ inducedDelay += d;
52+ return inducedDelay;
53+ }
54+
55+ return { now : now
56+ , addDelay : addDelay
57+ }
58+ }();
59+
34 var updateInProgress = false;
60 var updateInProgress = false;
35 function notify(id, v) {
61 function notify(id, v) {
36 if (updateInProgress) {
62 if (updateInProgress) {
@@ -40,7 +66,7 @@ function init(display, container, module, ports, moduleToReplace) {
40 'Definitely report this to <https://github.com/evancz/Elm/issues>\n');
66 'Definitely report this to <https://github.com/evancz/Elm/issues>\n');
41 }
67 }
42 updateInProgress = true;
68 updateInProgress = true;
43− var timestep = Date.now();
69+ var timestep = timer.now();
44 for (var i = inputs.length; i--; ) {
70 for (var i = inputs.length; i--; ) {
45 inputs[i].recv(timestep, id, v);
71 inputs[i].recv(timestep, id, v);
46 }
72 }
@@ -72,6 +98,7 @@ function init(display, container, module, ports, moduleToReplace) {
72 id:ElmRuntime.guid(),
98 id:ElmRuntime.guid(),
73 addListener:addListener,
99 addListener:addListener,
74 inputs:inputs,
100 inputs:inputs,
101+ timer:timer,
75 ports: { incoming:ports, outgoing:{}, uses:portUses }
102 ports: { incoming:ports, outgoing:{}, uses:portUses }
76 };
103 };
77
104