Bug 1811231 part 1 - Add tests for onPop and CheckReturn source locations. r=arai

This tests the line/column we report for (1) the final yield/return in a function or
generator, and (2) for the CheckReturn exception in a derived class constructor.

The expected values in the tests are wrong, but it shows what we currently get.
This will be fixed in the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D167256
This commit is contained in:
Jan de Mooij
2023-01-23 10:27:16 +00:00
parent a4deb4eaa5
commit 1996608411
2 changed files with 76 additions and 0 deletions
@@ -0,0 +1,18 @@
// Test source location for missing-super-call check at the end of a derived class constructor.
class A {};
class B extends A {
constructor(x) {
if (x === null) {
throw "fail";
}
}
};
let ex;
try {
new B();
} catch (e) {
ex = e;
}
assertEq(ex instanceof ReferenceError, true);
assertEq(ex.lineNumber, 6);
assertEq(ex.columnNumber, 13);
@@ -0,0 +1,58 @@
// Ensure onPop hook for the final return/yield uses the correct source location
// (closing '}' of the function body).
var g = newGlobal({newCompartment: true});
var dbg = new Debugger(g);
dbg.onEnterFrame = frame => {
if (frame.type === "global") {
return;
}
frame.onPop = c => {
if (c.yield !== true) {
const data = frame.script.getOffsetMetadata(frame.offset);
g.log.push(`pop(${data.lineNumber}:${data.columnNumber})`);
}
};
};
g.evaluate(` // line 1
this.log = []; // 2
function A() { // 3
log.push("A"); // 4
if (log === null) { // 5
throw "fail"; // 6
} // 7
} // 8
function* B() { // 9
log.push("B"); // 10
if (log === null) { // 11
throw "fail"; // 12
} // 13
} // 14
async function C() { // 15
log.push("C"); // 16
if (log === null) { // 17
throw "fail"; // 18
} // 19
} // 20
let D = async () => { // 21
log.push("D"); // 22
if (log === null) { // 23
throw "fail"; // 24
} // 25
}; // 26
class E extends class {} { // 27
constructor() { // 28
log.push("E"); // 29
super(); // 30
if (log === null) { // 31
throw "fail"; // 32
} // 33
} // 34
} // 35
A();
for (let x of B()) {}
C();
D();
new E();
`);
assertEq(g.log.join(","), "A,pop(8:0),B,pop(12:8),C,pop(18:8),D,pop(24:8),E,pop(27:16),pop(34:4)");