Skip to content

Commit e5e6e50

Browse files
committed
got block scopes displaying better
1 parent 44741c1 commit e5e6e50

4 files changed

Lines changed: 62 additions & 32 deletions

File tree

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,22 @@ function listener(event, execState, eventData, data) {
705705
}
706706
*/
707707

708-
//log(' f.scopeCount()', f.scopeCount());
708+
// first calculate the total number of block scopes so that we can
709+
// number them properly to maintain their identities (tricky hack)
710+
var nBlockScopes = 0;
711+
for (ii = 0; ii < f.scopeCount(); ii++) {
712+
sc = f.scope(ii);
713+
scopeType = sc.details_.details_[0];
714+
if (scopeType === 5) {
715+
nBlockScopes++;
716+
}
717+
}
718+
719+
//log(' f.scopeCount()', f.scopeCount(), ', nBlockScopes:', nBlockScopes);
720+
709721
var nParentScopes = 1;
710-
// trick: go through the scopes BACKWARDS so that nested blocks
711-
// are displayed in order (outer blocks before inner blocks)
722+
// TODO: for some weird reason, it doesn't work when I iterate
723+
// forwards, strange
712724
for (ii = f.scopeCount() - 1;
713725
ii >= 0;
714726
ii--) {
@@ -738,7 +750,7 @@ function listener(event, execState, eventData, data) {
738750
739751
*/
740752
scopeType = sc.details_.details_[0];
741-
//log(' scopeType:', scopeType);
753+
//log(' scopeType:', scopeType, ii);
742754
var e;
743755
// DON'T grab globals again since it's redundant
744756
if (scopeType === 1 || scopeType === 4) { // Local or Catch (for exceptions)
@@ -784,7 +796,9 @@ function listener(event, execState, eventData, data) {
784796
// toplevel scope (see below); it should all be pointing to
785797
// the same object anyhow
786798
} else if (scopeType === 5) { // block scope for ES6 let (?) only in Node v6
787-
scopeIdx = sc.scope_index_ + 1; // uniquely identify this block (+1 for human readability)
799+
// uniquely identify this block (need to subtract from nBlockScopes
800+
// to get the right number when there are multiple nested blocks (tricky weird!)
801+
scopeIdx = nBlockScopes - sc.scope_index_;
788802
scopeObj = sc.details_.details_[1];
789803
assert(_.isObject(scopeObj));
790804
//log('Local block:', scopeIdx, util.inspect(sc, {showHidden: true, depth: null}));
@@ -815,9 +829,23 @@ function listener(event, execState, eventData, data) {
815829
curTraceEntry.stack_to_render.unshift(traceStackEntry);
816830
}
817831

832+
// first calculate the total number of block scopes so that we can
833+
// number them properly to maintain their identities (tricky hack)
834+
var nGlobalBlockScopes = 0;
835+
for (ii = 0; ii < topFrame.scopeCount(); ii++) {
836+
sc = topFrame.scope(ii);
837+
scopeType = sc.details_.details_[0];
838+
if (scopeType === 5) {
839+
nGlobalBlockScopes++;
840+
}
841+
}
842+
818843
//log(' topFrame.scopeCount()', topFrame.scopeCount());
819844
// finally, inspect only the top-level "global" frame to grab globals
820-
for (ii = 0; ii < topFrame.scopeCount(); ii++) {
845+
// go backwards to make things a bit more human-readable
846+
for (ii = topFrame.scopeCount() - 1;
847+
ii >= 0;
848+
ii--) {
821849
sc = topFrame.scope(ii);
822850

823851
/* From v8/src/debug/debug-scopes.h
@@ -883,7 +911,9 @@ function listener(event, execState, eventData, data) {
883911
// ends up being redundant and super confusing. hasLocalBlock is
884912
// a hack to elide that problem.
885913

886-
scopeIdx = sc.scope_index_ + 1; // uniquely identify this block (+1 for human readability)
914+
// uniquely identify this block (need to subtract from nGlobalBlockScopes
915+
// to get the right number when there are multiple nested blocks (tricky weird!)
916+
scopeIdx = nGlobalBlockScopes - sc.scope_index_;
887917
scopeObj = sc.details_.details_[1];
888918
assert(_.isObject(scopeObj));
889919
//log('Global block:', util.inspect(sc, {showHidden: true, depth: null}));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
{ stdout: '',
3232
func_name: '',
3333
stack_to_render: [],
34-
globals: { e: [ 'REF', 1 ], x: 5 },
35-
ordered_globals: [ 'e', 'x' ],
34+
globals: { x: 5, e: [ 'REF', 1 ] },
35+
ordered_globals: [ 'x', 'e' ],
3636
line: 6,
3737
col: 2,
3838
event: 'step_line',
3939
heap: { '1': [ 'INSTANCE_PPRINT', 'object', 'Error: oh crapo' ] } },
4040
{ stdout: 'hello\n',
4141
func_name: '',
4242
stack_to_render: [],
43-
globals: { e: [ 'REF', 1 ], x: 5 },
44-
ordered_globals: [ 'e', 'x' ],
43+
globals: { x: 5, e: [ 'REF', 1 ] },
44+
ordered_globals: [ 'x', 'e' ],
4545
line: 7,
4646
col: 2,
4747
event: 'step_line',

‎v4-cokapi/backends/javascript/tests/es6-global-let.golden‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,35 @@
3232
{ stdout: '',
3333
func_name: '',
3434
stack_to_render: [],
35-
globals: { 'a (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ], a: 5, b: 10 },
36-
ordered_globals: [ 'a (block 1)', 'a', 'b' ],
35+
globals: { a: 5, b: 10, 'a (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ] },
36+
ordered_globals: [ 'a', 'b', 'a (block 1)' ],
3737
line: 5,
3838
col: 2,
3939
event: 'step_line',
4040
heap: {} },
4141
{ stdout: '',
4242
func_name: '',
4343
stack_to_render: [],
44-
globals: { 'a (block 1)': 4, a: 5, b: 10 },
45-
ordered_globals: [ 'a (block 1)', 'a', 'b' ],
44+
globals: { a: 5, b: 10, 'a (block 1)': 4 },
45+
ordered_globals: [ 'a', 'b', 'a (block 1)' ],
4646
line: 6,
4747
col: 2,
4848
event: 'step_line',
4949
heap: {} },
5050
{ stdout: '',
5151
func_name: '',
5252
stack_to_render: [],
53-
globals: { 'a (block 1)': 4, a: 5, b: 1 },
54-
ordered_globals: [ 'a (block 1)', 'a', 'b' ],
53+
globals: { a: 5, b: 1, 'a (block 1)': 4 },
54+
ordered_globals: [ 'a', 'b', 'a (block 1)' ],
5555
line: 8,
5656
col: 2,
5757
event: 'step_line',
5858
heap: {} },
5959
{ stdout: '4\n',
6060
func_name: '',
6161
stack_to_render: [],
62-
globals: { 'a (block 1)': 4, a: 5, b: 1 },
63-
ordered_globals: [ 'a (block 1)', 'a', 'b' ],
62+
globals: { a: 5, b: 1, 'a (block 1)': 4 },
63+
ordered_globals: [ 'a', 'b', 'a (block 1)' ],
6464
line: 9,
6565
col: 2,
6666
event: 'step_line',

‎v4-cokapi/backends/javascript/tests/es6-let.golden‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@
145145
is_zombie: false,
146146
parent_frame_id_list: [],
147147
unique_hash: 'foo_f2',
148-
ordered_varnames: [ 'xxx', 'xxx (block 2)', 'xxx (block 1)' ],
148+
ordered_varnames: [ 'xxx', 'xxx (block 1)', 'xxx (block 2)' ],
149149
encoded_locals:
150150
{ xxx: 5,
151-
'xxx (block 2)': 10,
152-
'xxx (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ] } } ],
151+
'xxx (block 1)': 10,
152+
'xxx (block 2)': [ 'JS_SPECIAL_VAL', 'undefined' ] } } ],
153153
globals: { foo: [ 'REF', 1 ] },
154154
ordered_globals: [ 'foo' ],
155155
line: 7,
@@ -172,8 +172,8 @@
172172
is_zombie: false,
173173
parent_frame_id_list: [],
174174
unique_hash: 'foo_f2',
175-
ordered_varnames: [ 'xxx', 'xxx (block 2)', 'xxx (block 1)' ],
176-
encoded_locals: { xxx: 5, 'xxx (block 2)': 10, 'xxx (block 1)': 20 } } ],
175+
ordered_varnames: [ 'xxx', 'xxx (block 1)', 'xxx (block 2)' ],
176+
encoded_locals: { xxx: 5, 'xxx (block 1)': 10, 'xxx (block 2)': 20 } } ],
177177
globals: { foo: [ 'REF', 1 ] },
178178
ordered_globals: [ 'foo' ],
179179
line: 8,
@@ -196,8 +196,8 @@
196196
is_zombie: false,
197197
parent_frame_id_list: [],
198198
unique_hash: 'foo_f2',
199-
ordered_varnames: [ 'xxx', 'xxx (block 2)', 'xxx (block 1)' ],
200-
encoded_locals: { xxx: 5, 'xxx (block 2)': 10, 'xxx (block 1)': 20 } } ],
199+
ordered_varnames: [ 'xxx', 'xxx (block 1)', 'xxx (block 2)' ],
200+
encoded_locals: { xxx: 5, 'xxx (block 1)': 10, 'xxx (block 2)': 20 } } ],
201201
globals: { foo: [ 'REF', 1 ] },
202202
ordered_globals: [ 'foo' ],
203203
line: 9,
@@ -220,12 +220,12 @@
220220
is_zombie: false,
221221
parent_frame_id_list: [],
222222
unique_hash: 'foo_f2',
223-
ordered_varnames: [ 'xxx', 'xxx (block 3)', 'xxx (block 2)', 'xxx (block 1)' ],
223+
ordered_varnames: [ 'xxx', 'xxx (block 1)', 'xxx (block 2)', 'xxx (block 3)' ],
224224
encoded_locals:
225225
{ xxx: 5,
226-
'xxx (block 3)': 10,
226+
'xxx (block 1)': 10,
227227
'xxx (block 2)': 20,
228-
'xxx (block 1)': [ 'JS_SPECIAL_VAL', 'undefined' ] } } ],
228+
'xxx (block 3)': [ 'JS_SPECIAL_VAL', 'undefined' ] } } ],
229229
globals: { foo: [ 'REF', 1 ] },
230230
ordered_globals: [ 'foo' ],
231231
line: 10,
@@ -248,12 +248,12 @@
248248
is_zombie: false,
249249
parent_frame_id_list: [],
250250
unique_hash: 'foo_f2',
251-
ordered_varnames: [ 'xxx', 'xxx (block 3)', 'xxx (block 2)', 'xxx (block 1)' ],
251+
ordered_varnames: [ 'xxx', 'xxx (block 1)', 'xxx (block 2)', 'xxx (block 3)' ],
252252
encoded_locals:
253253
{ xxx: 5,
254-
'xxx (block 3)': 10,
254+
'xxx (block 1)': 10,
255255
'xxx (block 2)': 20,
256-
'xxx (block 1)': 30 } } ],
256+
'xxx (block 3)': 30 } } ],
257257
globals: { foo: [ 'REF', 1 ] },
258258
ordered_globals: [ 'foo' ],
259259
line: 11,

0 commit comments

Comments
 (0)