summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Object-errorLineNumber-errorColumnNumber.js
blob: a581f93b6e067d54183308dd7c8c16d0930cedb3 (plain)
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
// Debugger.Object.prototype.{errorLineNumber,errorColumnNumber} return the
// line number and column number associated with some error object.

var g = newGlobal({newCompartment: true});
var dbg = new Debugger();
var gw = dbg.addDebuggee(g);

var syntaxError = gw.executeInGlobal("\nlet a, a;").throw;
assertEq(syntaxError.errorLineNumber, 2);
assertEq(syntaxError.errorColumnNumber, 7);

var typeError = gw.executeInGlobal("\n1 + f();").throw;
assertEq(typeError.errorLineNumber, 2);
assertEq(typeError.errorColumnNumber, 1);

// Custom errors have no line/column numbers .
var customError = gw.executeInGlobal("\nthrow 1;").throw;
assertEq(customError.errorLineNumber, undefined);
assertEq(customError.errorColumnNumber, undefined);

customError = gw.executeInGlobal("\nthrow { errorLineNumber: 10, errorColumnNumber: 20 };").throw;
assertEq(customError.errorLineNumber, undefined);
assertEq(customError.errorColumnNumber, undefined);

customError = gw.executeInGlobal("\nthrow { lineNumber: 10, columnNumber: 20 };").throw;
assertEq(customError.errorLineNumber, undefined);
assertEq(customError.errorColumnNumber, undefined);

// Ensure that the method works across globals.
g.eval(`var g = newGlobal({newCompartment: true});
        g.eval('var err; \\n' +
               'try {\\n' +
               '  f();\\n' +
               '} catch (e) {\\n' +
               '  err = e;\\n' +
               '}');
        var err2 = g.err;`);
var otherGlobalError = gw.executeInGlobal("throw err2").throw;
assertEq(otherGlobalError.errorLineNumber, 3);
assertEq(otherGlobalError.errorColumnNumber, 3);

// Ensure that non-error objects return undefined.
const Args = [
    "1",
    "'blah'",
    "({})",
    "[]",
    "() => 1"
]

for (let arg of Args) {
    let nonError = gw.executeInGlobal(`${arg}`).return;
    assertEq(nonError.errorLineNumber, undefined);
    assertEq(nonError.errorColumnNumber, undefined);
}