Skip to content

Commit 835c625

Browse files
committed
yay handled error objects!
1 parent 630e3b9 commit 835c625

6 files changed

Lines changed: 118 additions & 35 deletions

File tree

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ function listener(event, execState, eventData, data) {
437437
curTraceEntry.event = logEventType;
438438
curTraceEntry.heap = getHeap();
439439

440+
// inspect only the top "global" frame to grab globals
440441
for (ii = 0; ii < topFrame.scopeCount(); ii++) {
441442
sc = topFrame.scope(ii);
442443
// According to https://code.google.com/p/v8-wiki/wiki/DebuggerProtocol
@@ -447,7 +448,7 @@ function listener(event, execState, eventData, data) {
447448
// 3: Closure
448449
// 4: Catch
449450
scopeType = sc.details_.details_[0];
450-
if (scopeType === 0) { // Global
451+
if (scopeType === 0) { // Global -- to handle global variables
451452
scopeObj = sc.details_.details_[1];
452453
var globalScopePairs = _.pairs(scopeObj);
453454
for (jj = 0; jj < globalScopePairs.length; jj++) {
@@ -460,6 +461,18 @@ function listener(event, execState, eventData, data) {
460461
}
461462
}
462463
}
464+
else if (scopeType === 4) { // Catch -- to handle global exception blocks
465+
scopeObj = sc.details_.details_[1];
466+
467+
var globalCatchScopePairs = _.pairs(scopeObj);
468+
for (jj = 0; jj < globalCatchScopePairs.length; jj++) {
469+
var globalCatchVarname = globalCatchScopePairs[jj][0];
470+
var globalCatchVal = globalCatchScopePairs[jj][1];
471+
curTraceEntry.ordered_globals.push(globalCatchVarname);
472+
assert(!_.has(curTraceEntry.globals, globalCatchVarname));
473+
curTraceEntry.globals[globalCatchVarname] = encodeObject(globalCatchVal);
474+
}
475+
}
463476
}
464477

465478
for (i = 0;
@@ -575,7 +588,8 @@ function listener(event, execState, eventData, data) {
575588
// 4: Catch
576589
scopeType = sc.details_.details_[0];
577590
var e;
578-
if (scopeType === 1) { // Local
591+
// DON'T grab globals again since it's redundant
592+
if (scopeType === 1 || scopeType === 4) { // Local or Catch (for exceptions)
579593
// encode local variables
580594

581595
scopeObj = sc.details_.details_[1];
@@ -587,7 +601,7 @@ function listener(event, execState, eventData, data) {
587601
assert(!_.has(traceStackEntry.encoded_locals, e[0]));
588602
traceStackEntry.encoded_locals[e[0]] = encodeObject(e[1]);
589603
}
590-
} else if (scopeType !== 0 && scopeType !== 1) { // With, Closure, Catch
604+
} else if (scopeType === 2 || scopeType === 3) { // With, Closure
591605
// poor person's closure display ... simply INLINE closure
592606
// variables into this frame, since that's what v8 provides us.
593607
// not as great as drawing real environment diagrams, but
@@ -612,6 +626,8 @@ function listener(event, execState, eventData, data) {
612626
}
613627

614628
nParentScopes++;
629+
} else {
630+
assert(scopeType === 0);
615631
}
616632
}
617633

‎v4-cokapi/backends/javascript/tests/caught-exception.golden‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131
{ stdout: '',
3232
func_name: '',
3333
stack_to_render: [],
34-
globals: { x: 5 },
35-
ordered_globals: [ 'x' ],
34+
globals: { e: [ 'REF', 1 ], x: 5 },
35+
ordered_globals: [ 'e', 'x' ],
3636
line: 6,
3737
col: 2,
3838
event: 'step_line',
39-
heap: {} },
39+
heap: { '1': [ 'INSTANCE', '' ] } },
4040
{ stdout: 'hello\n',
4141
func_name: '',
4242
stack_to_render: [],
43-
globals: { x: 5 },
44-
ordered_globals: [ 'x' ],
43+
globals: { e: [ 'REF', 1 ], x: 5 },
44+
ordered_globals: [ 'e', 'x' ],
4545
line: 7,
4646
col: 2,
4747
event: 'step_line',
48-
heap: {} },
48+
heap: { '1': [ 'INSTANCE', '' ] } },
4949
{ stdout: 'hello\ncaught\n',
5050
func_name: '',
5151
stack_to_render: [],

‎v4-cokapi/backends/javascript/tests/eloquentjs-8.1.golden‎

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,17 @@
444444
is_zombie: false,
445445
parent_frame_id_list: [],
446446
unique_hash: 'reliableMultiply_f2',
447-
ordered_varnames: [ 'parent:e', 'a', 'b' ],
448-
encoded_locals: { 'parent:e': [ 'REF', 4 ], a: 8, b: 8 } } ],
447+
ordered_varnames: [ 'e', 'a', 'b' ],
448+
encoded_locals: { e: [ 'REF', 4 ], a: 8, b: 8 } } ],
449449
globals:
450-
{ nTimes: 1,
450+
{ e: [ 'REF', 4 ],
451+
nTimes: 1,
451452
MultiplicatorUnitFailure: [ 'REF', 1 ],
452453
primitiveMultiply: [ 'REF', 2 ],
453454
reliableMultiply: [ 'REF', 3 ] },
454455
ordered_globals:
455-
[ 'nTimes',
456+
[ 'e',
457+
'nTimes',
456458
'MultiplicatorUnitFailure',
457459
'primitiveMultiply',
458460
'reliableMultiply' ],
@@ -853,15 +855,17 @@
853855
is_zombie: false,
854856
parent_frame_id_list: [],
855857
unique_hash: 'reliableMultiply_f2',
856-
ordered_varnames: [ 'parent:e', 'a', 'b' ],
857-
encoded_locals: { 'parent:e': [ 'REF', 5 ], a: 8, b: 8 } } ],
858+
ordered_varnames: [ 'e', 'a', 'b' ],
859+
encoded_locals: { e: [ 'REF', 5 ], a: 8, b: 8 } } ],
858860
globals:
859-
{ nTimes: 2,
861+
{ e: [ 'REF', 5 ],
862+
nTimes: 2,
860863
MultiplicatorUnitFailure: [ 'REF', 1 ],
861864
primitiveMultiply: [ 'REF', 2 ],
862865
reliableMultiply: [ 'REF', 3 ] },
863866
ordered_globals:
864-
[ 'nTimes',
867+
[ 'e',
868+
'nTimes',
865869
'MultiplicatorUnitFailure',
866870
'primitiveMultiply',
867871
'reliableMultiply' ],
@@ -1262,15 +1266,17 @@
12621266
is_zombie: false,
12631267
parent_frame_id_list: [],
12641268
unique_hash: 'reliableMultiply_f2',
1265-
ordered_varnames: [ 'parent:e', 'a', 'b' ],
1266-
encoded_locals: { 'parent:e': [ 'REF', 6 ], a: 8, b: 8 } } ],
1269+
ordered_varnames: [ 'e', 'a', 'b' ],
1270+
encoded_locals: { e: [ 'REF', 6 ], a: 8, b: 8 } } ],
12671271
globals:
1268-
{ nTimes: 3,
1272+
{ e: [ 'REF', 6 ],
1273+
nTimes: 3,
12691274
MultiplicatorUnitFailure: [ 'REF', 1 ],
12701275
primitiveMultiply: [ 'REF', 2 ],
12711276
reliableMultiply: [ 'REF', 3 ] },
12721277
ordered_globals:
1273-
[ 'nTimes',
1278+
[ 'e',
1279+
'nTimes',
12741280
'MultiplicatorUnitFailure',
12751281
'primitiveMultiply',
12761282
'reliableMultiply' ],
@@ -1671,15 +1677,17 @@
16711677
is_zombie: false,
16721678
parent_frame_id_list: [],
16731679
unique_hash: 'reliableMultiply_f2',
1674-
ordered_varnames: [ 'parent:e', 'a', 'b' ],
1675-
encoded_locals: { 'parent:e': [ 'REF', 7 ], a: 8, b: 8 } } ],
1680+
ordered_varnames: [ 'e', 'a', 'b' ],
1681+
encoded_locals: { e: [ 'REF', 7 ], a: 8, b: 8 } } ],
16761682
globals:
1677-
{ nTimes: 4,
1683+
{ e: [ 'REF', 7 ],
1684+
nTimes: 4,
16781685
MultiplicatorUnitFailure: [ 'REF', 1 ],
16791686
primitiveMultiply: [ 'REF', 2 ],
16801687
reliableMultiply: [ 'REF', 3 ] },
16811688
ordered_globals:
1682-
[ 'nTimes',
1689+
[ 'e',
1690+
'nTimes',
16831691
'MultiplicatorUnitFailure',
16841692
'primitiveMultiply',
16851693
'reliableMultiply' ],
@@ -2080,15 +2088,17 @@
20802088
is_zombie: false,
20812089
parent_frame_id_list: [],
20822090
unique_hash: 'reliableMultiply_f2',
2083-
ordered_varnames: [ 'parent:e', 'a', 'b' ],
2084-
encoded_locals: { 'parent:e': [ 'REF', 8 ], a: 8, b: 8 } } ],
2091+
ordered_varnames: [ 'e', 'a', 'b' ],
2092+
encoded_locals: { e: [ 'REF', 8 ], a: 8, b: 8 } } ],
20852093
globals:
2086-
{ nTimes: 5,
2094+
{ e: [ 'REF', 8 ],
2095+
nTimes: 5,
20872096
MultiplicatorUnitFailure: [ 'REF', 1 ],
20882097
primitiveMultiply: [ 'REF', 2 ],
20892098
reliableMultiply: [ 'REF', 3 ] },
20902099
ordered_globals:
2091-
[ 'nTimes',
2100+
[ 'e',
2101+
'nTimes',
20922102
'MultiplicatorUnitFailure',
20932103
'primitiveMultiply',
20942104
'reliableMultiply' ],
@@ -2489,15 +2499,17 @@
24892499
is_zombie: false,
24902500
parent_frame_id_list: [],
24912501
unique_hash: 'reliableMultiply_f2',
2492-
ordered_varnames: [ 'parent:e', 'a', 'b' ],
2493-
encoded_locals: { 'parent:e': [ 'REF', 9 ], a: 8, b: 8 } } ],
2502+
ordered_varnames: [ 'e', 'a', 'b' ],
2503+
encoded_locals: { e: [ 'REF', 9 ], a: 8, b: 8 } } ],
24942504
globals:
2495-
{ nTimes: 6,
2505+
{ e: [ 'REF', 9 ],
2506+
nTimes: 6,
24962507
MultiplicatorUnitFailure: [ 'REF', 1 ],
24972508
primitiveMultiply: [ 'REF', 2 ],
24982509
reliableMultiply: [ 'REF', 3 ] },
24992510
ordered_globals:
2500-
[ 'nTimes',
2511+
[ 'e',
2512+
'nTimes',
25012513
'MultiplicatorUnitFailure',
25022514
'primitiveMultiply',
25032515
'reliableMultiply' ],
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{ code: 'try {\n throw Error(\'oops\');\n}\ncatch (e) {\n var xxx = 1;\n console.log(e); // e should be in scope here\n}',
2+
trace:
3+
[ { stdout: '',
4+
func_name: '',
5+
stack_to_render: [],
6+
globals: { xxx: [ 'JS_SPECIAL_VAL', 'undefined' ] },
7+
ordered_globals: [ 'xxx' ],
8+
line: 2,
9+
col: 10,
10+
event: 'step_line',
11+
heap: {} },
12+
{ exception_msg: 'Error: oops',
13+
stdout: '',
14+
func_name: '',
15+
stack_to_render: [],
16+
globals: { xxx: [ 'JS_SPECIAL_VAL', 'undefined' ] },
17+
ordered_globals: [ 'xxx' ],
18+
line: 2,
19+
col: 10,
20+
event: 'exception',
21+
heap: {} },
22+
{ stdout: '',
23+
func_name: '',
24+
stack_to_render: [],
25+
globals: { e: [ 'REF', 1 ], xxx: [ 'JS_SPECIAL_VAL', 'undefined' ] },
26+
ordered_globals: [ 'e', 'xxx' ],
27+
line: 5,
28+
col: 4,
29+
event: 'step_line',
30+
heap: { '1': [ 'INSTANCE', '' ] } },
31+
{ stdout: '',
32+
func_name: '',
33+
stack_to_render: [],
34+
globals: { e: [ 'REF', 1 ], xxx: 1 },
35+
ordered_globals: [ 'e', 'xxx' ],
36+
line: 6,
37+
col: 4,
38+
event: 'step_line',
39+
heap: { '1': [ 'INSTANCE', '' ] } },
40+
{ stdout: '[Error: oops]\n',
41+
func_name: '',
42+
stack_to_render: [],
43+
globals: { xxx: 1 },
44+
ordered_globals: [ 'xxx' ],
45+
line: 7,
46+
col: 1,
47+
event: 'step_line',
48+
heap: {} } ] }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
try {
2+
throw Error('oops');
3+
}
4+
catch (e) {
5+
var xxx = 1;
6+
console.log(e); // e should be in scope here
7+
}

‎v4-cokapi/frontends/index.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<!--
55
6-
Cokapi, a multilingual successor to Online Python Tutor
6+
Cokapi, an experimental successor to Online Python Tutor
77
https://github.com/pgbovine/OnlinePythonTutor/
88
99
Copyright (C) Philip J. Guo (philip@pgbovine.net)
@@ -68,7 +68,7 @@
6868

6969
<body>
7070

71-
<p style="margin-bottom: 30px;">Cokapi is an experimental successor to
71+
<p style="margin-bottom: 30px;">Cokapi is an experimental version of
7272
<a href="http://pythontutor.com/">pythontutor.com</a>. Feel free to
7373
share the URL with relevant people and submit your feedback below, but
7474
<em>do not post the URL publicly</em> since it's not stable. Thanks!</p>

0 commit comments

Comments
 (0)