Debian Codegraph @

js/src/jit-test/tests/arrays/spreadnew-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 function g() {
14 // Ensure |new.target| and |this| are correct.
15 assertEq(new.target, g);
16 assertEq(typeof this, "object");
17 assertEq(Object.getPrototypeOf(this), g.prototype);
18
19 // Returns a Number object, because constructor calls need to return an object!
20 return new Number(arguments.length);
21 }
22
23 function f(a) {
24 var sum = 0;
25 for ( let i=0 ; i < iterations ; i++ )
26 sum += new g(...a);
27 return sum;
28 }
29
30 function time(k, t) {
31 var then = Date.now();
32 assertEq(t(), iterations*k);
33 var now = Date.now();
34 return now - then;
35 }
36
37 function p(v) {
38 // Uncomment to see timings
39 // print(v);
40 }
41
42 f(make(200));
43
44 // There is currently a cutoff after 375 where we bailout in order to avoid
45 // handling very large stack frames. This slows the operation down by a factor
46 // of 100 or so.
47
48 p(time(374, () => f(make(374))));
49 p(time(375, () => f(make(375))));
50 p(time(376, () => f(make(376))));
51 p(time(377, () => f(make(377))));