author | sundar |
Wed, 06 May 2015 20:04:42 +0530 | |
changeset 30394 | 72a59e4dffea |
parent 28881 | 0008daeef352 |
child 31925 | 85c87bc2f1f3 |
permissions | -rw-r--r-- |
28881
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
1 |
/* |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
2 |
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
4 |
* |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
8 |
* |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
13 |
* accompanied this code). |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
14 |
* |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
18 |
* |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
21 |
* questions. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
22 |
*/ |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
23 |
|
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
24 |
/** |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
25 |
* JDK-8072596: Arrays.asList results in ClassCastException with a JS array |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
26 |
* |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
27 |
* @test |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
28 |
* @run |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
29 |
*/ |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
30 |
var arr = java.util.Arrays.asList("hello world".split(' ')); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
31 |
// We split it into a list of two elements: [hello, world] |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
32 |
Assert.assertTrue(arr instanceof java.util.List); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
33 |
Assert.assertEquals(arr.length, 2); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
34 |
Assert.assertEquals(arr[0], "hello"); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
35 |
Assert.assertEquals(arr[1], "world"); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
36 |
|
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
37 |
var Jdk8072596TestSubject = Java.type("jdk.nashorn.test.models.Jdk8072596TestSubject"); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
38 |
var testSubject = new Jdk8072596TestSubject({bar: 0}); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
39 |
testSubject.test1(true, {foo: 1}, {bar: 2}); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
40 |
testSubject.test2(true, {foo: 1}, {bar: 2}, {baz: 3}, {bing: 4}); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
41 |
var h = "h"; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
42 |
var ello = "ello"; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
43 |
testSubject.test3(true, {foo: 5}, /* ConsString, why not */ h + ello, [6, 7], 8); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
44 |
Jdk8072596TestSubject.test4({foo: 9}); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
45 |
|
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
46 |
// Test wrapping setters arguments and unwrapping getters return values on list. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
47 |
var list = new java.util.ArrayList(); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
48 |
list.add(null); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
49 |
var obj0 = {valueOf: function() { return 0; }}; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
50 |
var obj1 = {foo: 10}; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
51 |
list[obj0] = obj1; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
52 |
testSubject.testListHasWrappedObject(list); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
53 |
// NOTE: can't use Assert.assertSame(obj1, list[obj0]), as the arguments would end up being wrapped... |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
54 |
Assert.assertTrue(obj1 === list[obj0]); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
55 |
|
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
56 |
// Test wrapping setters arguments and unwrapping getters return values on array. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
57 |
var arr2 = new (Java.type("java.lang.Object[]"))(1); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
58 |
var obj2 = {bar: 11}; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
59 |
arr2[obj0] = obj2; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
60 |
testSubject.testArrayHasWrappedObject(arr2); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
61 |
Assert.assertTrue(obj2 === arr2[obj0]); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
62 |
|
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
63 |
// Test wrapping setters index and arguments and getters index, and unwrapping getters return values on map. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
64 |
// Since ScriptObjectMirror.equals() uses underlying ScriptObject identity, using them as map keys works. |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
65 |
var map = new java.util.HashMap(); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
66 |
var obj3 = {bar: 12}; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
67 |
map[obj0] = obj3; |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
68 |
testSubject.testMapHasWrappedObject(map, obj0); |
0008daeef352
8072596: Arrays.asList results in ClassCastException with a JS array
attila
parents:
diff
changeset
|
69 |
Assert.assertTrue(obj3 === map[obj0]); |