diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/ctypes/conversion-function.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/ctypes/conversion-function.js')
-rw-r--r-- | js/src/jit-test/tests/ctypes/conversion-function.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/ctypes/conversion-function.js b/js/src/jit-test/tests/ctypes/conversion-function.js new file mode 100644 index 0000000000..cd90f1b606 --- /dev/null +++ b/js/src/jit-test/tests/ctypes/conversion-function.js @@ -0,0 +1,33 @@ +// Type conversion error should report its type. + +load(libdir + 'asserts.js'); + +function test() { + // Note: js shell cannot handle the exception in return value. + + // primitive + let func_type = ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, + [ctypes.int32_t]).ptr; + let f1 = func_type(function() {}); + assertTypeErrorMessage(() => { f1("foo"); }, + /can't pass the string "foo" to argument 1 of ctypes\.FunctionType\(ctypes\.default_abi, ctypes\.voidptr_t, \[ctypes\.int32_t\]\)\.ptr\(ctypes\.UInt64\("[x0-9A-Fa-f]+"\)\)/); + + // struct + let test_struct = ctypes.StructType("test_struct", [{ "x": ctypes.int32_t }]); + let func_type2 = ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, + [test_struct]).ptr; + let f2 = func_type2(function() {}); + assertTypeErrorMessage(() => { f2({ "x": "foo" }); }, + /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.int32_t, \[test_struct\]\)\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\)/); + assertTypeErrorMessage(() => { f2({ "x": "foo", "y": "bar" }); }, + /property count of the object \(\{x:\"foo\", y:\"bar\"\}\) does not match to field count of the type test_struct \(expected 1, got 2\) at argument 1 of ctypes\.FunctionType\(ctypes\.default_abi, ctypes\.int32_t, \[test_struct\]\)\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\)/); + assertTypeErrorMessage(() => { f2({ 0: "foo" }); }, + /property name the number 0 of the object \(\{0:\"foo\"\}\) is not a string at argument 1 of ctypes\.FunctionType\(ctypes\.default_abi, ctypes\.int32_t, \[test_struct\]\)\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\)/); + + // error sentinel + assertTypeErrorMessage(() => { func_type(function() {}, null, "foo"); }, + "can't convert the string \"foo\" to the return type of ctypes.FunctionType(ctypes.default_abi, ctypes.voidptr_t, [ctypes.int32_t])"); +} + +if (typeof ctypes === "object") + test(); |