Debian Codegraph @

js/src/jit-test/tests/ctypes/incompatible-cdata.js

raw
1 load(libdir + 'asserts.js');
2
3 function test() {
4 assertTypeErrorMessage(() => { ctypes.int32_t(0).address.call(1); },
5 "CData.prototype.address called on incompatible object, got the number 1");
6 assertTypeErrorMessage(() => { ctypes.char.array(10)("abc").readString.call(1); },
7 "CData.prototype.readString called on incompatible object, got the number 1");
8
9 assertTypeErrorMessage(() => { ctypes.char.array(10)("abc").readStringReplaceMalformed.call(1); },
10 "CData.prototype.readStringReplaceMalformed called on incompatible object, got the number 1");
11
12 if (ctypes.int32_t.prototype.toSource) {
13 assertTypeErrorMessage(() => { ctypes.int32_t(0).toSource.call(1); },
14 "CData.prototype.toSource called on incompatible object, got the number 1");
15 }
16
17 let p = Object.getPrototypeOf(ctypes.int32_t());
18 let o = {};
19 Object.setPrototypeOf(o, p);
20 assertTypeErrorMessage(() => { o.readString(); },
21 "CData.prototype.readString called on incompatible object, got <<error converting value to string>>");
22 assertTypeErrorMessage(() => { o.readStringReplaceMalformed(); },
23 "CData.prototype.readStringReplaceMalformed called on incompatible object, got <<error converting value to string>>");
24 }
25
26 if (typeof ctypes === "object")
27 test();