summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Script-getEffectfulOffsets.js
blob: 2221b7e6cdc3362c447e7e0a7563e8daf022c20b (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
59
60
61
62
63
64
65
66
67
// Check that Script.getEffectfulOffsets behaves sensibly.

var g = newGlobal({newCompartment: true});
var dbg = Debugger(g);
var numEffectfulOperations;

function onNewScript(script) {
  script.getChildScripts().forEach(onNewScript);
  numEffectfulOperations += script.getEffectfulOffsets().length;
}
dbg.onNewScript = onNewScript;

function test(code, expected) {
  numEffectfulOperations = 0;
  g.eval(`
function f(a, b, c) {
${code}
}
`);
  assertEq(numEffectfulOperations, expected);
}

const base = 1;
test("", base);

test("a.f = 0", base + 1);
test("a.f++", base + 1);
test("return a.f", base + 0);
test("a[b] = 0", base + 1);
test("a[b]++", base + 1);
test("return a[b]", base + 0);
test("a = 0", base + 0);
test("d = 0", base + 1);
test("with (a) { b = 0; }", base + 7);
test("let o = {}; ({x: o.x} = { x: 10 })", base + 1);
test("var x", base + 0);

// d is not closed over, and "let d = 0;" uses InitLexical,
// which is non-effectful.
test(`
let d = 10;
`, base + 0);

// d is closed over, and "let d = 0;" uses InitAliasedLexical with hops == 0,
// which is non-effectful.
test(`
let d = 10;
function g() {
  d;
}
`, base + 0);

// Private accessor uses InitAliasedLexical with hops == 1,
// which is currently marked as effectful.
// Please fix this test if it's marked as non-effectful in the future.
test(`
class B {
  set #x(x) {}
}
`, base + 1);

test(`
class B {
  get #x() {}
  set #x(x) {}
}
`, base + 2);