From a4f45f709278208cb61501df2792412f11aed3c4 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Mon, 11 Dec 2023 20:10:33 -0700 Subject: perf(ext/ffi): switch from middleware to tasks (#21239) Deno-side changes for https://github.com/denoland/deno_core/pull/350 --------- Co-authored-by: Aapo Alasuutari --- cli/tests/unit/ffi_test.ts | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'cli/tests') 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(); + }, +); -- cgit v1.2.3