osr-while-let.js 1.23 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: --allow-natives-syntax --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

"use strict";

function test(expected, func) {
  assertEquals(expected, func());
  assertEquals(expected, func());
  assertEquals(expected, func());
}

function foo() {
  var result = 0;
  {
    let x = 0;
    var temp_x = x;
    var first = 1;
    outer: while (true) {
      let x = temp_x;
      if (first == 1) first = 0;
      else x = x + 1 | 0;
      var flag = 1;
      for (; flag == 1; (flag = 0, temp_x = x)) {
        if (x < 2) {
          result = x; %OptimizeOsr();
29
          %PrepareFunctionForOptimization(foo);
30 31 32 33 34 35 36 37 38
        } else {
          break outer;
        }
      }
      if (flag == 1) break;
    }
  }
  return result;
}
39
%PrepareFunctionForOptimization(foo);
40 41 42 43 44 45 46 47 48 49 50 51

test(1, foo);


function smo() {
  var result = 0;
  {
    let x = 11;
    outer: while (true) {
      let y = x;
      for (var i = 0; i < 5; i++) {
        %OptimizeOsr();
52
        %PrepareFunctionForOptimization(smo);
53 54 55 56 57 58 59
        if (i) break outer;
        else result = y;
      }
    }
  }
  return result;
}
60
%PrepareFunctionForOptimization(smo);
61 62

test(11, smo);