Debian Codegraph @

js/src/jit-test/tests/ctypes/array-index.js

raw
1 load(libdir + 'asserts.js');
2
3 function test() {
4 let a = ctypes.int32_t.array(10)();
5 assertTypeErrorMessage(() => { let x = a[-1]; },
6 "the string \"-1\" is not a valid array index");
7 assertTypeErrorMessage(() => { a[-1] = 1; },
8 "the string \"-1\" is not a valid array index");
9 assertTypeErrorMessage(() => { a.addressOfElement(-1); },
10 "the number -1 is not a valid array index");
11
12 assertRangeErrorMessage(() => { let x = a[10]; },
13 "array index 10 is out of bounds for array of length 10");
14 assertRangeErrorMessage(() => { a[10] = 1; },
15 "array index 10 is out of bounds for array of length 10");
16 assertRangeErrorMessage(() => { a.addressOfElement(10); },
17 "array index 10 is out of bounds for array of length 10");
18
19 let obj = {
20 toSource() {
21 throw 1;
22 }
23 };
24 assertTypeErrorMessage(() => { a.addressOfElement(obj); },
25 "<<error converting value to string>> is not a valid array index");
26 }
27
28 if (typeof ctypes === "object")
29 test();