Debian Codegraph @

js/src/jit-test/tests/basic/testTypedArrayMaybeUndefined.js

raw
1 // Testing GETELEM and SETELEM on a typed array where the
2 // type set of the object may include undefined or other
3 // primitive types.
4
5 // Argument x has type {void, double, Uint16Array}.
6 function testSet(x) {
7 var y = 0;
8 for (var i=0; i<40; i++) {
9 x[i] = 3;
10 }
11 return x[10];
12 }
13
14 // Argument x has type {void, int32, Uint16Array}.
15 function testGet(x) {
16 var y = 0;
17 for (var i=0; i<40; i++) {
18 y += x[i];
19 }
20 return y;
21 }
22
23 var arr = new Uint16Array(40);
24 assertEq(testSet(arr), 3);
25 try {
26 testSet(undefined);
27 } catch(e) {
28 assertEq(e instanceof TypeError, true);
29 }
30 try {
31 testSet(4.5);
32 } catch(e) {
33 assertEq(e instanceof TypeError, true);
34 }
35
36 assertEq(testGet(arr), 120);
37 try {
38 testGet(undefined);
39 } catch(e) {
40 assertEq(e instanceof TypeError, true);
41 }
42 try {
43 testGet(12345);
44 } catch(e) {
45 assertEq(e instanceof TypeError, true);
46 }