test/script/basic/typedarrays.js

Tue, 21 Mar 2017 13:41:57 -0700

author
asaha
date
Tue, 21 Mar 2017 13:41:57 -0700
changeset 2160
1df40fe54cd6
parent 1258
4ba23f4c0ed6
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@962 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
attila@962 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
attila@962 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@962 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /**
aoqi@0 25 * typedarray test.
aoqi@0 26 *
aoqi@0 27 * @test
attila@962 28 * @run
aoqi@0 29 */
aoqi@0 30
lagergren@1258 31 //JDK-8066217, constructor for arraybuffer not behaving as per spec
lagergren@1258 32 function checkLength(ab, l) {
lagergren@1258 33 if (ab.byteLength != l) {
lagergren@1258 34 throw "length error: " + ab.byteLength + " != " + l;
lagergren@1258 35 }
lagergren@1258 36 }
lagergren@1258 37 checkLength(new ArrayBuffer(), 0);
lagergren@1258 38 checkLength(new ArrayBuffer(0), 0);
lagergren@1258 39 checkLength(new ArrayBuffer(1024), 1024);
lagergren@1258 40 checkLength(new ArrayBuffer(1,2,3), 1);
lagergren@1258 41 checkLength(new ArrayBuffer([17]), 17);
aoqi@0 42
aoqi@0 43 var typeDefinitions = [
attila@962 44 Int8Array,
attila@962 45 Uint8Array,
attila@962 46 Uint8ClampedArray,
attila@962 47 Int16Array,
attila@962 48 Uint16Array,
attila@962 49 Int32Array,
attila@962 50 Uint32Array,
attila@962 51 Float32Array,
attila@962 52 Float64Array,
aoqi@0 53 ];
aoqi@0 54
aoqi@0 55 var mem1 = new ArrayBuffer(1024);
aoqi@0 56 mem1.byteLength;
aoqi@0 57 mem1.slice(512);
aoqi@0 58 mem1.slice(512, 748);
aoqi@0 59
aoqi@0 60 var size = 128;
aoqi@0 61 var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
aoqi@0 62 var arr2 = [99, 89];
aoqi@0 63 var partial = [];
aoqi@0 64 var all = [];
aoqi@0 65
aoqi@0 66 typeDefinitions.forEach(function(arrayDef) {
aoqi@0 67 var p = arrayDef.prototype;
aoqi@0 68 var sub = [];
attila@962 69 sub.push(new arrayDef(mem1, arrayDef.BYTES_PER_ELEMENT, 3));
aoqi@0 70 sub.push(new arrayDef(size));
aoqi@0 71 sub.push(new arrayDef(arr));
aoqi@0 72 //push the instances, they will be reused to do instance based construction
aoqi@0 73 partial.push({
attila@962 74 instances:sub,
aoqi@0 75 type:arrayDef
aoqi@0 76 });
attila@962 77
aoqi@0 78 all.concat(all, sub);
attila@962 79
aoqi@0 80 });
aoqi@0 81
aoqi@0 82 partial.forEach(function(inst) {
aoqi@0 83 // build new instances with TypeArray instance as parameter.
aoqi@0 84 partial.forEach(function(other) {
aoqi@0 85 other.instances.forEach(function(otherInstance) {
aoqi@0 86 var ii = new inst.type(otherInstance);
aoqi@0 87 all.push(ii);
aoqi@0 88 });
aoqi@0 89 })
aoqi@0 90 });
aoqi@0 91
aoqi@0 92 all.forEach(function(instance) {
aoqi@0 93 // cover instance props and functions
aoqi@0 94 var arr = Object.getOwnPropertyNames(instance);
aoqi@0 95 arr.forEach(function(p) {
aoqi@0 96 var val = instance[p];
attila@963 97 if(!isNaN(p)) {
aoqi@0 98 val[p] = 99;
attila@962 99 }
aoqi@0 100 });
attila@962 101
aoqi@0 102 instance.set(instance, 0);
aoqi@0 103 instance.set(instance);
aoqi@0 104 instance.set(arr2);
aoqi@0 105 instance.subarray(5, 9);
aoqi@0 106 instance.subarray(5);
aoqi@0 107 });

mercurial