Skip to content

Commit 4f54459

Browse files
committed
mostly works, kinda
1 parent fb1c407 commit 4f54459

5 files changed

Lines changed: 254 additions & 288 deletions

File tree

‎v5-unity/iframe-embed.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<body>
1515

1616
<div id="vizDiv"></div>
17+
<div id="frontendErrorOutput"></div>
1718

1819
</body>
1920
</html>

‎v5-unity/js/cruft/shared-sessions.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
// maybe put into a separate codechella module?
33
/*
44
5+
6+
// return whether two states match, except don't worry about curInstr
7+
/*
8+
static appStateEq(s1, s2) {
9+
assert(s1.origin == s2.origin); // sanity check!
10+
11+
return (s1.code == s2.code &&
12+
s1.mode == s2.mode &&
13+
s1.cumulative == s2.cumulative &&
14+
s1.heapPrimitives == s1.heapPrimitives &&
15+
s1.textReferences == s2.textReferences &&
16+
s1.py == s2.py &&
17+
s1.rawInputLstJSON == s2.rawInputLstJSON);
18+
}
19+
*/
20+
21+
522
// grab this as early as possible before TogetherJS munges the URL
623
var togetherjsInUrl = ($.bbq.getState('togetherjs') !== undefined);
724

‎v5-unity/js/iframe-embed.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,8 @@ class IframeEmbedFrontend extends AbstractBaseFrontend {
9292
this.myVisualizer.redrawConnectors();
9393
}
9494

95-
handleUncaughtExceptionFunc(trace) {
96-
var excMsg = null;
97-
if (trace.length == 1) {
98-
excMsg = trace[0].exception_msg; // killer!
99-
} else if (trace.length > 0 && trace[trace.length - 1].exception_msg) {
100-
excMsg = trace[trace.length - 1].exception_msg;
101-
} else {
102-
excMsg = "Unknown error. Reload the page and try again. Or report a bug to philip@pgbovine.net";
103-
}
104-
$("#vizDiv").html(pytutor.htmlspecialchars(excMsg));
95+
handleUncaughtException(trace) {
96+
// NOP
10597
}
10698

10799
// David Pritchard's code for resizeContainer option ...

‎v5-unity/js/opt-frontend-common.ts‎

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,15 @@ const langSettingToJsonpEndpoint = {
8181

8282

8383
// for shared sessions ... put back in later
84-
var executeCodeSignalFromRemote = false;
85-
var togetherjsSyncRequested = false;
84+
//var executeCodeSignalFromRemote = false;
85+
//var togetherjsSyncRequested = false;
8686

8787

8888
// the main event!
8989
//
9090
// NB: this still relies on global state such as localStorage and the
91-
// browser URL hash string, so you can't quite have more than one
92-
// of these objects per page; it still should be instantiated as a singleton
93-
//
94-
// this should also be treated like an Abstract Base Class
91+
// browser URL hash string, so you still can't have more than one of these
92+
// objects per page; should still be instantiated as a SINGLETON
9593
export abstract class AbstractBaseFrontend {
9694
sessionUUID: string = generateUUID(); // remains constant throughout one page load ("session")
9795

@@ -116,7 +114,7 @@ export abstract class AbstractBaseFrontend {
116114

117115
abstract executeCode(forceStartingInstr?: number, forceRawInputLst?: string[]) : any;
118116
abstract finishSuccessfulExecution() : any;
119-
abstract handleUncaughtExceptionFunc(trace: any[]) : any;
117+
abstract handleUncaughtException(trace: any[]) : any;
120118

121119
constructor(params: any = {}) {
122120
// optional params -- TODO: handle later
@@ -132,6 +130,17 @@ export abstract class AbstractBaseFrontend {
132130
}
133131
*/
134132

133+
if (supports_html5_storage()) {
134+
// generate a unique UUID per "user" (as indicated by a single browser
135+
// instance on a user's machine, which can be more precise than IP
136+
// addresses due to sharing of IP addresses within, say, a school
137+
// computer lab)
138+
// added on 2015-01-27 for more precise user identification
139+
if (!localStorage.getItem('opt_uuid')) {
140+
localStorage.setItem('opt_uuid', generateUUID());
141+
}
142+
}
143+
135144
// register a generic AJAX error handler
136145
$(document).ajaxError(function(evt, jqxhr, settings, exception) {
137146
// ignore errors related to togetherjs stuff:
@@ -172,7 +181,6 @@ export abstract class AbstractBaseFrontend {
172181
// message and give up.
173182
if (this.num414Tries === 0) {
174183
this.num414Tries++;
175-
this.startExecutingCode(); // TODO: does this work?
176184
$("#executeBtn").click();
177185
} else {
178186
this.num414Tries = 0;
@@ -188,15 +196,14 @@ export abstract class AbstractBaseFrontend {
188196
});
189197

190198
this.clearFrontendError();
191-
192199
$("#embedLinkDiv").hide();
193-
$("#executeBtn").attr('disabled', false);
194-
$("#executeBtn").click(this.executeCodeFromScratch.bind(this));
195-
200+
$("#executeBtn")
201+
.attr('disabled', false)
202+
.click(this.executeCodeFromScratch.bind(this));
196203
}
197204

198205
// empty stub so that our code doesn't crash.
199-
// override this with a version in codeopticon-learner.js if needed
206+
// TODO: override this with a version in codeopticon-learner.js if needed
200207
logEventCodeopticon(obj) { } // NOP
201208

202209
setFronendError(lines) {
@@ -293,27 +300,22 @@ export abstract class AbstractBaseFrontend {
293300
assert(backendScript);
294301
var jsonp_endpoint = langSettingToJsonpEndpoint[pyState]; // maybe null
295302

296-
var _me = this;
297-
298303
var execCallback = (dataFromBackend) => {
299304
var trace = dataFromBackend.trace;
300305
var killerException = null;
301306
// don't enter visualize mode if there are killer errors:
302307
if (!trace ||
303308
(trace.length == 0) ||
304309
(trace[trace.length - 1].event == 'uncaught_exception')) {
305-
306-
this.handleUncaughtExceptionFunc(trace);
310+
this.handleUncaughtException(trace);
307311

308312
if (trace.length == 1) {
309313
killerException = trace[0]; // killer!
310314
this.setFronendError([trace[0].exception_msg]);
311-
}
312-
else if (trace.length > 0 && trace[trace.length - 1].exception_msg) {
315+
} else if (trace.length > 0 && trace[trace.length - 1].exception_msg) {
313316
killerException = trace[trace.length - 1]; // killer!
314317
this.setFronendError([trace[trace.length - 1].exception_msg]);
315-
}
316-
else {
318+
} else {
317319
this.setFronendError(
318320
["Unknown error. Reload the page and try again. Or report a bug to",
319321
"philip@pgbovine.net by clicking on the 'Generate permanent link'",
@@ -334,7 +336,7 @@ export abstract class AbstractBaseFrontend {
334336
// SUPER HACK -- slip in backendOptionsObj as an extra field
335337
// NB: why do we do this? for more detailed logging?
336338
this.myVisualizer.backendOptionsObj = backendOptionsObj;
337-
this.finishSuccessfulExecution(); // TODO: should we do this even if we're calling runTestCaseCallback?
339+
this.finishSuccessfulExecution(); // TODO: should we also run this if we're calling runTestCaseCallback?
338340
}
339341

340342
// VERY SUBTLE -- reinitialize TogetherJS so that it can detect
@@ -344,10 +346,11 @@ export abstract class AbstractBaseFrontend {
344346
}
345347
}
346348

347-
this.doneExecutingCode(); // rain or shine, we're done executing!
348349
// run this at the VERY END after all the dust has settled
350+
this.doneExecutingCode(); // rain or shine, we're done executing!
349351

350-
// do logging at the VERY END after the dust settles ...
352+
// do logging at the VERY END after the dust settles ... maybe
353+
// move into opt-frontend.js?
351354
// and don't do it for iframe-embed.js since getAppState doesn't
352355
// work in that case ...
353356
/*
@@ -405,6 +408,7 @@ export abstract class AbstractBaseFrontend {
405408
}
406409

407410
// if we don't have any deltas, then don't bother sending deltaObj:
411+
// NB: not all subclasses will initialize this.deltaObj
408412
var deltaObjStringified = (this.deltaObj && (this.deltaObj.deltas.length > 0)) ? JSON.stringify(this.deltaObj) : null;
409413
if (deltaObjStringified) {
410414
// if deltaObjStringified is too long, then that will likely make
@@ -444,7 +448,7 @@ export abstract class AbstractBaseFrontend {
444448
success: execCallback.bind(this) /* tricky! */,
445449
});
446450
} else {
447-
// Python 2 or 3
451+
// for Python 2 or 3, directly execute backendScript
448452
assert (pyState === '2' || pyState === '3');
449453
$.get(backendScript,
450454
{user_script : codeToExec,

0 commit comments

Comments
 (0)