Debian Codegraph @

js/src/jit-test/tests/arrays/spreadsupercall-optimization.js

raw
1 // Test case adapted from "apply-optimization.js" to test SpreadNew instead of FunApply.
2
3 // Uses fewer iterations than "apply-optimization.js" to keep the overall runtime reasonable.
4 const iterations = 40;
5
6 function make(k) {
7 var a = new Array(k);
8 for ( let i=0 ; i < k ; i++ )
9 a[i] = {}
10 return a;
11 }
12
13 class Base {
14 constructor() {
15 // Ensure |new.target| and |this| are correct.
16 assertEq(new.target, g);
17 assertEq(typeof this, "object");
18 assertEq(Object.getPrototypeOf(this), g.prototype);
19
20 // Returns a Number object, because constructor calls need to return an object!
21 return new Number(arguments.length);
22 }
23 }
24
25 class g extends Base {
26 constructor(...args) {
27 super(...args);
28 }
29 }
30
31 function f(a) {
32 var sum = 0;
33 for ( let i=0 ; i < iterations ; i++ )
34 sum += new g(...a);
35 return sum;
36 }
37
38 function time(k, t) {
39 var then = Date.now();
40 assertEq(t(), iterations*k);
41 var now = Date.now();
42 return now - then;
43 }
44
45 function p(v) {
46 // Uncomment to see timings
47 // print(v);
48 }
49
50 f(make(200));
51
52 // There is currently a cutoff after 375 where we bailout in order to avoid
53 // handling very large stack frames. This slows the operation down by a factor
54 // of 100 or so.
55
56 p(time(374, () => f(make(374))));
57 p(time(375, () => f(make(375))));
58 p(time(376, () => f(make(376))));
59 p(time(377, () => f(make(377))));