1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Test instrumentation functionality when using generators and async functions.
load(libdir + 'eqArrayHelper.js');
var g = newGlobal({ newCompartment: true });
var dbg = Debugger(g);
var gdbg = dbg.addDebuggee(g);
var allScripts = [];
function setScriptId(script) {
script.setInstrumentationId(allScripts.length);
allScripts.push(script);
script.getChildScripts().forEach(setScriptId);
}
dbg.onNewScript = setScriptId;
function getOffsetLine(scriptId, offset) {
const script = allScripts[scriptId];
return script.getOffsetMetadata(offset).lineNumber;
}
const executedLines = [];
gdbg.setInstrumentation(
gdbg.makeDebuggeeValue((kind, script, offset) => {
executedLines.push(getOffsetLine(script, offset));
}),
["breakpoint"]
);
function testFunction(fn, expected) {
gdbg.setInstrumentationActive(true);
for (var i = 0; i < 5; i++) {
executedLines.length = 0;
fn();
assertEqArray(executedLines, expected);
}
gdbg.setInstrumentationActive(false);
}
g.eval(`
async function asyncfun() {
await Promise.resolve(0);
await Promise.resolve(1);
var a = 0;
await Promise.resolve(2);
a++;
}
`);
testFunction(() => {
async function f() { await g.asyncfun(); }
f();
drainJobQueue();
}, [3, 3, 4, 4, 5, 6, 6, 7]);
g.eval(`
function *generator() {
yield 1;
var a = 0;
yield 2;
a++;
}
`);
testFunction(() => {
for (const i of g.generator()) {}
}, [3, 4, 5, 6]);
|