@@ -27,7 +27,6 @@ Elm.debuggerAttach = function(module) {
27function debugModule(module, runtime) {
27function debugModule(module, runtime) {
28 var programPaused = false;
28 var programPaused = false;
29 var recordedEvents = [];
29 var recordedEvents = [];
30− var eventCounter = 0;
31 var asyncCallbacks = [];
30 var asyncCallbacks = [];
33 function wrapNotify(id, v) {
32 function wrapNotify(id, v) {
@@ -66,8 +65,12 @@ function debugModule(module, runtime) {
66 recordedEvents = [];
65 recordedEvents = [];
69− function getRecordedEvents() {
68+ function getRecordedEventsLength() {
70− return recordedEvents.slice();
69+ return recordedEvents.length;
72+ function getRecordedEventAt(i) {
73+ return recordedEvents[i];
73 function setPaused(v) {
76 function setPaused(v) {
@@ -99,18 +102,21 @@ function debugModule(module, runtime) {
99 // API functions
102 // API functions
100 clearAsyncCallbacks: clearAsyncCallbacks,
103 clearAsyncCallbacks: clearAsyncCallbacks,
101 clearRecordedEvents: clearRecordedEvents,
104 clearRecordedEvents: clearRecordedEvents,
102− getRecordedEvents: getRecordedEvents,
105+ getRecordedEventsLength: getRecordedEventsLength,
106+ getRecordedEventAt: getRecordedEventAt,
103 getPaused: getPaused,
107 getPaused: getPaused,
104− setPaused: setPaused
108+ setPaused: setPaused,
109+ tracePath: tracePathInit(runtime)
108function debuggerInit(debugModule, runtime) {
113function debuggerInit(debugModule, runtime) {
109 var Signal = Elm.Signal.make(runtime);
114 var Signal = Elm.Signal.make(runtime);
111− var tracePath = tracePathInit(runtime);
112− var tracePathNode = A2(Signal.lift, tracePath.graphicsUpdate, debugModule.moduleInstance.main);
116+ var tracePathNode = A2(Signal.lift, debugModule.tracePath.graphicsUpdate, debugModule.moduleInstance.main);
113− runtime.node.parentNode.appendChild(tracePath.canvas);
117+ runtime.node.parentNode.appendChild(debugModule.tracePath.canvas);
119+ var eventCounter = 0;
115 function resetProgram() {
121 function resetProgram() {
116 debugModule.clearAsyncCallbacks();
122 debugModule.clearAsyncCallbacks();
@@ -133,7 +139,7 @@ function debuggerInit(debugModule, runtime) {
133 resetProgram();
139 resetProgram();
136− if (index < 0 || index >= recordedEvents.length) {
142+ if (index < 0 || index > getMaxSteps()) {
137 throw "Index out of bounds: " + index;
143 throw "Index out of bounds: " + index;
@@ -144,16 +150,16 @@ function debuggerInit(debugModule, runtime) {
145 assert(index >= eventCounter, "index must be bad");
151 assert(index >= eventCounter, "index must be bad");
146 while (eventCounter < index) {
152 while (eventCounter < index) {
147− var nextEvent = recordedEvents[eventCounter];
153+ var nextEvent = debugModule.getRecordedEventAt(eventCounter);
148 runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
154 runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
150 eventCounter += 1;
156 eventCounter += 1;
152− assert(eventCounter == index, "while loop didnt' work");
158+ assert(eventCounter == index, "while loop didn't work");
155 function getMaxSteps() {
161 function getMaxSteps() {
156− return recordedEvents.length - 1;
162+ return debugModule.getRecordedEventsLength() - 1;
159 function doPlayback(eventList) {
165 function doPlayback(eventList) {