summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/typedarray/ensure-non-inline.js
blob: d8859fa6279dd29ccd8ee31f8d23b2cceb5ea642 (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
const constructors = [
    Int8Array,
    Uint8Array,
    Uint8ClampedArray,
    Int16Array,
    Uint16Array,
    Int32Array,
    Uint32Array,
    Float32Array,
    Float64Array ];

function messWith(view, obj) {
    view[0] = 1;
    view[1] = 1;
    view[2] = 2;
    view[3] = 3;
    ensureNonInline(obj);
    assertEq(view[0], 1);
    assertEq(view[1], 1);
    assertEq(view[2], 2);
    assertEq(view[3], 3);
}

function test() {
    // Bufferless
    for (const ctor of constructors) {
        let small = new ctor(4);
        messWith(small, small);
        let big = new ctor(4000);
        messWith(big, big);
    }

    // With buffer, single view, operate on view
    for (const ctor of constructors) {
        let ab = new ArrayBuffer(96);
        const small = new ctor(ab);
        messWith(small, small);
        ab = new ArrayBuffer(4000);
        const big = new ctor(ab);
        messWith(big, big);
    }

    // With buffer, single view, operate on ArrayBuffer
    for (const ctor of constructors) {
        let ab = new ArrayBuffer(96);
        const small = new ctor(ab);
        messWith(small, ab);
        ab = new ArrayBuffer(4000);
        const big = new ctor(ab);
        messWith(big, ab);
    }

    // With buffer, dual view, operate on view
    for (const ctor of constructors) {
        let ab = new ArrayBuffer(96);
        let view0 = new Uint8Array(ab);
        const small = new ctor(ab);
        messWith(small, small);
        ab = new ArrayBuffer(4000);
        view0 = new Uint8Array(ab);
        const big = new ctor(ab);
        messWith(big, big);
    }

    // With buffer, dual view, operate on ArrayBuffer
    for (const ctor of constructors) {
        let ab = new ArrayBuffer(96);
        let view0 = new Uint8Array(ab);
        const small = new ctor(ab);
        messWith(small, ab);
        ab = new ArrayBuffer(4000);
        view0 = new Uint8Array(ab);
        const big = new ctor(ab);
        messWith(big, ab);
    }
}

try {
    ensureNonInline(new Array(3));
    assertEq(false, true);
} catch (e) {
    assertEq(e.message.includes("unhandled type"), true);
}

test();