summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/TypedArray/detached-array-buffer-checks.js
blob: 55256fb29d81aefdb6eaef6c329c296f94ac8489 (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
// Nearly every %TypedArray%.prototype method should throw a TypeError when called
// atop a detached array buffer. Here we check verify that this holds true for
// all relevant functions.
let buffer = new ArrayBuffer(32);
let array  = new Int32Array(buffer);
detachArrayBuffer(buffer);

// A nice poisoned callable to ensure that we fail on a detached buffer check
// before a method attempts to do anything with its arguments.
var POISON = (function() {
    var internalTarget = {};
    var throwForAllTraps =
    new Proxy(internalTarget, { get(target, prop, receiver) {
        assertEq(target, internalTarget);
        assertEq(receiver, throwForAllTraps);
        throw "FAIL: " + prop + " trap invoked";
    }});
    return new Proxy(throwForAllTraps, throwForAllTraps);
});


assertThrowsInstanceOf(() => {
    array.copyWithin(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.entries();
}, TypeError);

assertThrowsInstanceOf(() => {
    array.fill(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.filter(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.find(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.findIndex(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.forEach(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.indexOf(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.includes(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.join(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.keys();
}, TypeError);

assertThrowsInstanceOf(() => {
    array.lastIndexOf(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.map(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.reduce(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.reduceRight(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.reverse();
}, TypeError);

assertThrowsInstanceOf(() => {
    array.slice(POISON, POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.some(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.values();
}, TypeError);

assertThrowsInstanceOf(() => {
    array.every(POISON);
}, TypeError);

assertThrowsInstanceOf(() => {
    array.sort(POISON);
}, TypeError);

if (typeof reportCompare === "function")
    reportCompare(true, true);