Skip to content

Commit 37816be

Browse files
committed
patching up java backend limitations
1 parent 70c2a28 commit 37816be

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎v3/js/pytutor.js‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4583,13 +4583,22 @@ function closeModal(divId) {
45834583
// All of the Java frontend code in this function was written by David
45844584
// Pritchard and Will Gwozdz, and integrated by Philip Guo
45854585
ExecutionVisualizer.prototype.activateJavaFrontend = function() {
4586-
// super hack by Philip that reverses the direction of the stack so
4587-
// that it grows DOWN and renders the same way as the Python and JS
4588-
// visualizer stacks
4586+
var prevLine = null;
45894587
this.curTrace.forEach(function(e, i) {
4588+
// ugh the Java backend doesn't attach line numbers to exception
4589+
// events, so just take the previous line number as our best guess
4590+
if (e.event === 'exception' && !e.line) {
4591+
e.line = prevLine;
4592+
}
4593+
4594+
// super hack by Philip that reverses the direction of the stack so
4595+
// that it grows DOWN and renders the same way as the Python and JS
4596+
// visualizer stacks
45904597
if (e.stack_to_render !== undefined) {
45914598
e.stack_to_render.reverse();
45924599
}
4600+
4601+
prevLine = e.line;
45934602
});
45944603

45954604
this.add_pytutor_hook(

‎v5-unity/js/pytutor.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ export class ExecutionVisualizer {
216216
this.domRootD3 = tmpRootD3.select('div.ExecutionVisualizer');
217217

218218
if (this.params.lang === 'java') {
219-
this.activateJavaFrontend(); // ohhhh yeah!
219+
this.activateJavaFrontend(); // ohhhh yeah! do this before initializing codeOutputLines (ugh order dependency)
220220
}
221221

222+
222223
var lines = this.curInputCode.split('\n');
223224
for (var i = 0; i < lines.length; i++) {
224225
var cod = lines[i];
@@ -710,13 +711,22 @@ export class ExecutionVisualizer {
710711
// All of the Java frontend code in this function was written by David
711712
// Pritchard and Will Gwozdz, and integrated into pytutor.js by Philip Guo
712713
activateJavaFrontend() {
713-
// super hack by Philip that reverses the direction of the stack so
714-
// that it grows DOWN and renders the same way as the Python and JS
715-
// visualizer stacks
716-
this.curTrace.forEach(function(e, i) {
714+
var prevLine = null;
715+
this.curTrace.forEach((e, i) => {
716+
// ugh the Java backend doesn't attach line numbers to exception
717+
// events, so just take the previous line number as our best guess
718+
if (e.event === 'exception' && !e.line) {
719+
e.line = prevLine;
720+
}
721+
722+
// super hack by Philip that reverses the direction of the stack so
723+
// that it grows DOWN and renders the same way as the Python and JS
724+
// visualizer stacks
717725
if (e.stack_to_render !== undefined) {
718726
e.stack_to_render.reverse();
719727
}
728+
729+
prevLine = e.line;
720730
});
721731

722732
this.add_pytutor_hook(

0 commit comments

Comments
 (0)