Skip to content

Commit 3e85242

Browse files
author
Philip Guo
committed
subtle bug-fix so that variables can be named
'length' without causing the app to croak (thanks again to Peter Wentworth!)
1 parent d59e340 commit 3e85242

2 files changed

Lines changed: 13 additions & 54 deletions

File tree

‎TODO‎

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -141,54 +141,6 @@ else:
141141
the appropriate annotations would display when you stepped through the
142142
line of code immediately below each annotation.
143143

144-
---
145-
2011-05-23
146-
147-
Bug report from Peter Wentworth
148-
149-
'''
150-
Hi Philip
151-
152-
I hope you are keeping well!
153-
154-
Scripts fail in the visualizer when the user has a variable called
155-
“length”, because somehow the front-end jquery is doing something wrong.
156-
It happens both when used as a local or as a global variable. See my
157-
image of what is happening on your site. (Tried in both Firefox and
158-
Internet Explorer).
159-
160-
It looks like a jquery bug (I haven’t tried moving to a newer version –
161-
I’m using 1.3.2 that I got from your version).
162-
163-
The iterators + lambda functions appear to be misbehaving when varname
164-
has the value “length”. So I’ve had to rip out the iterators and gone
165-
for vanilla javascript loops, which has solved it for me.
166-
167-
I’ve done changes similar to this in 4 places in function updateOutput
168-
in file edu_python.js
169-
170-
171-
// $.each(curTrace[i].globals, function(varname, val) {
172-
// // eliminate duplicates (act as an ordered set)
173-
// if ($.inArray(varname, orderedGlobals) == -1) {
174-
// orderedGlobals.push(varname);
175-
// curGlobalFields[varname] = undefined; // 'unset it'
176-
// }
177-
// });
178-
179-
for (varname in curTrace[i].globals) {
180-
// eliminate duplicates (act as an ordered set)
181-
if ($.inArray(varname, orderedGlobals) == -1) {
182-
orderedGlobals.push(varname);
183-
curGlobalFields[varname] = undefined; // 'unset it'
184-
}
185-
}
186-
187-
Regards
188-
189-
Peter
190-
'''
191-
192144
---
193145
2011-09-15
194146

‎edu-python.js‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,12 @@ function updateOutput() {
232232

233233
// render locals in alphabetical order for tidiness:
234234
var orderedVarnames = [];
235-
$.each(localVars, function(varname, val) {
235+
236+
// use plain ole' iteration rather than jQuery $.each() since
237+
// the latter breaks when a variable is named "length"
238+
for (varname in localVars) {
236239
orderedVarnames.push(varname);
237-
});
240+
}
238241
orderedVarnames.sort();
239242

240243
if (orderedVarnames.length > 0) {
@@ -270,10 +273,12 @@ function updateOutput() {
270273
var nonEmptyGlobals = false;
271274
var curGlobalFields = {};
272275
if (curEntry.globals != undefined) {
273-
$.each(curEntry.globals, function(varname, val) {
276+
// use plain ole' iteration rather than jQuery $.each() since
277+
// the latter breaks when a variable is named "length"
278+
for (varname in curEntry.globals) {
274279
curGlobalFields[varname] = true;
275280
nonEmptyGlobals = true;
276-
});
281+
}
277282
}
278283

279284
if (nonEmptyGlobals) {
@@ -288,13 +293,15 @@ function updateOutput() {
288293
// some entries (like for exceptions) don't have GLOBALS
289294
if (curTrace[i].globals == undefined) continue;
290295

291-
$.each(curTrace[i].globals, function(varname, val) {
296+
// use plain ole' iteration rather than jQuery $.each() since
297+
// the latter breaks when a variable is named "length"
298+
for (varname in curTrace[i].globals) {
292299
// eliminate duplicates (act as an ordered set)
293300
if ($.inArray(varname, orderedGlobals) == -1) {
294301
orderedGlobals.push(varname);
295302
curGlobalFields[varname] = undefined; // 'unset it'
296303
}
297-
});
304+
}
298305

299306
var earlyStop = true;
300307
// as an optimization, STOP as soon as you've found everything in curGlobalFields:

0 commit comments

Comments
 (0)