I did something similar for my bachelor thesis. (I would share the thesis but since it's German i don't assume it would be of much help). There i generated PHP from Blocks, started it and then wanted to enable the user to step through the generated code block by block. The following isn't specific for Javascript so you might have to change some bits and pieces. Lets say the generated code looks similar to this:
codeGeneratedByFirstBlock();
codeGeneratedBySecondBlock();
codeGeneratedByThirdBlock();
My simple solution for tracking which Block is the actual block executed is to let My PHP codeGenerator generate slightly different code, when generating code for debugging:
setActualBlock(<idOfFirstBlock>);
codeGeneratedByFirstBlock();
setActualBlock(<idOfSecondBlock>)
codeGeneratedBySecondBlock();
setActualBlock(<idOfThirdBlock>)
codeGeneratedByThirdBlock();
The trick is, that the codeGenerator knows the id of the block it's generating code for. So let the Generator put this knowledge right in the code it's generating.
So when some of the codeGeneratedBy..Block() functions throws an exception, you would now know which block it corresponds to because you saved the lasts blocks id before. You might have to wrap codeGeneratedBy..Block() in a function, that catches Exceptions, continues normally when there is no exception but highlights the actual block when there is one.
There are some caveats anyway: This is good if you don't care about changing the generated code for debugging. That means the code isn't shown to the user or you don't care for the code to be "educational". There could also be problems when you have multi threaded code or callback code. When the callback is executed, you might have already called setActualBlockId() with another id that doesn't correspond to the block that generated the callback code.