summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/warp/typeof-switch.js
blob: 4dc33c3686a2a4342af006342cc86991c19f8412 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Test case |typeof| folding in switch-statement contexts.

function TypeOf(thing) {
  switch (typeof thing) {
  case "undefined":
    return "undefined";
  case "object":
    return "object";
  case "function":
    return "function";
  case "string":
    return "string";
  case "number":
    return "number";
  case "boolean":
    return "boolean";
  case "symbol":
    return "symbol";
  case "bigint":
    return "bigint";
  case "bad":
    return "bad";
  }
  return "bad2";
}

function test() {
  const ccwGlobal = newGlobal({newCompartment: true});
  const xs = [
    // "undefined"
    // Plain undefined and objects emulating undefined, including various
    // proxy wrapper cases.
    undefined,
    createIsHTMLDDA(),
    wrapWithProto(createIsHTMLDDA(), null),
    ccwGlobal.eval("createIsHTMLDDA()"),

    // "object"
    // Plain objects and various proxy wrapper cases.
    {},
    this,
    new Proxy({}, {}),
    wrapWithProto({}, null),
    transplantableObject({proxy: true}).object,
    ccwGlobal.Object(),

    // "function"
    // Plain functions and various proxy wrapper cases.
    function(){},
    new Proxy(function(){}, {}),
    new Proxy(createIsHTMLDDA(), {}),
    wrapWithProto(function(){}, null),
    ccwGlobal.Function(),

    // "string"
    "",

    // "number"
    // Int32 and Double numbers.
    0,
    1.23,

    // "boolean"
    true,

    // "symbol"
    Symbol(),

    // "bigint"
    0n,
  ];

  for (let i = 0; i < 500; ++i) {
    let x = xs[i % xs.length];
    assertEq(TypeOf(x), typeof x);
  }
}
for (let i = 0; i < 2; ++i) test();