10a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// Copyright 2011 the V8 project authors. All rights reserved.
20a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// Redistribution and use in source and binary forms, with or without
30a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// modification, are permitted provided that the following conditions are
40a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// met:
50a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//
60a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//     * Redistributions of source code must retain the above copyright
70a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//       notice, this list of conditions and the following disclaimer.
80a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//     * Redistributions in binary form must reproduce the above
90a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//       copyright notice, this list of conditions and the following
100a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//       disclaimer in the documentation and/or other materials provided
110a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//       with the distribution.
120a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//     * Neither the name of Google Inc. nor the names of its
130a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//       contributors may be used to endorse or promote products derived
140a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//       from this software without specific prior written permission.
150a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org//
160a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
170a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
180a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
190a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
200a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
210a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
220a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
230a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
240a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
250a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
260a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
270a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org
28394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com// Flags: --allow-natives-syntax
290a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org
30394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comfunction outer () {
31394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  var val = 0;
320a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org
33394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  function foo () {
34394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    val = 0;
35394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    val;
36394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    var z = false;
37394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    var y = true;
38394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    if (!z) {
39394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com      while (z = !z) {
40394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com        if (y) val++;
41394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com      }
42394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    }
43394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    return val++;
44394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  }
450a4e901cdfb5505a896d30aa8c2e04fce0fbe069vegorov@chromium.org
46394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com  return foo;
47394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com}
48394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
49394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
50394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comvar foo = outer();
51394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com
52394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comassertEquals(1, foo());
53394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comassertEquals(1, foo());
54394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.com    %OptimizeFunctionOnNextCall(foo);
55394dbcf9009cf5203b6d85e8b515fcff072040f3erik.corry@gmail.comassertEquals(1, foo());
56