Skip to content

Commit 4f0094d

Browse files
committed
added some JS-specific visualizer hacks
W
1 parent 5459fb5 commit 4f0094d

2 files changed

Lines changed: 52 additions & 6 deletions

File tree

‎v3/css/pytutor.css‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ div.ExecutionVisualizer .funcObj {
236236
white-space: nowrap;
237237
}
238238

239+
div.ExecutionVisualizer .funcCode {
240+
font-size: 8pt;
241+
}
242+
239243
div.ExecutionVisualizer .retval {
240244
font-size: 9pt;
241245
}
@@ -333,7 +337,8 @@ div.ExecutionVisualizer table.classTbl td.classKey {
333337

334338
div.ExecutionVisualizer table.dictTbl td.dictVal,
335339
div.ExecutionVisualizer table.instTbl td.instVal,
336-
div.ExecutionVisualizer table.classTbl td.classVal {
340+
div.ExecutionVisualizer table.classTbl td.classVal,
341+
div.ExecutionVisualizer td.funcCod {
337342
background-color: #ffffc6;
338343
}
339344

@@ -358,6 +363,9 @@ div.ExecutionVisualizer table.classTbl td.classVal {
358363
padding-left: 4px;
359364
}
360365

366+
div.ExecutionVisualizer td.funcCod {
367+
padding-left: 4px;
368+
}
361369

362370
div.ExecutionVisualizer table.classTbl td,
363371
div.ExecutionVisualizer table.instTbl td {
@@ -369,7 +377,8 @@ div.ExecutionVisualizer table.instTbl td.instVal {
369377
border-left: 1px #888 solid;
370378
}
371379

372-
div.ExecutionVisualizer table.classTbl {
380+
div.ExecutionVisualizer table.classTbl,
381+
div.ExecutionVisualizer table.funcTbl {
373382
border-collapse: collapse;
374383
border: 1px #888 solid;
375384
}

‎v3/js/pytutor.js‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,7 +3114,7 @@ ExecutionVisualizer.prototype.renderPrimitiveObject = function(obj, d3DomElement
31143114
d3DomElement.append('<span class="stringObj">' + literalStr + '</span>');
31153115
}
31163116
else if (typ == "object") {
3117-
assert(obj[0] == 'SPECIAL_FLOAT');
3117+
assert(obj[0] == 'SPECIAL_FLOAT' || obj[0] == 'JS_SPECIAL_VAL');
31183118
d3DomElement.append('<span class="numberObj">' + obj[1] + '</span>');
31193119
}
31203120
else {
@@ -3402,6 +3402,39 @@ function(objID, stepNum, d3DomElement, isTopLevel) {
34023402
d3DomElement.append('<div class="funcObj">' + funcPrefix + ' ' + funcName + '</div>');
34033403
}
34043404
}
3405+
else if (obj[0] == 'JS_FUNCTION') { /* TODO: refactor me */
3406+
// JavaScript function
3407+
assert(obj.length == 5);
3408+
var funcName = htmlspecialchars(obj[1]);
3409+
var funcCode = htmlspecialchars(obj[2]);
3410+
var prototype = obj[3];
3411+
var parentFrameID = obj[4];
3412+
3413+
3414+
if (prototype || parentFrameID || myViz.showAllFrameLabels) {
3415+
d3DomElement.append('<table class="classTbl"></table>');
3416+
var tbl = d3DomElement.children('table');
3417+
tbl.append('<tr><td class="funcCod" colspan="2"><pre class="funcCode">' + funcCode + '</pre>' + '</td></tr>');
3418+
3419+
if (prototype) {
3420+
tbl.append('<tr class="classEntry"><td class="classKey">prototype</td><td class="classVal"></td></tr>');
3421+
var newRow = tbl.find('tr:last');
3422+
var valTd = newRow.find('td:last');
3423+
myViz.renderNestedObject(prototype, stepNum, valTd);
3424+
}
3425+
3426+
if (parentFrameID) {
3427+
tbl.append('<tr class="classEntry"><td class="classKey">parent</td><td class="classVal">' + 'f' + parentFrameID + '</td></tr>');
3428+
}
3429+
else if (myViz.showAllFrameLabels) {
3430+
tbl.append('<tr class="classEntry"><td class="classKey">parent</td><td class="classVal">' + 'global' + '</td></tr>');
3431+
}
3432+
}
3433+
else {
3434+
// compact form:
3435+
d3DomElement.append('<pre class="funcCode">' + funcCode + '</pre>');
3436+
}
3437+
}
34053438
else if (obj[0] == 'HEAP_PRIMITIVE') {
34063439
assert(obj.length == 3);
34073440

@@ -3526,7 +3559,11 @@ var rbRE = new RegExp('\\]|}|\\)|>', 'g');
35263559
function varnameToCssID(varname) {
35273560
// make sure to REPLACE ALL (using the 'g' option)
35283561
// rather than just replacing the first entry
3529-
return varname.replace(lbRE, 'LeftB_').replace(rbRE, '_RightB').replace(/[.]/g, '_DOT_').replace(/ /g, '_');
3562+
return varname.replace(lbRE, 'LeftB_')
3563+
.replace(rbRE, '_RightB')
3564+
.replace(/[:]/g, '_COLON_')
3565+
.replace(/[.]/g, '_DOT_')
3566+
.replace(/ /g, '_');
35303567
}
35313568

35323569

@@ -3587,13 +3624,13 @@ function isPrimitiveType(obj) {
35873624
if (hook_result[0]) return hook_result[1];
35883625

35893626
// null is a primitive
3590-
if (obj == null) {
3627+
if (obj === null) {
35913628
return true;
35923629
}
35933630

35943631
if (typeof obj == "object") {
35953632
// kludge: only 'SPECIAL_FLOAT' objects count as primitives
3596-
return (obj[0] == 'SPECIAL_FLOAT');
3633+
return (obj[0] == 'SPECIAL_FLOAT' || obj[0] == 'JS_SPECIAL_VAL');
35973634
}
35983635
else {
35993636
// non-objects are primitives

0 commit comments

Comments
 (0)