Debian Codegraph @

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

raw
1 // Type conversion error should report its type.
2
3 load(libdir + 'asserts.js');
4
5 function test() {
6 let test_struct = ctypes.StructType("test_struct", [{ "x": ctypes.int32_t }]);
7 let struct_val = test_struct();
8
9 // constructor
10 assertTypeErrorMessage(() => { ctypes.int32_t.ptr("foo"); },
11 "can't convert the string \"foo\" to the type ctypes.int32_t.ptr");
12
13 // value setter
14 assertTypeErrorMessage(() => { test_struct.ptr().value = "foo"; },
15 "can't convert the string \"foo\" to the type test_struct.ptr");
16 assertTypeErrorMessage(() => { test_struct.ptr().value = {}; },
17 "can't convert the object ({}) to the type test_struct.ptr");
18 assertTypeErrorMessage(() => { test_struct.ptr().value = [1, 2]; },
19 "can't convert the array [1, 2] to the type test_struct.ptr");
20 assertTypeErrorMessage(() => { test_struct.ptr().value = new Int8Array([1, 2]); },
21 "can't convert the typed array ({0:1, 1:2}) to the type test_struct.ptr");
22
23 // contents setter
24 assertTypeErrorMessage(() => { ctypes.int32_t().address().contents = {}; },
25 "can't convert the object ({}) to the type int32_t");
26 }
27
28 if (typeof ctypes === "object")
29 test();