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