[JSC] Do not use asArrayModes() with Structures because it discards TypedArray inform...
[WebKit-https.git] / JSTests / stress / compare-eq-on-null-and-undefined-optimized-in-constant-folding.js
1 "use strict"
2
3 function unreachableCodeTest() {
4     var a;
5
6     var b = null;
7     if (b) {
8         a = 5;
9     }
10     return a == b;
11 }
12 noInline(unreachableCodeTest);
13
14 for (let i = 0; i < 1e4; ++i) {
15     if (!unreachableCodeTest())
16         throw "Failed unreachableCodeTest() with i = " + i;
17 }
18
19
20 function inlinedCompareToNull(a) {
21     return a == null;
22 }
23
24 function inlinedComparedToUndefined(a) {
25     return a == undefined;
26 }
27
28 // Warmup. Litter the profile with every types.
29 function warmupInlineFunctions() {
30     let returnValue = 0;
31     for (let i = 0; i < 1e4; ++i) {
32         returnValue += inlinedCompareToNull("foo");
33         returnValue += inlinedCompareToNull(null);
34         returnValue += inlinedCompareToNull(Math);
35         returnValue += inlinedCompareToNull(5);
36         returnValue += inlinedCompareToNull(5.5);
37
38         returnValue += inlinedComparedToUndefined("foo");
39         returnValue += inlinedComparedToUndefined(null);
40         returnValue += inlinedComparedToUndefined(Math);
41         returnValue += inlinedComparedToUndefined(5);
42         returnValue += inlinedComparedToUndefined(5.5);
43     }
44     return returnValue;
45 }
46 noInline(warmupInlineFunctions);
47 warmupInlineFunctions();
48
49 function testInlineFunctions(undefinedArg, nullArg) {
50     if (inlinedCompareToNull("foo"))
51         throw "Failed inlinedCompareToNull(\"foo\")";
52
53     if (!inlinedCompareToNull(null))
54         throw "Failed !inlinedCompareToNull(null)";
55
56     if (!inlinedCompareToNull(undefined))
57         throw "Failed !inlinedCompareToNull(undefined)";
58
59     if (!inlinedCompareToNull(undefinedArg))
60         throw "Failed !inlinedCompareToNull(undefinedArg)";
61
62     if (!inlinedCompareToNull(nullArg))
63         throw "Failed !inlinedCompareToNull(nullArg)";
64
65 }
66 noInline(testInlineFunctions);
67
68 for (let i = 0; i < 1e4; ++i) {
69     testInlineFunctions(undefined, null);
70 }