Debian Codegraph @

js/src/jit-test/tests/warp/typeof-switch.js

raw
1 // Test case |typeof| folding in switch-statement contexts.
2
3 function TypeOf(thing) {
4 switch (typeof thing) {
5 case "undefined":
6 return "undefined";
7 case "object":
8 return "object";
9 case "function":
10 return "function";
11 case "string":
12 return "string";
13 case "number":
14 return "number";
15 case "boolean":
16 return "boolean";
17 case "symbol":
18 return "symbol";
19 case "bigint":
20 return "bigint";
21 case "bad":
22 return "bad";
23 }
24 return "bad2";
25 }
26
27 function test() {
28 const ccwGlobal = newGlobal({newCompartment: true});
29 const xs = [
30 // "undefined"
31 // Plain undefined and objects emulating undefined, including various
32 // proxy wrapper cases.
33 undefined,
34 createIsHTMLDDA(),
35 wrapWithProto(createIsHTMLDDA(), null),
36 ccwGlobal.eval("createIsHTMLDDA()"),
37
38 // "object"
39 // Plain objects and various proxy wrapper cases.
40 {},
41 this,
42 new Proxy({}, {}),
43 wrapWithProto({}, null),
44 transplantableObject({proxy: true}).object,
45 ccwGlobal.Object(),
46
47 // "function"
48 // Plain functions and various proxy wrapper cases.
49 function(){},
50 new Proxy(function(){}, {}),
51 new Proxy(createIsHTMLDDA(), {}),
52 wrapWithProto(function(){}, null),
53 ccwGlobal.Function(),
54
55 // "string"
56 "",
57
58 // "number"
59 // Int32 and Double numbers.
60 0,
61 1.23,
62
63 // "boolean"
64 true,
65
66 // "symbol"
67 Symbol(),
68
69 // "bigint"
70 0n,
71 ];
72
73 for (let i = 0; i < 500; ++i) {
74 let x = xs[i % xs.length];
75 assertEq(TypeOf(x), typeof x);
76 }
77 }
78 for (let i = 0; i < 2; ++i) test();