Skip to content

Commit 6214736

Browse files
committed
print out all attributes for functions
1 parent 3f58f1f commit 6214736

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

‎v4-cokapi/backends/javascript/jslogger.js‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ function encodeObject(o) {
247247
var i;
248248

249249
if (_.isFunction(o)) {
250+
var funcProperties = []; // each element is a pair of [name, encoded value]
251+
250252
var encodedProto = null;
251253
if (_.isObject(o.prototype)) {
252254
// TRICKY TRICKY! for inheritance to be displayed properly, we
@@ -261,10 +263,23 @@ function encodeObject(o) {
261263
encodedProto = encodeObject(o.prototype);
262264
}
263265
}
266+
267+
if (encodedProto) {
268+
funcProperties.push(['prototype', encodedProto]);
269+
}
270+
271+
// now get all of the normal properties out of this function
272+
// object (it's unusual to put properties in a function object,
273+
// but it's still legal!)
274+
var funcPropPairs = _.pairs(o);
275+
for (i = 0; i < funcPropPairs.length; i++) {
276+
funcProperties.push([funcPropPairs[i][0], encodeObject(funcPropPairs[i][1])]);
277+
}
278+
264279
newEncodedObj.push('JS_FUNCTION',
265280
o.name,
266281
o.toString() /* code string*/,
267-
encodedProto,
282+
funcProperties,
268283
null /* parent frame */);
269284
} else if (_.isArray(o)) {
270285
newEncodedObj.push('LIST');

‎v4-cokapi/frontends/js/pytutor.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,21 +3418,23 @@ function(objID, stepNum, d3DomElement, isTopLevel) {
34183418
assert(obj.length == 5);
34193419
var funcName = htmlspecialchars(obj[1]);
34203420
var funcCode = htmlspecialchars(obj[2]);
3421-
var prototype = obj[3];
3421+
var funcProperties = obj[3]; // a (possibly-empty) list of key-value pairs
34223422
var parentFrameID = obj[4];
34233423

34243424

3425-
if (prototype || parentFrameID || myViz.showAllFrameLabels) {
3425+
if (funcProperties.length > 0 || parentFrameID || myViz.showAllFrameLabels) {
34263426
d3DomElement.append('<table class="classTbl"></table>');
34273427
var tbl = d3DomElement.children('table');
34283428
tbl.append('<tr><td class="funcCod" colspan="2"><pre class="funcCode">' + funcCode + '</pre>' + '</td></tr>');
34293429

3430-
if (prototype) {
3431-
tbl.append('<tr class="classEntry"><td class="classKey">prototype</td><td class="classVal"></td></tr>');
3432-
var newRow = tbl.find('tr:last');
3433-
var valTd = newRow.find('td:last');
3434-
myViz.renderNestedObject(prototype, stepNum, valTd);
3435-
}
3430+
$.each(funcProperties, function(ind, kvPair) {
3431+
tbl.append('<tr class="classEntry"><td class="classKey"></td><td class="classVal"></td></tr>');
3432+
var newRow = tbl.find('tr:last');
3433+
var keyTd = newRow.find('td:first');
3434+
var valTd = newRow.find('td:last');
3435+
keyTd.append('<span class="keyObj">' + htmlspecialchars(kvPair[0]) + '</span>');
3436+
myViz.renderNestedObject(kvPair[1], stepNum, valTd);
3437+
});
34363438

34373439
if (parentFrameID) {
34383440
tbl.append('<tr class="classEntry"><td class="classKey">parent</td><td class="classVal">' + 'f' + parentFrameID + '</td></tr>');

0 commit comments

Comments
 (0)