Debian Codegraph @

js/src/jit-test/tests/warp/function-load-length.js

raw
1 // Test transpiling of LoadFunctionLengthResult and cover possible bailout conditions.
2
3 function empty() {}
4
5 // Note: Typically won't use LoadFunctionLengthResult, because the "length"
6 // property will be resolved on the first access.
7 function testGlobalFunction() {
8 for (var i = 0; i < 200; ++i) {
9 assertEq(empty.length, 0);
10 }
11 }
12 testGlobalFunction();
13
14 // Note: Typically won't use LoadFunctionLengthResult, because the "length"
15 // property will be resolved on the first access.
16 function testInnerFunction() {
17 function f() {}
18 for (var i = 0; i < 200; ++i) {
19 assertEq(f.length, 0);
20 }
21 }
22 testInnerFunction();
23
24 function testPerLoopFunction() {
25 for (var i = 0; i < 200; ++i) {
26 assertEq(function(){}.length, 0);
27 }
28 }
29 testPerLoopFunction();
30
31 // Note: Typically won't use LoadFunctionLengthResult, because the "length"
32 // property will be resolved on the first access.
33 function testNativeFunction() {
34 for (var i = 0; i < 200; ++i) {
35 assertEq(Math.max.length, 2);
36 }
37 }
38 testNativeFunction();
39
40 // Note: Typically won't use LoadFunctionLengthResult, because the "length"
41 // property will be resolved on the first access.
42 function testSelfHostedFunction() {
43 for (var i = 0; i < 200; ++i) {
44 assertEq(Array.prototype.forEach.length, 1);
45 }
46 }
47 testSelfHostedFunction();
48
49 // Bailout when the length doesn't fit into int32.
50 function testBailoutLength() {
51 var values = [0, 0x80000000];
52 var bound = empty.bind();
53
54 for (var i = 0; i < 10; ++i) {
55 var value = values[0 + (i >= 5)];
56
57 // Define on each iteration to get the same shape.
58 Object.defineProperty(bound, "length", {value});
59
60 for (var j = 0; j < 100; ++j) {
61 var f = bound.bind();
62 assertEq(f.length, value);
63 }
64 }
65 }
66 testBailoutLength();
67
68 // Bailout when trying to read "length" from a property with a lazy script.
69 function testBailoutLazyFunction() {
70 for (var i = 0; i < 200; ++i) {
71 var values = [function(){}, function(a){}];
72 var index = 0 + (i >= 100);
73 assertEq(values[index].length, index);
74 }
75 }
76 testBailoutLazyFunction();
77
78 // Bailout when trying to read "length" from a property with a lazy self-hosted script.
79 function testBailoutLazySelfHostedFunction() {
80 for (var i = 0; i < 200; ++i) {
81 var values = [function(){}, Array.prototype.map];
82 var index = 0 + (i >= 100);
83 assertEq(values[index].length, index);
84 }
85 }
86 testBailoutLazySelfHostedFunction();