JDK-8027042.js revision 651:7985ec3782b5
113546Sjulian/*
235509Sjb * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
313546Sjulian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
413546Sjulian *
513546Sjulian * This code is free software; you can redistribute it and/or modify it
613546Sjulian * under the terms of the GNU General Public License version 2 only, as
713546Sjulian * published by the Free Software Foundation.
813546Sjulian *
913546Sjulian * This code is distributed in the hope that it will be useful, but WITHOUT
1013546Sjulian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1113546Sjulian * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1213546Sjulian * version 2 for more details (a copy is included in the LICENSE file that
13165967Simp * accompanied this code).
1413546Sjulian *
1513546Sjulian * You should have received a copy of the GNU General Public License version
1613546Sjulian * 2 along with this work; if not, write to the Free Software Foundation,
1713546Sjulian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1813546Sjulian *
1913546Sjulian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2049439Sdeischen * or visit www.oracle.com if you need additional information or have any
2113546Sjulian * questions.
2213546Sjulian */
2313546Sjulian
2413546Sjulian/**
2513546Sjulian * JDK-8027042: Evaluation order for binary operators can be improved
2613546Sjulian *
2713546Sjulian * @test
2813546Sjulian * @run
2950476Speter */
3024518Sjb
3113546Sjulian// var with getter side effect
3213546SjulianObject.defineProperty(this, "a", { get: function() {print("get a"); return 1; }});
3313546Sjulian
3413546Sjulian// var with both getter and conversion side effect
3513546SjulianObject.defineProperty(this, "b", { get: function() {print("get b"); return {valueOf: function() { print("conv b"); return 10; }}; }});
3636830Sjb
3736830Sjb(function() {
3813546Sjulian    // var with toPrimitive conversion side effect
3913546Sjulian    var c = {valueOf: function() { print("conv c"); return 100; }};
40103388Smini
4113546Sjulian    print(b + (c + a));
42174112Sdeischen    print(b + (c + b));
43174112Sdeischen    print(b + (a + b));
4495948Sarchie    print(b + (b + c));
4571581Sdeischen    print(b + (b + c));
4613546Sjulian    print(b + (c + (a - b)));
4795948Sarchie    print(b + (c + (c - b)));
4895948Sarchie    print(b + (c + (b - c)));
49113658Sdeischen    print(b + (b + (a ? 2 : 3)));
5095948Sarchie    print(b + (b + (b ? 2 : 3)));
5195948Sarchie    print(b + (b + (c ? 2 : 3)));
52123312Sdavidxu    print(b + ((-c) + (-a)));
53103419Smini    print(b + ((-c) + (-b)));
54123312Sdavidxu    print(b + ((-c) + (-c)));
5595948Sarchie    try { print(b + new a); } catch (e) {}
5695948Sarchie    try { print(b + new b); } catch (e) {}
5795948Sarchie    try { print(b + new c); } catch (e) {}
58})();
59