on master help sign in
Debugger: access recorded events.
commitb624ffa86258d0e09aeffc05b72081cd90e7e914 authorLaszlo Pandy <laszlo.pandy@prezi.com> dateTue 5 Nov 2013, 13:53 (13 years ago) parentecc6c14
1 file changed+18−12
runtime/Debugger.js+18−12
runtime/Debugger.js+18−12
@@ -27,7 +27,6 @@ Elm.debuggerAttach = function(module) {
2727function debugModule(module, runtime) {
2828 var programPaused = false;
2929 var recordedEvents = [];
30− var eventCounter = 0;
3130 var asyncCallbacks = [];
3231
3332 function wrapNotify(id, v) {
@@ -66,8 +65,12 @@ function debugModule(module, runtime) {
6665 recordedEvents = [];
6766 }
6867
69− function getRecordedEvents() {
70− return recordedEvents.slice();
68+ function getRecordedEventsLength() {
69+ return recordedEvents.length;
70+ }
71+
72+ function getRecordedEventAt(i) {
73+ return recordedEvents[i];
7174 }
7275
7376 function setPaused(v) {
@@ -99,18 +102,21 @@ function debugModule(module, runtime) {
99102 // API functions
100103 clearAsyncCallbacks: clearAsyncCallbacks,
101104 clearRecordedEvents: clearRecordedEvents,
102− getRecordedEvents: getRecordedEvents,
105+ getRecordedEventsLength: getRecordedEventsLength,
106+ getRecordedEventAt: getRecordedEventAt,
103107 getPaused: getPaused,
104− setPaused: setPaused
108+ setPaused: setPaused,
109+ tracePath: tracePathInit(runtime)
105110 };
106111}
107112
108113function debuggerInit(debugModule, runtime) {
109114 var Signal = Elm.Signal.make(runtime);
110115
111− var tracePath = tracePathInit(runtime);
112− var tracePathNode = A2(Signal.lift, tracePath.graphicsUpdate, debugModule.moduleInstance.main);
113− runtime.node.parentNode.appendChild(tracePath.canvas);
116+ var tracePathNode = A2(Signal.lift, debugModule.tracePath.graphicsUpdate, debugModule.moduleInstance.main);
117+ runtime.node.parentNode.appendChild(debugModule.tracePath.canvas);
118+
119+ var eventCounter = 0;
114120
115121 function resetProgram() {
116122 debugModule.clearAsyncCallbacks();
@@ -133,7 +139,7 @@ function debuggerInit(debugModule, runtime) {
133139 resetProgram();
134140 }
135141
136− if (index < 0 || index >= recordedEvents.length) {
142+ if (index < 0 || index > getMaxSteps()) {
137143 throw "Index out of bounds: " + index;
138144 }
139145
@@ -144,16 +150,16 @@ function debuggerInit(debugModule, runtime) {
144150
145151 assert(index >= eventCounter, "index must be bad");
146152 while (eventCounter < index) {
147− var nextEvent = recordedEvents[eventCounter];
153+ var nextEvent = debugModule.getRecordedEventAt(eventCounter);
148154 runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
149155
150156 eventCounter += 1;
151157 }
152− assert(eventCounter == index, "while loop didnt' work");
158+ assert(eventCounter == index, "while loop didn't work");
153159 }
154160
155161 function getMaxSteps() {
156− return recordedEvents.length - 1;
162+ return debugModule.getRecordedEventsLength() - 1;
157163 }
158164
159165 function doPlayback(eventList) {