Debian Codegraph @

js/src/jit-test/tests/cacheir/bound-construct-scripted.js

raw
1 function testNewTargetGuard() {
2 var weirdNewTarget = function() {};
3 var fun = function() { return new.target; };
4 var boundFun = fun.bind(null);
5 for (var i = 0; i < 60; i++) {
6 var newTarget = i < 40 ? boundFun : weirdNewTarget;
7 var res = Reflect.construct(boundFun, [], newTarget);
8 assertEq(res, i < 40 ? fun : weirdNewTarget);
9 }
10 }
11 testNewTargetGuard();
12
13 function testPrototypeGuard() {
14 var fun = function() {};
15 var boundFun = fun.bind(null);
16 var customPrototype1 = {};
17 var customPrototype2 = {};
18 fun.prototype = customPrototype1;
19
20 for (var i = 0; i < 60; i++) {
21 if (i === 40) {
22 fun.prototype = customPrototype2;
23 }
24 var res = new boundFun();
25 assertEq(Object.getPrototypeOf(res), i < 40 ? customPrototype1 : customPrototype2);
26 }
27 }
28 testPrototypeGuard();
29
30 function testNonObjectPrototypeGuard() {
31 var fun = function() {};
32 var boundFun = fun.bind(null);
33 fun.prototype = null;
34 var customPrototype = {};
35
36 for (var i = 0; i < 60; i++) {
37 if (i === 40) {
38 fun.prototype = customPrototype;
39 }
40 var res = new boundFun();
41 assertEq(Object.getPrototypeOf(res), i < 40 ? Object.prototype : customPrototype);
42 }
43 }
44 testNonObjectPrototypeGuard();
45
46 function testObjectReturnValue() {
47 var fun = function() { return Math; };
48 var boundFun = fun.bind(null);
49 for (var i = 0; i < 60; i++) {
50 var res = new boundFun();
51 assertEq(res, Math);
52 }
53 }
54 testObjectReturnValue();
55
56 function testManyArgs() {
57 var fun = function(a, b, c, d, e, f, g, h, i, j) {
58 this.values = [a, b, c, d, e, f, g, h, i, j].join(",");
59 };
60 var boundFun1 = fun.bind(null, 1, 2);
61 var boundFun2 = fun.bind(null, 1, 2, 3, 4, 5, 6);
62 for (var i = 0; i < 60; i++) {
63 assertEq(new boundFun1().values, "1,2,,,,,,,,");
64 assertEq(new boundFun1(10, 11, 12, 13, 14).values, "1,2,10,11,12,13,14,,,");
65 assertEq(new boundFun1(10, 11, 12, 13, 14, 15, 16, 17).values, "1,2,10,11,12,13,14,15,16,17");
66
67 assertEq(new boundFun2().values, "1,2,3,4,5,6,,,,");
68 assertEq(new boundFun2(10, 11).values, "1,2,3,4,5,6,10,11,,");
69 assertEq(new boundFun2(10, 11, 12, 13, 14, 15, 16, 17).values, "1,2,3,4,5,6,10,11,12,13");
70 }
71 }
72 testManyArgs();