aboutsummaryrefslogtreecommitdiff
path: root/test/script/basic/typedarrays.js
blob: d66c79b8a7abb70444a56f9c64517052bddec2d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/**
 * typedarray test.
 *
 * @test
 * @run
 */

//JDK-8066217, constructor for arraybuffer not behaving as per spec
function checkLength(ab, l) {
    if (ab.byteLength != l) {
        throw "length error: " + ab.byteLength + " != " + l;
    }
}
checkLength(new ArrayBuffer(), 0);
checkLength(new ArrayBuffer(0), 0);
checkLength(new ArrayBuffer(1024), 1024);
checkLength(new ArrayBuffer(1,2,3), 1);
checkLength(new ArrayBuffer([17]), 17);

var typeDefinitions = [
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array,
];

var mem1 = new ArrayBuffer(1024);
mem1.byteLength;
mem1.slice(512);
mem1.slice(512, 748);

var size = 128;
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var arr2 = [99, 89];
var partial = [];
var all = [];

typeDefinitions.forEach(function(arrayDef) {
    var p = arrayDef.prototype;
    var sub = [];
    sub.push(new arrayDef(mem1, arrayDef.BYTES_PER_ELEMENT, 3));
    sub.push(new arrayDef(size));
    sub.push(new arrayDef(arr));
    //push the instances, they will be reused to do instance based construction
    partial.push({
        instances:sub,
        type:arrayDef
    });

    all.concat(all, sub);

});

partial.forEach(function(inst) {
    // build new instances with TypeArray instance as parameter.
    partial.forEach(function(other) {
        other.instances.forEach(function(otherInstance) {
            var ii = new inst.type(otherInstance);
            all.push(ii);
        });
    })
});

all.forEach(function(instance) {
    // cover instance props and functions
    var arr = Object.getOwnPropertyNames(instance);
    arr.forEach(function(p) {
        var val = instance[p];
        if(!isNaN(p)) {
            val[p] = 99;
        }
    });

    instance.set(instance, 0);
    instance.set(instance);
    instance.set(arr2);
    instance.subarray(5, 9);
    instance.subarray(5);
});