osr-follow.js 1.18 KB
Newer Older
1 2 3 4
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
// Flags: --use-osr
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

function foo(a) {
  var sum = 0;
  var inc = a ? 100 : 200;
  for (var i = 0; i < 100000; i++) {
    sum += inc;
  }
  return sum + inc;
}

function bar(a) {
  var sum = 0;
  var inc = a ? 100 : 200;
  var x = a ? 5 : 6;
  var y = a ? 7 : 8;
  for (var i = 0; i < 100000; i++) {
    sum += inc;
  }
  return sum ? x : y;
}

function baz(a) {
  var limit = a ? 100001 : 100002;
  var r = 1;
  var x = a ? 1 : 2;
  var y = a ? 3 : 4;
  for (var i = 0; i < limit; i++) {
    r = r * -1;
  }
  return r > 0 ? x == y : x != y;
}

function qux(a) {
  var limit = a ? 100001 : 100002;
  var r = 1;
  var x = a ? 1 : 2;
  var y = a ? 3 : 4;
  for (var i = 0; i < limit; i++) {
    r = r * -1;
  }
  var w = r > 0 ? x : y;
  var z = r > 0 ? y : x;
  return w === z;
}

function test(func, tv, fv) {
  assertEquals(tv, func(true));
  assertEquals(fv, func(false));
  assertEquals(tv, func(true));
  assertEquals(fv, func(false));
}

test(foo, 10000100, 20000200);
test(bar, 5, 6);
test(baz, true, false);
test(qux, false, false);