1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --allow-natives-syntax
6//
7var f = (function() {
8  "use asm";
9  function f(x, y) {
10    return x - y;
11  }
12  return f;
13})();
14
15var counter = 0;
16
17var deopt = { toString : function() {
18  %DeoptimizeFunction(f);
19  counter++;
20  return "2";
21} };
22
23var o = { toString : function() {
24  counter++;
25  return "1";
26} };
27
28counter = 0;
29assertEquals(1, f(deopt, o));
30assertEquals(2, counter);
31
32%OptimizeFunctionOnNextCall(f);
33counter = 0;
34assertEquals(-1, f(o, deopt));
35assertEquals(2, counter);
36
37%OptimizeFunctionOnNextCall(f);
38counter = 0;
39assertEquals(0, f(deopt, deopt));
40assertEquals(2, counter);
41