@@ -19,8 +19,12 @@ Elm.debuggerRestart = function() {
1919 staticDebugger.restart();
2020};
2121
22−Elm.debuggerStep = function() {
23− staticDebugger.step();
22+Elm.debuggerGetMaxSteps = function() {
23+ return staticDebugger.getMaxSteps();
24+};
25+
26+Elm.debuggerStepTo = function(index) {
27+ staticDebugger.stepTo(index);
2428};
2529
2630function debuggerInit(module, elm) {
@@ -29,6 +33,7 @@ function debuggerInit(module, elm) {
2933 var allNodes = null;
3034
3135 var recordedEvents = [];
36+ var eventCounter = 0;
3237 var asyncTimers = [];
3338 var initialProgramState = {
3439 nodeValues: [],
@@ -76,18 +81,33 @@ function debuggerInit(module, elm) {
7681 });
7782 }
7883
79− function stepRecording() {
80− if (programPaused) {
81− if (recordedEvents.length > 0) {
82− var nextEvent = recordedEvents.shift();
83− elm.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
84− }
85− }
86− else {
87− // move into stepping mode
84+ function gotoStep(index) {
85+ if (!programPaused) {
8886 programPaused = true;
8987 resetProgram();
9088 }
89+
90+ if (index < 0 || index >= recordedEvents.length) {
91+ throw "Index out of bounds: " + index;
92+ }
93+
94+ if (index < eventCounter) {
95+ resetProgram();
96+ eventCounter = 0;
97+ }
98+
99+ assert(index >= eventCounter, "index must be bad");
100+ while (eventCounter < index) {
101+ var nextEvent = recordedEvents[eventCounter];
102+ elm.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
103+
104+ eventCounter += 1;
105+ }
106+ assert(eventCounter == index, "while loop didnt' work");
107+ }
108+
109+ function getMaxSteps() {
110+ return recordedEvents.length - 1;
91111 }
92112
93113 function clearAsyncEvents() {
@@ -130,7 +150,8 @@ function debuggerInit(module, elm) {
130150 // debugger functions
131151 reset: resetProgram,
132152 restart: restartProgram,
133− step: stepRecording
153+ getMaxSteps: getMaxSteps,
154+ stepTo: gotoStep
134155 };
135156
136157 allNodes = flattenNodes(wrappedElm.inputs);