summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/number-toString.js
blob: ed076a67538067a71d6f4ec7aae66a3598d45695 (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
function int32() {
  var n = 42;
  for (var i = 0; i < 100; i++) {
    assertEq(n.toString(), "42");
  }
}

function double() {
  var n = 3.14;
  for (var i = 0; i < 100; i++) {
    assertEq(n.toString(), "3.14");
  }
}

function number() {
  var n = 1;
  for (var i = 0; i < 100; i++) {
    assertEq(n.toString(), i > 50 ? "3.14" : "1");
    if (i == 50) {
      n = 3.14;
    }
  }
}

function obj() {
  var o = new Number(42);
  for (var i = 0; i < 100; i++) {
    assertEq(o.toString(), "42");
  }
}

function overwritten() {
  Number.prototype.toString = () => "haha";
  var n = 42;
  for (var i = 0; i < 100; i++) {
    assertEq(n.toString(), "haha");
  }
}

int32();
double();
number();
obj();
overwritten();