16f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// Copyright 2014 the V8 project authors. All rights reserved. 26f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// Redistribution and use in source and binary forms, with or without 36f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// modification, are permitted provided that the following conditions are 46f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// met: 56f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// 66f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// * Redistributions of source code must retain the above copyright 76f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// notice, this list of conditions and the following disclaimer. 86f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// * Redistributions in binary form must reproduce the above 96f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// copyright notice, this list of conditions and the following 106f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// disclaimer in the documentation and/or other materials provided 116f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// with the distribution. 126f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// * Neither the name of Google Inc. nor the names of its 136f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// contributors may be used to endorse or promote products derived 146f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// from this software without specific prior written permission. 156f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// 166f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org 286f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org// Flags: --allow-natives-syntax 296f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org 306f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgfunction f(o) { 316f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org var a = 1; 326f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org if (true) return o.v && a; 336f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org} 346f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org 356f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgf({}); 366f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgf({}); 376f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org%OptimizeFunctionOnNextCall(f); 386f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgassertEquals(1, f({ v: 1 })); 396f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org 406f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org 416f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgfunction f1() { return 1 && 2; }; 426f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgfunction f2() { return 1 || 2; }; 436f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgfunction f3() { return 0 && 2; }; 446f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgfunction f4() { return 0 || 2; }; 456f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org 466f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgfunction test() { 476f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org assertEquals(2, f1()); 486f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org assertEquals(1, f2()); 496f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org assertEquals(0, f3()); 506f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org assertEquals(2, f4()); 516f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org} 526f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org 536f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgtest(); 546f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgtest(); 556f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.org[f1, f2, f3, f4].forEach(function(f) { %OptimizeFunctionOnNextCall(f); }); 566f1040e5c87d24f21c8afc2e08dc26cd1bfc5d1fmachenbach@chromium.orgtest(); 57