mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
feat(ext/ffi): Add static method variants to Deno.UnsafePointerView (#15146)
This commit is contained in:
parent
569910856e
commit
9c594de0ff
2 changed files with 40 additions and 2 deletions
16
cli/dts/lib.deno.unstable.d.ts
vendored
16
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -535,10 +535,24 @@ declare namespace Deno {
|
|||
getFloat64(offset?: number): number;
|
||||
/** Gets a C string (null terminated string) at the specified byte offset from the pointer. */
|
||||
getCString(offset?: number): string;
|
||||
/** Gets a C string (null terminated string) at the specified byte offset from the specified pointer. */
|
||||
static getCString(pointer: BigInt, 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. */
|
||||
/** Gets an ArrayBuffer of length `byteLength` at the specified byte offset from the specified pointer. */
|
||||
static getArrayBuffer(
|
||||
pointer: BigInt,
|
||||
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 byte offset from the pointer. */
|
||||
copyInto(destination: TypedArray, offset?: number): void;
|
||||
/** Copies the memory of the specified pointer into a typed array. Length is determined from the typed array's `byteLength`. Also takes optional byte offset from the pointer. */
|
||||
static copyInto(
|
||||
pointer: BigInt,
|
||||
destination: TypedArray,
|
||||
offset?: number,
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,10 +121,25 @@
|
|||
);
|
||||
}
|
||||
|
||||
static getCString(pointer, offset = 0) {
|
||||
return core.opSync(
|
||||
"op_ffi_cstr_read",
|
||||
offset ? BigInt(pointer) + BigInt(offset) : pointer,
|
||||
);
|
||||
}
|
||||
|
||||
getArrayBuffer(byteLength, offset = 0) {
|
||||
return core.opSync(
|
||||
"op_ffi_get_buf",
|
||||
offset ? this.pointer + BigInt(offset) : this.pointer,
|
||||
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
|
||||
byteLength,
|
||||
);
|
||||
}
|
||||
|
||||
static getArrayBuffer(pointer, byteLength, offset = 0) {
|
||||
return core.opSync(
|
||||
"op_ffi_get_buf",
|
||||
offset ? BigInt(pointer) + BigInt(offset) : pointer,
|
||||
byteLength,
|
||||
);
|
||||
}
|
||||
|
@ -137,6 +152,15 @@
|
|||
destination.byteLength,
|
||||
);
|
||||
}
|
||||
|
||||
static copyInto(pointer, destination, offset = 0) {
|
||||
core.opSync(
|
||||
"op_ffi_buf_copy_into",
|
||||
offset ? BigInt(pointer) + BigInt(offset) : pointer,
|
||||
destination,
|
||||
destination.byteLength,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class UnsafePointer {
|
||||
|
|
Loading…
Reference in a new issue