summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Debugger-isCompilableUnit.js
blob: dbfde0ef46e642365f8d936ec8541f0df4b95d20 (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
56
57
58
load(libdir + "asserts.js");

const bad_types = [
    2112,
    {geddy: "lee"},
    () => 1,
    [],
    Array
]

// We only accept strings around here!
for (var badType of bad_types) {
    assertThrowsInstanceOf(() => {
        Debugger.isCompilableUnit(badType);
    }, TypeError);
}

const compilable_units = [
   "wubba-lubba-dub-dub",
   "'Get Schwifty!'",
   "1 + 2",
   "function f(x) {}",
   "function x(...f,) {", // statements with bad syntax are always compilable
   "let x = 100",
   ";;;;;;;;",
   "",
   " ",
   "\n",
   "let x",
]

const non_compilable_units = [
    "function f(x) {",
    "(...d) =>",
    "{geddy:",
    "{",
    "[1, 2",
    "[",
    "1 +",
    "let x =",
    "3 ==",
]

for (var code of compilable_units) {
    assertEq(Debugger.isCompilableUnit(code), true);
}

for (var code of non_compilable_units) {
    assertEq(Debugger.isCompilableUnit(code), false);
}

// Supplying no arguments should throw a type error
assertThrowsInstanceOf(() => {
    Debugger.isCompilableUnit();
}, TypeError);

// Supplying extra arguments should be fine
assertEq(Debugger.isCompilableUnit("", 1, 2, 3, 4, {}, []), true);