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 * typedarray test. 26 * 27 * @test 28 * @run 29 */ 30 31 //JDK-8066217, constructor for arraybuffer not behaving as per spec 32 function checkLength(ab, l) { 33 if (ab.byteLength != l) { 34 throw "length error: " + ab.byteLength + " != " + l; 35 } 36 } 37 checkLength(new ArrayBuffer(), 0); 38 checkLength(new ArrayBuffer(0), 0); 39 checkLength(new ArrayBuffer(1024), 1024); 40 checkLength(new ArrayBuffer(1,2,3), 1); 41 checkLength(new ArrayBuffer([17]), 17); 42 43 var typeDefinitions = [ 44 Int8Array, 45 Uint8Array, 46 Uint8ClampedArray, 47 Int16Array, 48 Uint16Array, 49 Int32Array, 50 Uint32Array, 51 Float32Array, 52 Float64Array, 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 = []; 69 sub.push(new arrayDef(mem1, arrayDef.BYTES_PER_ELEMENT, 3)); 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({ 74 instances:sub, 75 type:arrayDef 76 }); 77 78 all.concat(all, sub); 79 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]; 97 if(!isNaN(p)) { 98 val[p] = 99; 99 } 100 }); 101 102 instance.set(instance, 0); 103 instance.set(instance); 104 instance.set(arr2); 105 instance.subarray(5, 9); 106 instance.subarray(5); 107 });