author | hannesw |
Fri, 03 Feb 2017 13:28:00 +0100 | |
changeset 43555 | 1bb10bccf057 |
parent 29537 | e6615d669728 |
permissions | -rw-r--r-- |
17965 | 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. |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
4 |
* |
17965 | 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. |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
8 |
* |
17965 | 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). |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
14 |
* |
17965 | 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. |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
18 |
* |
17965 | 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 |
* typedarray test. |
|
26 |
* |
|
27 |
* @test |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
28 |
* @run |
17965 | 29 |
*/ |
30 |
||
29537
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
31 |
//JDK-8066217, constructor for arraybuffer not behaving as per spec |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
32 |
function checkLength(ab, l) { |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
33 |
if (ab.byteLength != l) { |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
34 |
throw "length error: " + ab.byteLength + " != " + l; |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
35 |
} |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
36 |
} |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
37 |
checkLength(new ArrayBuffer(), 0); |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
38 |
checkLength(new ArrayBuffer(0), 0); |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
39 |
checkLength(new ArrayBuffer(1024), 1024); |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
40 |
checkLength(new ArrayBuffer(1,2,3), 1); |
e6615d669728
8066217: ArrayBuffer constructor was erroneous with zero args
lagergren
parents:
24778
diff
changeset
|
41 |
checkLength(new ArrayBuffer([17]), 17); |
17965 | 42 |
|
43 |
var typeDefinitions = [ |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
44 |
Int8Array, |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
45 |
Uint8Array, |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
46 |
Uint8ClampedArray, |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
47 |
Int16Array, |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
48 |
Uint16Array, |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
49 |
Int32Array, |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
50 |
Uint32Array, |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
51 |
Float32Array, |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
52 |
Float64Array, |
17965 | 53 |
]; |
54 |
||
55 |
var mem1 = new ArrayBuffer(1024); |
|
56 |
mem1.byteLength; |
|
57 |
mem1.slice(512); |
|
58 |
mem1.slice(512, 748); |
|
59 |
||
60 |
var size = 128; |
|
61 |
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
|
62 |
var arr2 = [99, 89]; |
|
63 |
var partial = []; |
|
64 |
var all = []; |
|
65 |
||
66 |
typeDefinitions.forEach(function(arrayDef) { |
|
67 |
var p = arrayDef.prototype; |
|
68 |
var sub = []; |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
69 |
sub.push(new arrayDef(mem1, arrayDef.BYTES_PER_ELEMENT, 3)); |
17965 | 70 |
sub.push(new arrayDef(size)); |
71 |
sub.push(new arrayDef(arr)); |
|
72 |
//push the instances, they will be reused to do instance based construction |
|
73 |
partial.push({ |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
74 |
instances:sub, |
17965 | 75 |
type:arrayDef |
76 |
}); |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
77 |
|
17965 | 78 |
all.concat(all, sub); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
79 |
|
17965 | 80 |
}); |
81 |
||
82 |
partial.forEach(function(inst) { |
|
83 |
// build new instances with TypeArray instance as parameter. |
|
84 |
partial.forEach(function(other) { |
|
85 |
other.instances.forEach(function(otherInstance) { |
|
86 |
var ii = new inst.type(otherInstance); |
|
87 |
all.push(ii); |
|
88 |
}); |
|
89 |
}) |
|
90 |
}); |
|
91 |
||
92 |
all.forEach(function(instance) { |
|
93 |
// cover instance props and functions |
|
94 |
var arr = Object.getOwnPropertyNames(instance); |
|
95 |
arr.forEach(function(p) { |
|
96 |
var val = instance[p]; |
|
24720 | 97 |
if(!isNaN(p)) { |
17965 | 98 |
val[p] = 99; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
99 |
} |
17965 | 100 |
}); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24720
diff
changeset
|
101 |
|
17965 | 102 |
instance.set(instance, 0); |
103 |
instance.set(instance); |
|
104 |
instance.set(arr2); |
|
105 |
instance.subarray(5, 9); |
|
106 |
instance.subarray(5); |
|
107 |
}); |