| 1 |
// |jit-test| skip-if: getBuildConfiguration("arm") || getBuildConfiguration("arm64") |
| 2 |
// skip on arm, arm64 due to bug 1511615 |
| 3 |
load(libdir + 'asserts.js'); |
| 4 |
|
| 5 |
function test() { |
| 6 |
// non object |
| 7 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(0, "foo"); }, |
| 8 |
"expected _a CData object_ of a function pointer type, got the string \"foo\""); |
| 9 |
// non CData object |
| 10 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(0, ["foo"]); }, |
| 11 |
"expected a _CData_ object of a function pointer type, got the array [\"foo\"]"); |
| 12 |
|
| 13 |
// a CData which is not a pointer |
| 14 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(0, ctypes.int32_t(0)); }, |
| 15 |
"expected a CData object of a function _pointer_ type, got ctypes.int32_t(0)"); |
| 16 |
// a pointer CData which is not a function |
| 17 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(0, ctypes.int32_t.ptr(0)); }, |
| 18 |
"expected a CData object of a _function_ pointer type, got ctypes.int32_t.ptr(ctypes.UInt64(\"0x0\"))"); |
| 19 |
|
| 20 |
// null function |
| 21 |
let func_type = ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, |
| 22 |
[ctypes.int32_t, ctypes.int32_t]).ptr; |
| 23 |
let f0 = func_type(0); |
| 24 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(0, f0); }, |
| 25 |
"expected a CData object of a _non-NULL_ function pointer type, got ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, [ctypes.int32_t, ctypes.int32_t]).ptr(ctypes.UInt64(\"0x0\"))"); |
| 26 |
|
| 27 |
// a function with 2 arguments |
| 28 |
let f1 = func_type(x => x); |
| 29 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(0, f1); }, |
| 30 |
"expected a function accepting exactly one argument, got ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, [ctypes.int32_t, ctypes.int32_t])"); |
| 31 |
|
| 32 |
// non CData in argument 1 |
| 33 |
let func_type2 = ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, |
| 34 |
[ctypes.int32_t.ptr]).ptr; |
| 35 |
let f2 = func_type2(x => x); |
| 36 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(0, f2); }, |
| 37 |
"can't convert the number 0 to the type of argument 1 of ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, [ctypes.int32_t.ptr]).ptr"); |
| 38 |
|
| 39 |
// wrong struct in argument 1 |
| 40 |
let test_struct = ctypes.StructType("test_struct", [{ "x": ctypes.int32_t }]); |
| 41 |
let func_type3 = ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, |
| 42 |
[test_struct]).ptr; |
| 43 |
let f3 = func_type3(x => x); |
| 44 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer({ "x": "foo" }, f3); }, |
| 45 |
"can't convert the string \"foo\" to the 'x' field (int32_t) of test_struct at argument 1 of ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, [test_struct]).ptr"); |
| 46 |
|
| 47 |
// different size in argument 1 |
| 48 |
let func_type4 = ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, |
| 49 |
[ctypes.int32_t]).ptr; |
| 50 |
let f4 = func_type4(x => x); |
| 51 |
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(ctypes.int16_t(0), f4); }, |
| 52 |
"expected an object with the same size as argument 1 of ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, [ctypes.int32_t]).ptr, got ctypes.int16_t(0)"); |
| 53 |
|
| 54 |
let fin = ctypes.CDataFinalizer(ctypes.int32_t(0), f4); |
| 55 |
fin.dispose(); |
| 56 |
assertTypeErrorMessage(() => { ctypes.int32_t(0).value = fin; }, |
| 57 |
"attempting to convert an empty CDataFinalizer"); |
| 58 |
assertTypeErrorMessage(() => { f4(fin); }, |
| 59 |
/attempting to convert an empty CDataFinalizer at argument 1 of ctypes\.FunctionType\(ctypes\.default_abi, ctypes\.int32_t, \[ctypes\.int32_t\]\)\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\)/); |
| 60 |
} |
| 61 |
|
| 62 |
if (typeof ctypes === "object") |
| 63 |
test(); |