Debian Codegraph @

js/src/jit-test/tests/ctypes/pointer.js

raw
1 load(libdir + 'asserts.js');
2
3 function test() {
4 let p = ctypes.StructType("foo").ptr(0);
5
6 assertTypeErrorMessage(() => { p.increment(); },
7 "cannot modify pointer of undefined size foo.ptr(ctypes.UInt64(\"0x0\"))");
8 assertTypeErrorMessage(() => { p.decrement(); },
9 "cannot modify pointer of undefined size foo.ptr(ctypes.UInt64(\"0x0\"))");
10
11 assertTypeErrorMessage(() => { let a = p.contents; },
12 "cannot get contents of pointer of undefined size foo.ptr(ctypes.UInt64(\"0x0\"))");
13 assertTypeErrorMessage(() => { p.contents = 1; },
14 "cannot set contents of pointer of undefined size foo.ptr(ctypes.UInt64(\"0x0\"))");
15
16 let p2 = ctypes.int32_t.ptr(0);
17 assertTypeErrorMessage(() => { let a = p2.contents; },
18 "cannot read contents of null pointer ctypes.int32_t.ptr(ctypes.UInt64(\"0x0\"))");
19 assertTypeErrorMessage(() => { p2.contents = 1; },
20 "cannot write contents to null pointer ctypes.int32_t.ptr(ctypes.UInt64(\"0x0\"))");
21 assertTypeErrorMessage(() => { p2.readString(); },
22 "cannot read contents of null pointer ctypes.int32_t.ptr(ctypes.UInt64(\"0x0\"))");
23
24 assertTypeErrorMessage(() => { ctypes.int32_t(0).readString(); },
25 "expected PointerType or ArrayType, got ctypes.int32_t(0)");
26 assertTypeErrorMessage(() => { ctypes.int32_t(0).address().readString(); },
27 /base type ctypes\.int32_t\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\) is not an 8-bit or 16-bit integer or character type/);
28 }
29
30 if (typeof ctypes === "object")
31 test();