From ad82918f56b215a428ebe7c533ee825e1152d1b4 Mon Sep 17 00:00:00 2001 From: Dj <43033058+DjDeveloperr@users.noreply.github.com> Date: Sat, 7 Jan 2023 19:58:10 -0800 Subject: feat(ext/ffi): structs by value (#15060) Adds support for passing and returning structs as buffers to FFI. This does not implement fastapi support for structs. Needed for certain system APIs such as AppKit on macOS. --- cli/tsc/dts/lib.deno.unstable.d.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'cli/tsc/dts/lib.deno.unstable.d.ts') diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index d34a5bd62..e3ae8f46f 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -94,6 +94,13 @@ declare namespace Deno { */ type NativeVoidType = "void"; + /** **UNSTABLE**: New API, yet to be vetted. + * + * The native struct type for interfacing with foreign functions. + * + */ + type NativeStructType = { readonly struct: readonly NativeType[] }; + /** **UNSTABLE**: New API, yet to be vetted. * * All supported types for interfacing with foreign functions. @@ -106,7 +113,8 @@ declare namespace Deno { | NativeBooleanType | NativePointerType | NativeBufferType - | NativeFunctionType; + | NativeFunctionType + | NativeStructType; /** **UNSTABLE**: New API, yet to be vetted. * @@ -136,7 +144,9 @@ declare namespace Deno { * * @category FFI */ - type ToNativeType = ToNativeTypeMap[T]; + type ToNativeType = T extends + NativeStructType ? BufferSource + : ToNativeTypeMap[Exclude]; /** **UNSTABLE**: New API, yet to be vetted. * @@ -153,7 +163,8 @@ declare namespace Deno { * @category FFI */ type ToNativeResultType = - ToNativeResultTypeMap[T]; + T extends NativeStructType ? BufferSource + : ToNativeResultTypeMap[Exclude]; /** **UNSTABLE**: New API, yet to be vetted. * @@ -193,7 +204,9 @@ declare namespace Deno { * * @category FFI */ - type FromNativeType = FromNativeTypeMap[T]; + type FromNativeType = T extends + NativeStructType ? Uint8Array + : FromNativeTypeMap[Exclude]; /** **UNSTABLE**: New API, yet to be vetted. * @@ -212,7 +225,8 @@ declare namespace Deno { * @category FFI */ type FromNativeResultType = - FromNativeResultTypeMap[T]; + T extends NativeStructType ? Uint8Array + : FromNativeResultTypeMap[Exclude]; /** **UNSTABLE**: New API, yet to be vetted. * -- cgit v1.2.3