Debian Codegraph @

js/src/jit-test/tests/class/super-in-nested-eval.js

raw
1 // |jit-test| allow-overrecursed
2
3 // Test super() and super.foo() calls in deeply nested eval.
4
5 class C {
6 constructor(x) { this.x = x; }
7 foo() { this.x++; }
8 }
9 class D extends C {
10 constructor(depth) {
11 var d = depth;
12 var callsuper = 'super(depth); super.foo();';
13 var s = "var q; if (d-- > 0) { eval(s) } else { eval(callsuper); }";
14 eval(s);
15 }
16 }
17
18 const MAX_DEPTH = 250;
19
20 // These values should work.
21 var depths = [0, 1, 10, 200, MAX_DEPTH];
22 for (var d of depths) {
23 var o = new D(d);
24 assertEq(o.x, d + 1);
25 }
26
27 // This should fail.
28 var ex;
29 try {
30 new D(MAX_DEPTH + 1);
31 } catch(e) {
32 ex = e;
33 }
34 assertEq(ex instanceof InternalError, true);