osr-regex-id.js 964 Bytes
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

function id(f) { return f; }

function foo(a) {
  var r = /\0/;
  for (var i = 0; i < 10; i++) {
12
    if (a) %OptimizeOsr();
13 14 15 16 17 18
  }
  return r;
}

function bar(a) {
  for (var i = 0; i < 10; i++) {
19
    if (a) %OptimizeOsr();
20 21 22 23 24 25 26
    var r = /\0/;
  }
  return r;
}

function baz(a) {
  for (var i = 0; i < 10; i++) {
27
    if (a) %OptimizeOsr();
28 29 30 31 32 33 34
  }
  return /\0/;
}

function qux(a) {
  for (var i = 0; i < 10; i++) {
    if (i > 5 && a) {
35
      %OptimizeOsr();
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    } else {
      var r = /\0/;
    }
  }
  return r;
}

function test(f) {
  // Test the reference equality of regex's created in OSR'd function.
  var x = f(false);
  assertEquals(x, f(true));
  assertEquals(x, f(true));
  assertEquals(x, f(true));
}

test(foo);
test(bar);
test(baz);
test(qux);