on master help sign in
renamed for clarity
efdb99fMichael James
runtime/Debugger.js+28−28
@@ -16,7 +16,7 @@ Elm.debuggerAttach = function(module, hotSwapState /* =undefined */) {
16 var wrappedModule = debugModule(module, runtime);
16 var wrappedModule = debugModule(module, runtime);
17 Elm.Debugger = debuggerInit(wrappedModule, runtime, hotSwapState);
17 Elm.Debugger = debuggerInit(wrappedModule, runtime, hotSwapState);
18 dispatchElmDebuggerInit();
18 dispatchElmDebuggerInit();
19− return wrappedModule.moduleInstance;
19+ return wrappedModule.debuggedModule;
20 }
20 }
21 };
21 };
22};
22};
@@ -40,7 +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+ var pauseTime = 0;
44
44
45 function wrapNotify(id, v) {
45 function wrapNotify(id, v) {
46 var timestep = runtime.timer.now();
46 var timestep = runtime.timer.now();
@@ -113,11 +113,11 @@ function debugModule(module, runtime) {
113 programPaused = true;
113 programPaused = true;
114 clearAsyncCallbacks();
114 clearAsyncCallbacks();
115 tracePath.stopRecording();
115 tracePath.stopRecording();
116− now = Date.now();
116+ pauseTime = Date.now();
117 }
117 }
118
118
119 function setContinue(position) {
119 function setContinue(position) {
120− var timerDelay = Date.now() - now;
120+ var timerDelay = Date.now() - pauseTime;
121 runtime.timer.addDelay(timerDelay);
121 runtime.timer.addDelay(timerDelay);
122 programPaused = false;
122 programPaused = false;
123 if (position > 0) {
123 if (position > 0) {
@@ -140,11 +140,11 @@ function debugModule(module, runtime) {
140 wrappedRuntime.runDelayed = wrapRunDelayed;
140 wrappedRuntime.runDelayed = wrapRunDelayed;
141
141
142 var assignedPropTracker = Object.create(wrappedRuntime);
142 var assignedPropTracker = Object.create(wrappedRuntime);
143− var moduleInstance = module.make(assignedPropTracker);
143+ var debuggedModule = module.make(assignedPropTracker);
144
144
145 // make sure the signal graph is actually a signal & extract the visual model
145 // make sure the signal graph is actually a signal & extract the visual model
146− if ( !('recv' in moduleInstance.main) ) {
146+ if ( !('recv' in debuggedModule.main) ) {
147− moduleInstance.main = Elm.Signal.make(runtime).constant(moduleInstance.main);
147+ debuggedModule.main = Elm.Signal.make(runtime).constant(debuggedModule.main);
148 }
148 }
149
149
150 // The main module stores imported modules onto the runtime.
150 // The main module stores imported modules onto the runtime.
@@ -154,13 +154,13 @@ function debugModule(module, runtime) {
154 runtime[key] = assignedPropTracker[key];
154 runtime[key] = assignedPropTracker[key];
155 });
155 });
156
156
157− var moduleNodes = flattenNodes(wrappedRuntime.inputs);
157+ var signalGraphNodes = flattenSignalGraph(wrappedRuntime.inputs);
158− var tracePath = tracePathInit(runtime, moduleInstance.main);
158+ var tracePath = tracePathInit(runtime, debuggedModule.main);
159
159
160 return {
160 return {
161− moduleInstance: moduleInstance,
161+ debuggedModule: debuggedModule,
162− moduleNodes: moduleNodes,
162+ signalGraphNodes: signalGraphNodes,
163− initialNodeValues: saveNodeValues(moduleNodes),
163+ initialSnapshot: snapshotSignalGraph(signalGraphNodes),
164 initialAsyncCallbacks: asyncCallbacks.slice(),
164 initialAsyncCallbacks: asyncCallbacks.slice(),
165 // API functions
165 // API functions
166 clearAsyncCallbacks: clearAsyncCallbacks,
166 clearAsyncCallbacks: clearAsyncCallbacks,
@@ -182,7 +182,7 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
182
182
183 function resetProgram() {
183 function resetProgram() {
184 debugModule.clearAsyncCallbacks();
184 debugModule.clearAsyncCallbacks();
185− restoreNodeValues(debugModule.moduleNodes, debugModule.initialNodeValues);
185+ restoreSnapshot(debugModule.signalGraphNodes, debugModule.initialSnapshot);
186 redrawGraphics();
186 redrawGraphics();
187 }
187 }
188
188
@@ -208,11 +208,11 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
208 return;
208 return;
209 }
209 }
210 resetProgram();
210 resetProgram();
211− var index = eventCounter;
211+ var continueIndex = eventCounter;
212 eventCounter = 0;
212 eventCounter = 0;
213 debugModule.tracePath.clearTraces();
213 debugModule.tracePath.clearTraces();
214 debugModule.tracePath.startRecording();
214 debugModule.tracePath.startRecording();
215− stepTo(index);
215+ stepTo(continueIndex);
216 debugModule.setContinue(eventCounter);
216 debugModule.setContinue(eventCounter);
217 }
217 }
218 }
218 }
@@ -258,20 +258,20 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
258 }
258 }
259
259
260 function redrawGraphics() {
260 function redrawGraphics() {
261− var main = debugModule.moduleInstance.main
261+ var main = debugModule.debuggedModule.main
262 for (var i = main.kids.length ; i-- ; ) {
262 for (var i = main.kids.length ; i-- ; ) {
263 main.kids[i].recv(runtime.timer.now(), true, main.id);
263 main.kids[i].recv(runtime.timer.now(), true, main.id);
264 }
264 }
265 }
265 }
266
266
267 function getHotSwapState() {
267 function getHotSwapState() {
268− var counter = eventCounter;
268+ var continueIndex = eventCounter;
269 if (!debugModule.getPaused()) {
269 if (!debugModule.getPaused()) {
270− counter = getMaxSteps();
270+ continueIndex = getMaxSteps();
271 }
271 }
272 return {
272 return {
273 recordedEvents: debugModule.copyRecordedEvents(),
273 recordedEvents: debugModule.copyRecordedEvents(),
274− eventCounter: counter
274+ eventCounter: continueIndex
275 };
275 };
276 }
276 }
277
277
@@ -315,9 +315,9 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
315 getPaused: debugModule.getPaused,
315 getPaused: debugModule.getPaused,
316 getHotSwapState: getHotSwapState,
316 getHotSwapState: getHotSwapState,
317 dispose: dispose,
317 dispose: dispose,
318− allNodes: debugModule.moduleNodes,
318+ allNodes: debugModule.signalGraphNodes,
319 watchTracker: debugModule.watchTracker,
319 watchTracker: debugModule.watchTracker,
320− mainNode: debugModule.moduleInstance.main
320+ mainSignalNode: debugModule.debuggedModule.main
321 };
321 };
322
322
323 return elmDebugger;
323 return elmDebugger;
@@ -336,10 +336,10 @@ function Point(x, y) {
336 }
336 }
337}
337}
338
338
339−function tracePathInit(runtime, mainNode) {
339+function tracePathInit(runtime, mainSignalNode) {
340 var List = Elm.List.make(runtime);
340 var List = Elm.List.make(runtime);
341 var Signal = Elm.Signal.make(runtime);
341 var Signal = Elm.Signal.make(runtime);
342− var tracePathNode = A2(Signal.lift, graphicsUpdate, mainNode);
342+ var tracePathNode = A2(Signal.lift, graphicsUpdate, mainSignalNode);
343 var tracePathCanvas = createCanvas();
343 var tracePathCanvas = createCanvas();
344 var tracePositions = {};
344 var tracePositions = {};
345 var recordingTraces = true;
345 var recordingTraces = true;
@@ -474,7 +474,7 @@ function assert(bool, msg) {
474 }
474 }
475}
475}
476
476
477−function saveNodeValues(allNodes) {
477+function snapshotSignalGraph(allNodes) {
478 var nodeValues = [];
478 var nodeValues = [];
479
479
480 allNodes.forEach(function(node) {
480 allNodes.forEach(function(node) {
@@ -485,18 +485,18 @@ function saveNodeValues(allNodes) {
485};
485};
486
486
487
487
488−function restoreNodeValues(allNodes, nodeStates) {
488+function restoreSnapshot(allNodes, snapshot) {
489− assert(allNodes.length == nodeStates.length, "saved program state has wrong length");
489+ assert(allNodes.length == snapshot.length, "saved program state has wrong length");
490 for (var i=0; i < allNodes.length; i++) {
490 for (var i=0; i < allNodes.length; i++) {
491 var node = allNodes[i];
491 var node = allNodes[i];
492− var state = nodeStates[i];
492+ var state = snapshot[i];
493 assert(node.id == state.id, "the nodes moved position");
493 assert(node.id == state.id, "the nodes moved position");
494
494
495 node.value = state.value;
495 node.value = state.value;
496 }
496 }
497}
497}
498
498
499−function flattenNodes(nodes) {
499+function flattenSignalGraph(nodes) {
500 var nodesById = {};
500 var nodesById = {};
501
501
502 function addAllToDict(node) {
502 function addAllToDict(node) {