| 1 |
load(libdir + 'asserts.js'); |
| 2 |
|
| 3 |
function test() { |
| 4 |
assertTypeErrorMessage(() => { ctypes.StructType("a").define.call(1); }, |
| 5 |
"StructType.prototype.define called on incompatible object, got the number 1"); |
| 6 |
assertTypeErrorMessage(() => { ctypes.StructType("a").define.call(ctypes.int32_t); }, |
| 7 |
"StructType.prototype.define called on non-StructType, got ctypes.int32_t"); |
| 8 |
|
| 9 |
let p = Object.getPrototypeOf(ctypes.StructType("a", [ { "x": ctypes.int32_t, } ])()); |
| 10 |
let o = {}; |
| 11 |
Object.setPrototypeOf(o, p); |
| 12 |
assertTypeErrorMessage(() => { let a = o.x; }, |
| 13 |
"StructType property getter called on incompatible object, got <<error converting value to string>>"); |
| 14 |
assertTypeErrorMessage(() => { o.x = 1; }, |
| 15 |
"StructType property setter called on incompatible object, got <<error converting value to string>>"); |
| 16 |
|
| 17 |
o = ctypes.int32_t(0); |
| 18 |
Object.setPrototypeOf(o, p); |
| 19 |
assertTypeErrorMessage(() => { let a = o.x; }, |
| 20 |
"StructType property getter called on non-StructType CData, got ctypes.int32_t(0)"); |
| 21 |
assertTypeErrorMessage(() => { o.x = 1; }, |
| 22 |
"StructType property setter called on non-StructType CData, got ctypes.int32_t(0)"); |
| 23 |
|
| 24 |
assertTypeErrorMessage(() => { ctypes.StructType("a", [])().addressOfField.call(1); }, |
| 25 |
"StructType.prototype.addressOfField called on incompatible object, got the number 1"); |
| 26 |
assertTypeErrorMessage(() => { ctypes.StructType("a", [])().addressOfField.call(ctypes.int32_t(0)); }, |
| 27 |
"StructType.prototype.addressOfField called on non-StructType CData, got ctypes.int32_t(0)"); |
| 28 |
} |
| 29 |
|
| 30 |
if (typeof ctypes === "object") |
| 31 |
test(); |