summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/ffi_test.ts39
1 files changed, 38 insertions, 1 deletions
diff --git a/cli/tests/unit/ffi_test.ts b/cli/tests/unit/ffi_test.ts
index 018cec674..89133b9b2 100644
--- a/cli/tests/unit/ffi_test.ts
+++ b/cli/tests/unit/ffi_test.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-import { assertEquals, assertThrows } from "./test_util.ts";
+import { assertEquals, assertRejects, assertThrows } from "./test_util.ts";
Deno.test({ permissions: { ffi: true } }, function dlopenInvalidArguments() {
const filename = "/usr/lib/libc.so.6";
@@ -98,3 +98,40 @@ Deno.test({ permissions: { ffi: true } }, function pointerOf() {
);
assertEquals(Number(baseAddress) + 80, float64AddressOffset);
});
+
+Deno.test({ permissions: { ffi: true } }, function callWithError() {
+ const throwCb = () => {
+ throw new Error("Error");
+ };
+ const cb = new Deno.UnsafeCallback({
+ parameters: [],
+ result: "void",
+ }, throwCb);
+ const fnPointer = new Deno.UnsafeFnPointer(cb.pointer, {
+ parameters: [],
+ result: "void",
+ });
+ assertThrows(() => fnPointer.call());
+ cb.close();
+});
+
+Deno.test(
+ { permissions: { ffi: true }, ignore: true },
+ async function callNonBlockingWithError() {
+ const throwCb = () => {
+ throw new Error("Error");
+ };
+ const cb = new Deno.UnsafeCallback({
+ parameters: [],
+ result: "void",
+ }, throwCb);
+ const fnPointer = new Deno.UnsafeFnPointer(cb.pointer, {
+ parameters: [],
+ result: "void",
+ nonblocking: true,
+ });
+ // TODO(mmastrac): currently ignored as we do not thread callback exceptions through nonblocking pointers
+ await assertRejects(async () => await fnPointer.call());
+ cb.close();
+ },
+);