Skip to content

Commit 42f7533

Browse files
committed
prep for block scope work
1 parent c9b5e45 commit 42f7533

2 files changed

Lines changed: 57 additions & 22 deletions

File tree

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

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,30 @@ function listener(event, execState, eventData, data) {
605605
// inspect only the top "global" frame to grab globals
606606
for (ii = 0; ii < topFrame.scopeCount(); ii++) {
607607
sc = topFrame.scope(ii);
608-
// According to https://code.google.com/p/v8-wiki/wiki/DebuggerProtocol
609-
//
610-
// 0: Global
611-
// 1: Local
612-
// 2: With
613-
// 3: Closure
614-
// 4: Catch
608+
609+
/* From v8/src/debug/debug-scopes.h
610+
611+
enum ScopeType {
612+
ScopeTypeGlobal = 0,
613+
ScopeTypeLocal,
614+
ScopeTypeWith,
615+
ScopeTypeClosure,
616+
ScopeTypeCatch,
617+
ScopeTypeBlock,
618+
ScopeTypeScript,
619+
ScopeTypeModule
620+
};
621+
622+
0: Global
623+
1: Local
624+
2: With
625+
3: Closure
626+
4: Catch
627+
5: Block scope for ES6 let (only in Node v6)
628+
6: Script (only in Node v6)
629+
7: Module (only in Node v6)
630+
631+
*/
615632
scopeType = sc.details_.details_[0];
616633
if (scopeType === 0) { // Global -- to handle global variables
617634
scopeObj = sc.details_.details_[1];
@@ -625,8 +642,7 @@ function listener(event, execState, eventData, data) {
625642
curTraceEntry.globals[globalVarname] = encodeObject(globalVal);
626643
}
627644
}
628-
}
629-
else if (scopeType === 4) { // Catch -- to handle global exception blocks
645+
} else if (scopeType === 4) { // Catch -- to handle global exception blocks
630646
scopeObj = sc.details_.details_[1];
631647

632648
var globalCatchScopePairs = _.pairs(scopeObj);
@@ -637,6 +653,10 @@ function listener(event, execState, eventData, data) {
637653
assert(!_.has(curTraceEntry.globals, globalCatchVarname));
638654
curTraceEntry.globals[globalCatchVarname] = encodeObject(globalCatchVal);
639655
}
656+
} else if (scopeType === 5) { // Block -- handle global ES6 let-style blocks
657+
// TODO: handle me. how do we uniquely identify this block? by
658+
// line or other code location? look up GetNestedScopeChain in
659+
// v8 source code
640660
}
641661
}
642662

@@ -744,15 +764,29 @@ function listener(event, execState, eventData, data) {
744764
ii++) {
745765
sc = f.scope(ii);
746766

747-
// According to https://code.google.com/p/v8-wiki/wiki/DebuggerProtocol
748-
//
749-
// 0: Global
750-
// 1: Local
751-
// 2: With
752-
// 3: Closure
753-
// 4: Catch
754-
// 5: ??? block scope for ES6 let (?) (only in Node v6)
755-
// 6: ??? (only in Node v6)
767+
/* From v8/src/debug/debug-scopes.h
768+
769+
enum ScopeType {
770+
ScopeTypeGlobal = 0,
771+
ScopeTypeLocal,
772+
ScopeTypeWith,
773+
ScopeTypeClosure,
774+
ScopeTypeCatch,
775+
ScopeTypeBlock,
776+
ScopeTypeScript,
777+
ScopeTypeModule
778+
};
779+
780+
0: Global
781+
1: Local
782+
2: With
783+
3: Closure
784+
4: Catch
785+
5: Block scope for ES6 let (only in Node v6)
786+
6: Script (only in Node v6)
787+
7: Module (only in Node v6)
788+
789+
*/
756790
scopeType = sc.details_.details_[0];
757791
var e;
758792
// DON'T grab globals again since it's redundant
@@ -795,11 +829,12 @@ function listener(event, execState, eventData, data) {
795829
nParentScopes++;
796830
} else if (scopeType === 5) { // block scope for ES6 let (?) only in Node v6
797831
// TODO: handle me. how do we uniquely identify this block? by
798-
// line or other code location?
832+
// line or other code location? look up GetNestedScopeChain in
833+
// v8 source code
799834
} else {
800835
assert(scopeType === 0 ||
801-
scopeType === 6 /* wtf?!? in Node v6.0.0, there's sometimes a
802-
scopeType of 6, which is mysterious, so skip it */);
836+
scopeType === 6 ||
837+
scopeType === 7);
803838
}
804839
}
805840

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
col: 4,
3838
event: 'step_line',
3939
heap: { '1': [ 'INSTANCE_PPRINT', 'object', 'Error: oops' ] } },
40-
{ stdout: 'Error: oops\n at Error (native)\n at userscript.js:4:11\n at ContextifyScript.Script.runInNewContext (vm.js:18:15)\n at module.exports (/home/pgbovine/OnlinePythonTutor/v4-cokapi/backends/javascript/node_modules/eval/eval.js:56:8)\n at Object.<anonymous> (/home/pgbovine/OnlinePythonTutor/v4-cokapi/backends/javascript/jslogger.js:951:3)\n at Module._compile (module.js:541:32)\n at Object.Module._extensions..js (module.js:550:10)\n at Module.load (module.js:456:32)\n at tryModuleLoad (module.js:415:12)\n at Function.Module._load (module.js:407:3)\n',
40+
{ stdout: 'Error: oops\n at Error (native)\n at userscript.js:4:11\n at ContextifyScript.Script.runInNewContext (vm.js:18:15)\n at module.exports (/home/pgbovine/OnlinePythonTutor/v4-cokapi/backends/javascript/node_modules/eval/eval.js:56:8)\n at Object.<anonymous> (/home/pgbovine/OnlinePythonTutor/v4-cokapi/backends/javascript/jslogger.js:986:3)\n at Module._compile (module.js:541:32)\n at Object.Module._extensions..js (module.js:550:10)\n at Module.load (module.js:456:32)\n at tryModuleLoad (module.js:415:12)\n at Function.Module._load (module.js:407:3)\n',
4141
func_name: '',
4242
stack_to_render: [],
4343
globals: { xxx: 1 },

0 commit comments

Comments
 (0)