on master help sign in
Debugger: access recorded events.
b624ffaLaszlo Pandy
runtime/Debugger.js+18−12
@@ -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 = [];
32
31
33 function wrapNotify(id, v) {
32 function wrapNotify(id, v) {
@@ -66,8 +65,12 @@ function debugModule(module, runtime) {
66 recordedEvents = [];
65 recordedEvents = [];
67 }
66 }
68
67
69− function getRecordedEvents() {
68+ function getRecordedEventsLength() {
70− return recordedEvents.slice();
69+ return recordedEvents.length;
70+ }
71+
72+ function getRecordedEventAt(i) {
73+ return recordedEvents[i];
71 }
74 }
72
75
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)
105 };
110 };
106}
111}
107
112
108function debuggerInit(debugModule, runtime) {
113function debuggerInit(debugModule, runtime) {
109 var Signal = Elm.Signal.make(runtime);
114 var Signal = Elm.Signal.make(runtime);
110
115
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);
118+
119+ var eventCounter = 0;
114
120
115 function resetProgram() {
121 function resetProgram() {
116 debugModule.clearAsyncCallbacks();
122 debugModule.clearAsyncCallbacks();
@@ -133,7 +139,7 @@ function debuggerInit(debugModule, runtime) {
133 resetProgram();
139 resetProgram();
134 }
140 }
135
141
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;
138 }
144 }
139
145
@@ -144,16 +150,16 @@ function debuggerInit(debugModule, runtime) {
144
150
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);
149
155
150 eventCounter += 1;
156 eventCounter += 1;
151 }
157 }
152− assert(eventCounter == index, "while loop didnt' work");
158+ assert(eventCounter == index, "while loop didn't work");
153 }
159 }
154
160
155 function getMaxSteps() {
161 function getMaxSteps() {
156− return recordedEvents.length - 1;
162+ return debugModule.getRecordedEventsLength() - 1;
157 }
163 }
158
164
159 function doPlayback(eventList) {
165 function doPlayback(eventList) {