summaryrefslogtreecommitdiff
path: root/cli/dts
diff options
context:
space:
mode:
authorElias Sjögreen <eliassjogreen1@gmail.com>2021-12-15 15:41:49 +0100
committerGitHub <noreply@github.com>2021-12-15 15:41:49 +0100
commitee49cce726c27cdcb372b9dba7f2deab840d9e6b (patch)
treed1a9a843eb5fba782a7cff5e50cb973ee3806225 /cli/dts
parent4d176b7b7c11aabc584bee45423f108ea47faefe (diff)
feat(ext/ffi): implement UnsafePointer and UnsafePointerView (#12828)
Diffstat (limited to 'cli/dts')
-rw-r--r--cli/dts/lib.deno.unstable.d.ts80
1 files changed, 77 insertions, 3 deletions
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index affa4b3fd..6b7755ee5 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -117,16 +117,90 @@ declare namespace Deno {
| "usize"
| "isize"
| "f32"
- | "f64";
+ | "f64"
+ | "pointer";
/** A foreign function as defined by its parameter and result types */
export interface ForeignFunction {
- parameters: (NativeType | "buffer")[];
+ parameters: NativeType[];
result: NativeType;
/** When true, function calls will run on a dedicated blocking thread and will return a Promise resolving to the `result`. */
nonblocking?: boolean;
}
+ type TypedArray =
+ | Int8Array
+ | Uint8Array
+ | Int16Array
+ | Uint16Array
+ | Int32Array
+ | Uint32Array
+ | Uint8ClampedArray
+ | Float32Array
+ | Float64Array
+ | BigInt64Array
+ | BigUint64Array;
+
+ /** **UNSTABLE**: Unsafe and new API, beware!
+ *
+ * An unsafe pointer to a memory location for passing and returning pointers to and from the ffi
+ */
+ export class UnsafePointer {
+ constructor(value: bigint);
+
+ value: bigint;
+
+ /**
+ * Return the direct memory pointer to the typed array in memory
+ */
+ static of(typedArray: TypedArray): UnsafePointer;
+
+ /**
+ * Returns the value of the pointer which is useful in certain scenarios.
+ */
+ valueOf(): bigint;
+ }
+
+ /** **UNSTABLE**: Unsafe and new API, beware!
+ *
+ * An unsafe pointer view to a memory location as specified by the `pointer`
+ * value. The `UnsafePointerView` API mimics the standard built in interface
+ * `DataView` for accessing the underlying types at an memory location
+ * (numbers, strings and raw bytes).
+ */
+ export class UnsafePointerView {
+ constructor(pointer: UnsafePointer);
+
+ pointer: UnsafePointer;
+
+ /** Gets an unsigned 8-bit integer at the specified byte offset from the pointer. */
+ getUint8(offset?: number): number;
+ /** Gets a signed 8-bit integer at the specified byte offset from the pointer. */
+ getInt8(offset?: number): number;
+ /** Gets an unsigned 16-bit integer at the specified byte offset from the pointer. */
+ getUint16(offset?: number): number;
+ /** Gets a signed 16-bit integer at the specified byte offset from the pointer. */
+ getInt16(offset?: number): number;
+ /** Gets an unsigned 32-bit integer at the specified byte offset from the pointer. */
+ getUint32(offset?: number): number;
+ /** Gets a signed 32-bit integer at the specified byte offset from the pointer. */
+ getInt32(offset?: number): number;
+ /** Gets an unsigned 64-bit integer at the specified byte offset from the pointer. */
+ getBigUint64(offset?: number): bigint;
+ /** Gets a signed 64-bit integer at the specified byte offset from the pointer. */
+ getBigInt64(offset?: number): bigint;
+ /** Gets a signed 32-bit float at the specified byte offset from the pointer. */
+ getFloat32(offset?: number): number;
+ /** Gets a signed 64-bit float at the specified byte offset from the pointer. */
+ getFloat64(offset?: number): number;
+ /** Gets a C string (null terminated string) at the specified byte offset from the pointer. */
+ getCString(offset?: number): string;
+ /** Gets an ArrayBuffer of length `byteLength` at the specified byte offset from the pointer. */
+ getArrayBuffer(byteLength: number, offset?: number): ArrayBuffer;
+ /** Copies the memory of the pointer into a typed array. Length is determined from the typed array's `byteLength`. Also takes optional offset from the pointer. */
+ copyInto(destination: TypedArray, offset?: number): void;
+ }
+
/** A dynamic library resource */
export interface DynamicLibrary<S extends Record<string, ForeignFunction>> {
/** All of the registered symbols along with functions for calling them */
@@ -135,7 +209,7 @@ declare namespace Deno {
close(): void;
}
- /** **UNSTABLE**: new API
+ /** **UNSTABLE**: Unsafe and new API, beware!
*
* Opens a dynamic library and registers symbols
*/