on master help sign in
Debugger: pause and continue.
b261585Laszlo Pandy
runtime/Debugger.js+41−13
@@ -33,7 +33,8 @@ function debugModule(module, runtime) {
33 var timestep = Date.now();
33 var timestep = Date.now();
34
34
35 if (programPaused) {
35 if (programPaused) {
36− // ignore notify because we are stepping
36+ // ignore async events generated while playing back
37+ // or user events while program is paused
37 }
38 }
38 else {
39 else {
39 runtime.notify(id, v, timestep);
40 runtime.notify(id, v, timestep);
@@ -42,12 +43,13 @@ function debugModule(module, runtime) {
42 };
43 };
43
44
44 function wrapRunDelayed(func, delayMs) {
45 function wrapRunDelayed(func, delayMs) {
45− return safeSetTimeout(func, delayMs);
46+ var cbObj = { func:func, delayMs:delayMs, timerId:0, executed:false };
46− };
47+ var timerId = setTimeout(function() {
47−
48+ cbObj.executed = true;
48− function safeSetTimeout(func, delayMs) {
49+ func();
49− var timerId = setTimeout(func, delayMs);
50+ }, delayMs);
51+ cbObj.timerId = timerId;
50− asyncCallbacks.push({ func:func, delayMs:delayMs, timerId:timerId });
52+ asyncCallbacks.push(cbObj);
51 return timerId;
53 return timerId;
52 }
54 }
53
55
@@ -57,7 +59,9 @@ function debugModule(module, runtime) {
57
59
58 function clearAsyncCallbacks() {
60 function clearAsyncCallbacks() {
59 asyncCallbacks.forEach(function(timer) {
61 asyncCallbacks.forEach(function(timer) {
62+ if (!timer.executed) {
60− clearTimeout(timer.timerId);
63+ clearTimeout(timer.timerId);
64+ }
61 });
65 });
62 }
66 }
63
67
@@ -75,6 +79,12 @@ function debugModule(module, runtime) {
75
79
76 function setPaused(v) {
80 function setPaused(v) {
77 programPaused = v;
81 programPaused = v;
82+ if (programPaused) {
83+ clearAsyncCallbacks();
84+ }
85+ else {
86+ executeCallbacks(asyncCallbacks);
87+ }
78 }
88 }
79
89
80 function getPaused() {
90 function getPaused() {
@@ -127,10 +137,18 @@ function debuggerInit(debugModule, runtime) {
127 function restartProgram() {
137 function restartProgram() {
128 resetProgram();
138 resetProgram();
129 debugModule.clearRecordedEvents();
139 debugModule.clearRecordedEvents();
130− debugModule.initialAsyncCallbacks.forEach(function(timer) {
140+ executeCallbacks(debugModule.initialAsyncCallbacks);
131− var func = timer.func;
141+ }
132− func();
142+
143+ function pauseProgram() {
144+ debugModule.setPaused(true);
145+ }
146+
147+ function continueProgram() {
148+ if (debugModule.getPaused())
149+ {
150+ debugModule.setPaused(false);
133− });
151+ }
134 }
152 }
135
153
136 function stepTo(index) {
154 function stepTo(index) {
@@ -179,8 +197,9 @@ function debuggerInit(debugModule, runtime) {
179 }
197 }
180
198
181 var elmDebugger = {
199 var elmDebugger = {
182− reset: resetProgram,
183 restart: restartProgram,
200 restart: restartProgram,
201+ pause: pauseProgram,
202+ kontinue: continueProgram,
184 getMaxSteps: getMaxSteps,
203 getMaxSteps: getMaxSteps,
185 stepTo: stepTo
204 stepTo: stepTo
186 };
205 };
@@ -286,6 +305,15 @@ function tracePathInit(runtime) {
286}
305}
287
306
288
307
308+function executeCallbacks(callbacks) {
309+ callbacks.forEach(function(timer) {
310+ if (!timer.executed) {
311+ var func = timer.func;
312+ func();
313+ }
314+ });
315+}
316+
289function createCanvas() {
317function createCanvas() {
290 var c = document.createElement('canvas');
318 var c = document.createElement('canvas');
291 c.width = window.innerWidth;
319 c.width = window.innerWidth;