attila@1239: /* attila@1239: * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. attila@1239: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@1239: * attila@1239: * This code is free software; you can redistribute it and/or modify it attila@1239: * under the terms of the GNU General Public License version 2 only, as attila@1239: * published by the Free Software Foundation. attila@1239: * attila@1239: * This code is distributed in the hope that it will be useful, but WITHOUT attila@1239: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or attila@1239: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License attila@1239: * version 2 for more details (a copy is included in the LICENSE file that attila@1239: * accompanied this code). attila@1239: * attila@1239: * You should have received a copy of the GNU General Public License version attila@1239: * 2 along with this work; if not, write to the Free Software Foundation, attila@1239: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@1239: * attila@1239: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA attila@1239: * or visit www.oracle.com if you need additional information or have any attila@1239: * questions. attila@1239: */ attila@1239: attila@1239: /** attila@1239: * JDK-8072596: Arrays.asList results in ClassCastException with a JS array attila@1239: * attila@1239: * @test attila@1239: * @run attila@1239: */ attila@1239: var arr = java.util.Arrays.asList("hello world".split(' ')); attila@1239: // We split it into a list of two elements: [hello, world] attila@1239: Assert.assertTrue(arr instanceof java.util.List); attila@1239: Assert.assertEquals(arr.length, 2); attila@1239: Assert.assertEquals(arr[0], "hello"); attila@1239: Assert.assertEquals(arr[1], "world"); attila@1239: attila@1239: var Jdk8072596TestSubject = Java.type("jdk.nashorn.test.models.Jdk8072596TestSubject"); attila@1239: var testSubject = new Jdk8072596TestSubject({bar: 0}); attila@1239: testSubject.test1(true, {foo: 1}, {bar: 2}); attila@1239: testSubject.test2(true, {foo: 1}, {bar: 2}, {baz: 3}, {bing: 4}); attila@1239: var h = "h"; attila@1239: var ello = "ello"; attila@1239: testSubject.test3(true, {foo: 5}, /* ConsString, why not */ h + ello, [6, 7], 8); attila@1239: Jdk8072596TestSubject.test4({foo: 9}); attila@1239: attila@1239: // Test wrapping setters arguments and unwrapping getters return values on list. attila@1239: var list = new java.util.ArrayList(); attila@1239: list.add(null); attila@1239: var obj0 = {valueOf: function() { return 0; }}; attila@1239: var obj1 = {foo: 10}; attila@1239: list[obj0] = obj1; attila@1239: testSubject.testListHasWrappedObject(list); attila@1239: // NOTE: can't use Assert.assertSame(obj1, list[obj0]), as the arguments would end up being wrapped... attila@1239: Assert.assertTrue(obj1 === list[obj0]); attila@1239: attila@1239: // Test wrapping setters arguments and unwrapping getters return values on array. attila@1239: var arr2 = new (Java.type("java.lang.Object[]"))(1); attila@1239: var obj2 = {bar: 11}; attila@1239: arr2[obj0] = obj2; attila@1239: testSubject.testArrayHasWrappedObject(arr2); attila@1239: Assert.assertTrue(obj2 === arr2[obj0]); attila@1239: attila@1239: // Test wrapping setters index and arguments and getters index, and unwrapping getters return values on map. attila@1239: // Since ScriptObjectMirror.equals() uses underlying ScriptObject identity, using them as map keys works. attila@1239: var map = new java.util.HashMap(); attila@1239: var obj3 = {bar: 12}; attila@1239: map[obj0] = obj3; attila@1239: testSubject.testMapHasWrappedObject(map, obj0); attila@1239: Assert.assertTrue(obj3 === map[obj0]);