attila@1183: /* sundar@1482: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. attila@1183: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@1482: * attila@1183: * This code is free software; you can redistribute it and/or modify it attila@1183: * under the terms of the GNU General Public License version 2 only, as attila@1183: * published by the Free Software Foundation. sundar@1482: * attila@1183: * This code is distributed in the hope that it will be useful, but WITHOUT attila@1183: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or attila@1183: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License attila@1183: * version 2 for more details (a copy is included in the LICENSE file that attila@1183: * accompanied this code). sundar@1482: * attila@1183: * You should have received a copy of the GNU General Public License version attila@1183: * 2 along with this work; if not, write to the Free Software Foundation, attila@1183: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@1482: * attila@1183: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA attila@1183: * or visit www.oracle.com if you need additional information or have any attila@1183: * questions. attila@1183: */ attila@1183: attila@1183: /** attila@1183: * JDK-8068573: POJO setter using [] syntax throws an exception attila@1183: * attila@1183: * @test attila@1183: * @run attila@1183: */ attila@1183: attila@1183: // Invoke a setter using []. It's important that the setter returns void. attila@1183: var pb = new (Java.type("jdk.nashorn.test.models.PropertyBind")) attila@1183: var n = "writeOnly"; attila@1183: pb[n] = 2; attila@1183: Assert.assertEquals(pb.peekWriteOnly(), 2); attila@1183: attila@1183: // Invoke an overloaded setter using []. It's important that one of the attila@1183: // overloads returns void. attila@1183: var os = new (Java.type("jdk.nashorn.test.models.OverloadedSetter")) attila@1183: var n2 = "color"; attila@1183: os[n2] = 3; // exercise int overload attila@1183: Assert.assertEquals(os.peekColor(), "3"); attila@1183: os[n2] = "blue"; // exercise string overload attila@1183: Assert.assertEquals(os.peekColor(), "blue"); attila@1183: for each(var x in [42, "42"]) { attila@1183: os[n2] = x; // exercise both overloads in the same call site attila@1183: Assert.assertEquals(os.peekColor(), "42"); attila@1183: } attila@1183: attila@1183: // Invoke an overloaded method using [], repeatedly in the same call attila@1183: // site. It's important that one of the overloads returns void. attila@1183: var n3="foo"; attila@1183: var param=["xyz", 1, "zyx", 2]; attila@1183: var expected=["boo", void 0, "boo", void 0]; attila@1183: for(var i in param) { attila@1183: Assert.assertEquals(os[n3](param[i]), expected[i]); attila@1183: }