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