Debian Codegraph @

js/src/jit-test/tests/debug/Frame-identity-07.js

raw
1 // Distinct generator calls result in distinct Debugger.Frames.
2
3 let g = newGlobal({newCompartment: true});
4 g.eval(`
5 function* count(n) {
6 if (n > 0) {
7 for (let x of count(n - 1))
8 yield x;
9 yield n;
10 }
11 }
12 `);
13
14 let log = "";
15 let dbg = Debugger(g);
16 let nextId = 0;
17 function mark(frame) {
18 if (frame.id === undefined)
19 frame.id = nextId++;
20 }
21 dbg.onEnterFrame = frame => {
22 mark(frame);
23 log += frame.id + "[";
24 frame.onPop = completion => {
25 mark(frame);
26 log += "]" + frame.id;
27 };
28 };
29
30
31 let j = 0;
32 for (let k of g.count(5)) {
33 assertEq(k, ++j);
34 log += " ";
35 }
36
37 assertEq(log,
38 // Calling a generator function just returns a generator object
39 // without running the body at all; hence "0[]0". However, this call
40 // does evaluate default argument values, if any, so we do report an
41 // onEnterFrame / onPop for it.
42 "0[]0" +
43 // Demanding the first value from the top generator forces
44 // SpiderMonkey to create all five generator objects (the empty "n[]n"
45 // pairs) and then demand a value from them (the longer "n[...]n"
46 // substrings).
47 "0[1[]11[2[]22[3[]33[4[]44[5[]55[]5]4]3]2]1]0 " +
48 "0[1[2[3[4[]4]3]2]1]0 " +
49 "0[1[2[3[]3]2]1]0 " +
50 "0[1[2[]2]1]0 " +
51 "0[1[]1]0 " +
52 "0[]0");