Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: object wrap UnsafePointerView #27587

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 1 addition & 158 deletions ext/ffi/00_ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ const {
isTypedArray,
} = core;
import {
op_ffi_buf_copy_into,
op_ffi_call_nonblocking,
op_ffi_call_ptr,
op_ffi_call_ptr_nonblocking,
op_ffi_cstr_read,
op_ffi_get_buf,
op_ffi_get_static,
op_ffi_load,
op_ffi_ptr_create,
Expand All @@ -21,21 +18,10 @@ import {
op_ffi_ptr_of_exact,
op_ffi_ptr_offset,
op_ffi_ptr_value,
op_ffi_read_bool,
op_ffi_read_f32,
op_ffi_read_f64,
op_ffi_read_i16,
op_ffi_read_i32,
op_ffi_read_i64,
op_ffi_read_i8,
op_ffi_read_ptr,
op_ffi_read_u16,
op_ffi_read_u32,
op_ffi_read_u64,
op_ffi_read_u8,
op_ffi_unsafe_callback_close,
op_ffi_unsafe_callback_create,
op_ffi_unsafe_callback_ref,
UnsafePointerView,
} from "ext:core/ops";
const {
ArrayBufferIsView,
Expand Down Expand Up @@ -74,149 +60,6 @@ function getBufferSourceByteLength(source) {
}
return ArrayBufferPrototypeGetByteLength(source);
}
class UnsafePointerView {
pointer;

constructor(pointer) {
this.pointer = pointer;
}

getBool(offset = 0) {
return op_ffi_read_bool(
this.pointer,
offset,
);
}

getUint8(offset = 0) {
return op_ffi_read_u8(
this.pointer,
offset,
);
}

getInt8(offset = 0) {
return op_ffi_read_i8(
this.pointer,
offset,
);
}

getUint16(offset = 0) {
return op_ffi_read_u16(
this.pointer,
offset,
);
}

getInt16(offset = 0) {
return op_ffi_read_i16(
this.pointer,
offset,
);
}

getUint32(offset = 0) {
return op_ffi_read_u32(
this.pointer,
offset,
);
}

getInt32(offset = 0) {
return op_ffi_read_i32(
this.pointer,
offset,
);
}

getBigUint64(offset = 0) {
return op_ffi_read_u64(
this.pointer,
// We return a BigInt, so the turbocall
// is forced to use BigInts everywhere.
BigInt(offset),
);
}

getBigInt64(offset = 0) {
return op_ffi_read_i64(
this.pointer,
// We return a BigInt, so the turbocall
// is forced to use BigInts everywhere.
BigInt(offset),
);
}

getFloat32(offset = 0) {
return op_ffi_read_f32(
this.pointer,
offset,
);
}

getFloat64(offset = 0) {
return op_ffi_read_f64(
this.pointer,
offset,
);
}

getPointer(offset = 0) {
return op_ffi_read_ptr(
this.pointer,
offset,
);
}

getCString(offset = 0) {
return op_ffi_cstr_read(
this.pointer,
offset,
);
}

static getCString(pointer, offset = 0) {
return op_ffi_cstr_read(
pointer,
offset,
);
}

getArrayBuffer(byteLength, offset = 0) {
return op_ffi_get_buf(
this.pointer,
offset,
byteLength,
);
}

static getArrayBuffer(pointer, byteLength, offset = 0) {
return op_ffi_get_buf(
pointer,
offset,
byteLength,
);
}

copyInto(destination, offset = 0) {
op_ffi_buf_copy_into(
this.pointer,
offset,
destination,
getBufferSourceByteLength(destination),
);
}

static copyInto(pointer, destination, offset = 0) {
op_ffi_buf_copy_into(
pointer,
offset,
destination,
getBufferSourceByteLength(destination),
);
}
}

const POINTER_TO_BUFFER_WEAK_MAP = new SafeWeakMap();
class UnsafePointer {
Expand Down
15 changes: 0 additions & 15 deletions ext/ffi/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,6 @@ deno_core::extension!(deno_ffi,
op_ffi_ptr_of_exact<P>,
op_ffi_ptr_offset<P>,
op_ffi_ptr_value<P>,
op_ffi_get_buf<P>,
op_ffi_buf_copy_into<P>,
op_ffi_cstr_read<P>,
op_ffi_read_bool<P>,
op_ffi_read_u8<P>,
op_ffi_read_i8<P>,
op_ffi_read_u16<P>,
op_ffi_read_i16<P>,
op_ffi_read_u32<P>,
op_ffi_read_i32<P>,
op_ffi_read_u64<P>,
op_ffi_read_i64<P>,
op_ffi_read_f32<P>,
op_ffi_read_f64<P>,
op_ffi_read_ptr<P>,
op_ffi_unsafe_callback_create<P>,
op_ffi_unsafe_callback_close,
op_ffi_unsafe_callback_ref,
Expand Down
Loading