test/script/basic/JDK-8026701.js

changeset 0
b1a7da25b547
child 962
ac62e33a99b0
equal deleted inserted replaced
-1:000000000000 0:b1a7da25b547
1 /*
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * JDK-8026701: Array.prototype.splice is slow on dense arrays
26 *
27 * @test
28 * @run
29 */
30
31 function testSplice(arr, e1, e2, e3) {
32 try {
33 print(arr);
34 print(arr.splice(3, 0, e1, e2, e3));
35 print(arr);
36 print(arr.splice(2, 3));
37 print(arr);
38 print(arr.splice(2, 3, arr[2], arr[3], arr[4]));
39 print(arr);
40 print(arr.splice(20, 10));
41 print(arr);
42 print(arr.splice(arr.length, 0, e1, e2, e3));
43 print(arr);
44 print(arr.splice(0, 2, arr[0], arr[1], arr[2], arr[3]));
45 print(arr);
46 } catch (error) {
47 print(error);
48 }
49 }
50
51 function convert(array, type) {
52 return (typeof Java === "undefined") ? array : Java.from(Java.to(array, type));
53 }
54
55 // run some splice tests on all dense array implementations
56 testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, -2, -3);
57 testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, -2, -3);
58 testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "double[]"), -1, -2, -3);
59 testSplice(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], -1, -2, -3);
60
61 // test array conversion during splice
62 testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, "-2", "-3");
63 testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, -2.5, -3.5);
64 testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, "-2", "-3");
65 testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, -2.5, -3.5);
66 testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "double[]"), -1, "-2", "-3");
67
68 // test combination with defined elements
69 testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13}), -1, -2, -3);
70 testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, writable: false}), -1, -2, -3);
71 testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, configurable: false}), -1, -2, -3);
72 testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, writable: false, configurable: false}), -1, -2, -3);

mercurial