@@ -1,4 +1,3 @@
2(function() {
1(function() {
3'use strict';
2'use strict';
@@ -23,7 +22,7 @@ Elm.debuggerAttach = function(module, hotSwapState /* =undefined */) {
24function dispatchElmDebuggerInit() {
23function dispatchElmDebuggerInit() {
25 if (parent.window) {
24 if (parent.window) {
26− var dispatch = function(_) {
25+ var dispatch = function() {
27 parent.window.postMessage("elmDebuggerInit", window.location.origin);
26 parent.window.postMessage("elmDebuggerInit", window.location.origin);
29 if (parent.window.document.readyState === "complete") {
28 if (parent.window.document.readyState === "complete") {
@@ -42,6 +41,31 @@ function debugModule(module, runtime) {
42 var watchTracker = Elm.Native.Debug.make(runtime).watchTracker;
41 var watchTracker = Elm.Native.Debug.make(runtime).watchTracker;
43 var pauseTime = 0;
42 var pauseTime = 0;
44+ // runtime is the prototype of wrappedRuntime
45+ // so we can access all runtime properties too
46+ var wrappedRuntime = Object.create(runtime);
47+ wrappedRuntime.notify = wrapNotify;
48+ wrappedRuntime.runDelayed = wrapRunDelayed;
50+ // make a copy of the wrappedRuntime
51+ var assignedPropTracker = Object.create(wrappedRuntime);
52+ var debuggedModule = module.make(assignedPropTracker);
54+ // make sure the signal graph is actually a signal & extract the visual model
55+ if ( !('recv' in debuggedModule.main) ) {
56+ debuggedModule.main = Elm.Signal.make(runtime).constant(debuggedModule.main);
59+ // The main module stores imported modules onto the runtime.
60+ // To ensure only one instance of each module is created,
61+ // we assign them back on the original runtime object.
62+ Object.keys(assignedPropTracker).forEach(function(key) {
63+ runtime[key] = assignedPropTracker[key];
66+ var signalGraphNodes = flattenSignalGraph(wrappedRuntime.inputs);
67+ var tracePath = tracePathInit(runtime, debuggedModule.main);
45 function wrapNotify(id, v) {
69 function wrapNotify(id, v) {
46 var timestep = runtime.timer.now();
70 var timestep = runtime.timer.now();
@@ -123,7 +147,7 @@ function debugModule(module, runtime) {
123 if (position > 0) {
147 if (position > 0) {
124 // If we're not unpausing at the head, then we need to dump the
148 // If we're not unpausing at the head, then we need to dump the
125 // events that are ahead of where we're continuing.
149 // events that are ahead of where we're continuing.
126− recordedEvents = recordedEvents.slice(0,position);
150+ recordedEvents = recordedEvents.slice(0, position);
127 executeCallbacks(asyncCallbacks, false);
151 executeCallbacks(asyncCallbacks, false);
129 tracePath.startRecording();
153 tracePath.startRecording();
@@ -133,30 +157,6 @@ function debugModule(module, runtime) {
133 return programPaused;
157 return programPaused;
136− // runtime is the prototype of wrappedRuntime
137− // so we can access all runtime properties too
138− var wrappedRuntime = Object.create(runtime);
139− wrappedRuntime.notify = wrapNotify;
140− wrappedRuntime.runDelayed = wrapRunDelayed;
142− var assignedPropTracker = Object.create(wrappedRuntime);
143− var debuggedModule = module.make(assignedPropTracker);
145− // make sure the signal graph is actually a signal & extract the visual model
146− if ( !('recv' in debuggedModule.main) ) {
147− debuggedModule.main = Elm.Signal.make(runtime).constant(debuggedModule.main);
150− // The main module stores imported modules onto the runtime.
151− // To ensure only one instance of each module is created,
152− // we assign them back on the original runtime object.
153− Object.keys(assignedPropTracker).forEach(function(key) {
154− runtime[key] = assignedPropTracker[key];
157− var signalGraphNodes = flattenSignalGraph(wrappedRuntime.inputs);
158− var tracePath = tracePathInit(runtime, debuggedModule.main);
161 debuggedModule: debuggedModule,
161 debuggedModule: debuggedModule,
162 signalGraphNodes: signalGraphNodes,
162 signalGraphNodes: signalGraphNodes,
@@ -173,7 +173,7 @@ function debugModule(module, runtime) {
173 setPaused: setPaused,
173 setPaused: setPaused,
174 setContinue: setContinue,
174 setContinue: setContinue,
175 tracePath: tracePath,
175 tracePath: tracePath,
176− watchTracker: watchTracker,
176+ watchTracker: watchTracker
@@ -203,7 +203,7 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
203 function continueProgram() {
203 function continueProgram() {
204 if (debugModule.getPaused())
204 if (debugModule.getPaused())
206− if(currentEventIndex === 0) {
206+ if (currentEventIndex === 0) {
207 restartProgram();
207 restartProgram();
@@ -232,31 +232,18 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
232 currentEventIndex = 0;
232 currentEventIndex = 0;
235− assert(index >= currentEventIndex, "index must be bad");
236 while (currentEventIndex < index) {
235 while (currentEventIndex < index) {
237 var nextEvent = debugModule.getRecordedEventAt(currentEventIndex);
236 var nextEvent = debugModule.getRecordedEventAt(currentEventIndex);
238 runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
237 runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
240 currentEventIndex += 1;
239 currentEventIndex += 1;
242− assert(currentEventIndex == index, "while loop didn't work");
245 function getMaxSteps() {
243 function getMaxSteps() {
246 return debugModule.getRecordedEventsLength();
244 return debugModule.getRecordedEventsLength();
249− function doPlayback(eventList) {
250− var x = eventList.shift();
252− runtime.notify(x[0], x[1], x[2]);
254− if (eventList.length > 0) {
255− var delta = eventList[0][2] - time;
256− setTimeout(function() { doPlayback(eventList); }, delta);
260 function redrawGraphics() {
247 function redrawGraphics() {
261 var main = debugModule.debuggedModule.main
248 var main = debugModule.debuggedModule.main
262 for (var i = main.kids.length ; i-- ; ) {
249 for (var i = main.kids.length ; i-- ; ) {
@@ -297,9 +284,7 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
297 debugModule.tracePath.stopRecording();
284 debugModule.tracePath.stopRecording();
299 stepTo(hotSwapState.currentEventIndex);
286 stepTo(hotSwapState.currentEventIndex);
300− if (paused) {
287+ if (!paused) {
301− debugModule.setPaused();
303 debugModule.setContinue(hotSwapState.currentEventIndex);
288 debugModule.setContinue(hotSwapState.currentEventIndex);
@@ -316,8 +301,7 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
316 getHotSwapState: getHotSwapState,
301 getHotSwapState: getHotSwapState,
317 dispose: dispose,
302 dispose: dispose,
318 allNodes: debugModule.signalGraphNodes,
303 allNodes: debugModule.signalGraphNodes,
319− watchTracker: debugModule.watchTracker,
304+ watchTracker: debugModule.watchTracker
320− signalGraphMain: debugModule.debuggedModule.main
323 return elmDebugger;
307 return elmDebugger;
@@ -446,7 +430,6 @@ function tracePathInit(runtime, signalGraphMain) {
450function executeCallbacks(callbacks, reexecute) {
433function executeCallbacks(callbacks, reexecute) {
451 callbacks.forEach(function(timer) {
434 callbacks.forEach(function(timer) {
452 if (reexecute || !timer.executed) {
435 if (reexecute || !timer.executed) {
@@ -484,7 +467,6 @@ function snapshotSignalGraph(signalGraphNodes) {
484 return nodeValues;
467 return nodeValues;
488function restoreSnapshot(signalGraphNodes, snapshot) {
470function restoreSnapshot(signalGraphNodes, snapshot) {
489 assert(signalGraphNodes.length == snapshot.length, "saved program state has wrong length");
471 assert(signalGraphNodes.length == snapshot.length, "saved program state has wrong length");
490 for (var i=0; i < signalGraphNodes.length; i++) {
472 for (var i=0; i < signalGraphNodes.length; i++) {