Debian Codegraph @

js/src/jit-test/tests/ctypes/conversion-native-function.js

raw
1 // Type conversion error for native function should report its name and type
2 // in C style.
3
4 load(libdir + 'asserts.js');
5
6 function test() {
7 let lib;
8 try {
9 lib = ctypes.open(ctypes.libraryName("m"));
10 } catch (e) {
11 }
12 if (!lib)
13 return;
14
15 let func = lib.declare("hypot",
16 ctypes.default_abi,
17 ctypes.double,
18 ctypes.double, ctypes.double);
19 assertTypeErrorMessage(() => { func(1, "xyzzy"); },
20 "can't pass the string \"xyzzy\" to argument 2 of double hypot(double, double)");
21
22 // test C style source for various types
23 let test_struct = ctypes.StructType("test_struct", [{ "x": ctypes.int32_t }]);
24 let test_func = ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t,
25 [ctypes.int32_t]).ptr;
26 func = lib.declare("hypot",
27 ctypes.default_abi,
28 ctypes.double,
29 ctypes.double, ctypes.int32_t.ptr.ptr.ptr.array(),
30 test_struct, test_struct.ptr.ptr,
31 test_func, test_func.ptr.ptr.ptr, "...");
32 assertTypeErrorMessage(() => { func("xyzzy", 1, 2, 3, 4, 5); },
33 "can't pass the string \"xyzzy\" to argument 1 of double hypot(double, int32_t****, struct test_struct, struct test_struct**, void* (*)(int32_t), void* (****)(int32_t), ...)");
34 }
35
36 if (typeof ctypes === "object")
37 test();