summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/testTypedArrayMaybeUndefined.js
blob: e2dc941928dd79c25e42d2e91b46165558203f72 (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
// Testing GETELEM and SETELEM on a typed array where the
// type set of the object may include undefined or other
// primitive types.

// Argument x has type {void, double, Uint16Array}.
function testSet(x) {
    var y = 0;
    for (var i=0; i<40; i++) {
        x[i] = 3;
    }
    return x[10];
}

// Argument x has type {void, int32, Uint16Array}.
function testGet(x) {
    var y = 0;
    for (var i=0; i<40; i++) {
        y += x[i];
    }
    return y;
}

var arr = new Uint16Array(40);
assertEq(testSet(arr), 3);
try {
    testSet(undefined);
} catch(e) {
    assertEq(e instanceof TypeError, true);
}
try {
    testSet(4.5);
} catch(e) {
    assertEq(e instanceof TypeError, true);
}

assertEq(testGet(arr), 120);
try {
    testGet(undefined);
} catch(e) {
    assertEq(e instanceof TypeError, true);
}
try {
    testGet(12345);
} catch(e) {
    assertEq(e instanceof TypeError, true);
}