test/script/basic/JDK-8068573.js

Tue, 28 Jul 2015 14:52:34 +0530

author
sundar
date
Tue, 28 Jul 2015 14:52:34 +0530
changeset 1482
58791cd01bc9
parent 1183
6ed91931b5a7
permissions
-rw-r--r--

8132092: Nashorn copyright has to be updated
Reviewed-by: jlaskey, hannesw, mhaupt

attila@1183 1 /*
sundar@1482 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
attila@1183 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sundar@1482 4 *
attila@1183 5 * This code is free software; you can redistribute it and/or modify it
attila@1183 6 * under the terms of the GNU General Public License version 2 only, as
attila@1183 7 * published by the Free Software Foundation.
sundar@1482 8 *
attila@1183 9 * This code is distributed in the hope that it will be useful, but WITHOUT
attila@1183 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
attila@1183 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
attila@1183 12 * version 2 for more details (a copy is included in the LICENSE file that
attila@1183 13 * accompanied this code).
sundar@1482 14 *
attila@1183 15 * You should have received a copy of the GNU General Public License version
attila@1183 16 * 2 along with this work; if not, write to the Free Software Foundation,
attila@1183 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sundar@1482 18 *
attila@1183 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
attila@1183 20 * or visit www.oracle.com if you need additional information or have any
attila@1183 21 * questions.
attila@1183 22 */
attila@1183 23
attila@1183 24 /**
attila@1183 25 * JDK-8068573: POJO setter using [] syntax throws an exception
attila@1183 26 *
attila@1183 27 * @test
attila@1183 28 * @run
attila@1183 29 */
attila@1183 30
attila@1183 31 // Invoke a setter using []. It's important that the setter returns void.
attila@1183 32 var pb = new (Java.type("jdk.nashorn.test.models.PropertyBind"))
attila@1183 33 var n = "writeOnly";
attila@1183 34 pb[n] = 2;
attila@1183 35 Assert.assertEquals(pb.peekWriteOnly(), 2);
attila@1183 36
attila@1183 37 // Invoke an overloaded setter using []. It's important that one of the
attila@1183 38 // overloads returns void.
attila@1183 39 var os = new (Java.type("jdk.nashorn.test.models.OverloadedSetter"))
attila@1183 40 var n2 = "color";
attila@1183 41 os[n2] = 3; // exercise int overload
attila@1183 42 Assert.assertEquals(os.peekColor(), "3");
attila@1183 43 os[n2] = "blue"; // exercise string overload
attila@1183 44 Assert.assertEquals(os.peekColor(), "blue");
attila@1183 45 for each(var x in [42, "42"]) {
attila@1183 46 os[n2] = x; // exercise both overloads in the same call site
attila@1183 47 Assert.assertEquals(os.peekColor(), "42");
attila@1183 48 }
attila@1183 49
attila@1183 50 // Invoke an overloaded method using [], repeatedly in the same call
attila@1183 51 // site. It's important that one of the overloads returns void.
attila@1183 52 var n3="foo";
attila@1183 53 var param=["xyz", 1, "zyx", 2];
attila@1183 54 var expected=["boo", void 0, "boo", void 0];
attila@1183 55 for(var i in param) {
attila@1183 56 Assert.assertEquals(os[n3](param[i]), expected[i]);
attila@1183 57 }

mercurial