feat(ext/ffi): support marking symbols as optional (#18529)

This commit is contained in:
Dj 2023-04-04 00:02:21 +05:30 committed by GitHub
parent 51d3fb78ad
commit 62c5664697
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 6 deletions

View file

@ -271,6 +271,11 @@ declare namespace Deno {
*
* @default {false} */
callback?: boolean;
/** When `true`, dlopen will not fail if the symbol is not found.
* Instead, the symbol will be set to `null`.
*
* @default {false} */
optional?: boolean;
}
/** **UNSTABLE**: New API, yet to be vetted.
@ -282,6 +287,11 @@ declare namespace Deno {
name?: string;
/** The type of the foreign static value. */
type: Type;
/** When `true`, dlopen will not fail if the symbol is not found.
* Instead, the symbol will be set to `null`.
*
* @default {false} */
optional?: boolean;
}
/** **UNSTABLE**: New API, yet to be vetted.
@ -336,7 +346,9 @@ declare namespace Deno {
* @category FFI
*/
type StaticForeignLibraryInterface<T extends ForeignLibraryInterface> = {
[K in keyof T]: StaticForeignSymbol<T[K]>;
[K in keyof T]: T[K]["optional"] extends true
? StaticForeignSymbol<T[K]> | null
: StaticForeignSymbol<T[K]>;
};
const brand: unique symbol;