summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/TypedObject/jit-prefix.js
blob: 198406aafde3eff2ff6127223cead0c2a53d0715 (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
if (!this.hasOwnProperty("TypedObject"))
  quit();

setJitCompilerOption("ion.warmup.trigger", 30);

var PointType2 =
  new TypedObject.StructType({
    x: TypedObject.float64,
    y: TypedObject.float64});

var PointType3 =
  new TypedObject.StructType({
    x: TypedObject.float64,
    y: TypedObject.float64,
    z: TypedObject.float64});

function xPlusY(p) {
  return p.x + p.y;
}

function xPlusYTweak(p) {
  p.x = 22;
  return xPlusY(p);
}

function foo() {
  var N = 100;
  var points = [];
  var obj;
  var s;

  for (var i = 0; i < N; i++) {
    if ((i % 2) == 0)
      obj = new PointType2({x: i, y: i+1});
    else
      obj = new PointType3({x: i, y: i+1, z: i+2});

    assertEq(xPlusY(obj), i + i + 1);
    assertEq(xPlusYTweak(obj), 22 + i + 1);
  }
}

foo();