diff options
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r-- | ext/ffi/00_ffi.js | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index 3f5c57a9c..f5b0fb4c3 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -6,7 +6,6 @@ const ops = core.ops; const __bootstrap = window.__bootstrap; const { - BigInt, ObjectDefineProperty, ArrayPrototypeMap, Number, @@ -17,9 +16,13 @@ Int32Array, Uint32Array, BigInt64Array, + BigUint64Array, Function, } = window.__bootstrap.primordials; + const U32_BUFFER = new Uint32Array(2); + const U64_BUFFER = new BigUint64Array(U32_BUFFER.buffer); + const I64_BUFFER = new BigInt64Array(U32_BUFFER.buffer); class UnsafePointerView { pointer; @@ -29,99 +32,119 @@ getBool(offset = 0) { return ops.op_ffi_read_bool( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getUint8(offset = 0) { return ops.op_ffi_read_u8( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getInt8(offset = 0) { return ops.op_ffi_read_i8( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getUint16(offset = 0) { return ops.op_ffi_read_u16( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getInt16(offset = 0) { return ops.op_ffi_read_i16( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getUint32(offset = 0) { return ops.op_ffi_read_u32( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getInt32(offset = 0) { return ops.op_ffi_read_i32( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getBigUint64(offset = 0) { - return ops.op_ffi_read_u64( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + ops.op_ffi_read_u64( + this.pointer, + offset, + U32_BUFFER, ); + return U64_BUFFER[0]; } getBigInt64(offset = 0) { - return ops.op_ffi_read_i64( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + ops.op_ffi_read_i64( + this.pointer, + offset, + U32_BUFFER, ); + return I64_BUFFER[0]; } getFloat32(offset = 0) { return ops.op_ffi_read_f32( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getFloat64(offset = 0) { return ops.op_ffi_read_f64( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getCString(offset = 0) { return ops.op_ffi_cstr_read( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } static getCString(pointer, offset = 0) { return ops.op_ffi_cstr_read( - offset ? BigInt(pointer) + BigInt(offset) : pointer, + pointer, + offset, ); } getArrayBuffer(byteLength, offset = 0) { return ops.op_ffi_get_buf( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, byteLength, ); } static getArrayBuffer(pointer, byteLength, offset = 0) { return ops.op_ffi_get_buf( - offset ? BigInt(pointer) + BigInt(offset) : pointer, + pointer, + offset, byteLength, ); } copyInto(destination, offset = 0) { ops.op_ffi_buf_copy_into( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, destination, destination.byteLength, ); @@ -129,7 +152,8 @@ static copyInto(pointer, destination, offset = 0) { ops.op_ffi_buf_copy_into( - offset ? BigInt(pointer) + BigInt(offset) : pointer, + pointer, + offset, destination, destination.byteLength, ); |