1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/script/basic/JDK-8015267.js Wed Apr 27 01:36:41 2016 +0800 1.3 @@ -0,0 +1,109 @@ 1.4 +/* 1.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * JDK-8015267: have a List/Deque adapter for JS array-like objects 1.29 + * 1.30 + * @test 1.31 + * @run 1.32 + */ 1.33 + 1.34 +var a = ['a', 'b', 'c', 'd'] 1.35 + 1.36 +var l = Java.to(a, java.util.List) 1.37 +print(l instanceof java.util.List) 1.38 +print(l instanceof java.util.Deque) 1.39 + 1.40 +print(l[0]) 1.41 +print(l[1]) 1.42 +print(l[2]) 1.43 +print(l[3]) 1.44 + 1.45 +print(l.size()) 1.46 + 1.47 +l.push('x') 1.48 +print(a) 1.49 + 1.50 +l.addLast('y') 1.51 +print(a) 1.52 + 1.53 +print(l.pop()) 1.54 +print(l.removeLast()) 1.55 +print(a) 1.56 + 1.57 +l.add('e') 1.58 +l.add(5, 'f') 1.59 +print(a) 1.60 + 1.61 +l.add(0, 'z') 1.62 +print(a) 1.63 + 1.64 +l.add(2, 'x') 1.65 +print(a) 1.66 + 1.67 +l[7] = 'g' 1.68 +print(a) 1.69 + 1.70 +try { l.add(15, '') } catch(e) { print(e.class) } 1.71 +try { l.remove(15) } catch(e) { print(e.class) } 1.72 +try { l.add(-1, '') } catch(e) { print(e.class) } 1.73 +try { l.remove(-1) } catch(e) { print(e.class) } 1.74 + 1.75 +l.remove(7) 1.76 +l.remove(2) 1.77 +l.remove(0) 1.78 +print(a) 1.79 + 1.80 +print(l.peek()) 1.81 +print(l.peekFirst()) 1.82 +print(l.peekLast()) 1.83 + 1.84 +print(l.element()) 1.85 +print(l.getFirst()) 1.86 +print(l.getLast()) 1.87 + 1.88 +l.offer('1') 1.89 +l.offerFirst('2') 1.90 +l.offerLast('3') 1.91 +print(a) 1.92 + 1.93 +a = ['1', '2', 'x', '3', '4', 'x', '5', '6', 'x', '7', '8'] 1.94 +print(a) 1.95 +var l = Java.to(a, java.util.List) 1.96 +l.removeFirstOccurrence('x') 1.97 +print(a) 1.98 +l.removeLastOccurrence('x') 1.99 +print(a) 1.100 + 1.101 +var empty = Java.to([], java.util.List) 1.102 +try { empty.pop() } catch(e) { print(e.class) } 1.103 +try { empty.removeFirst() } catch(e) { print(e.class) } 1.104 +try { empty.removeLast() } catch(e) { print(e.class) } 1.105 + 1.106 +try { empty.element() } catch(e) { print(e.class) } 1.107 +try { empty.getFirst() } catch(e) { print(e.class) } 1.108 +try { empty.getLast() } catch(e) { print(e.class) } 1.109 + 1.110 +print(empty.peek()) 1.111 +print(empty.peekFirst()) 1.112 +print(empty.peekLast())