diff options
| author | 2022-09-08 23:29:00 -0700 | |
|---|---|---|
| committer | 2022-09-08 23:29:30 -0700 | |
| commit | 206820d27a952e2a7c84da9177ca36d825ee7987 (patch) | |
| tree | 9cc9c6e82820e358fa2cd4172d2998509baf37b2 /src/bun.js/base.zig | |
| parent | 8d8b72cf3f7119f0bc018513d89eca5f8ec44ab3 (diff) | |
| download | bun-206820d27a952e2a7c84da9177ca36d825ee7987.tar.gz bun-206820d27a952e2a7c84da9177ca36d825ee7987.tar.zst bun-206820d27a952e2a7c84da9177ca36d825ee7987.zip | |
[bun:ffi] Implement `read.{u8,i8,i16,i32,u16,u32,ptr,intptr}`
`read` in `bun:ffi` lets you read data from a pointer without creating a new DataView/ArrayBufferView
```
import {read} from 'bun:ffi';
expect(read.i8(ptr_, i)).toBe(view.getInt8(i, true));
expect(read.i16(ptr_, i)).toBe(view.getInt16(i, true));
expect(read.i32(ptr_, i)).toBe(view.getInt32(i, true));
expect(read.u8(ptr_, i)).toBe(view.getUint8(i, true));
expect(read.u16(ptr_, i)).toBe(view.getUint16(i, true));
expect(read.u32(ptr_, i)).toBe(view.getUint32(i, true));
}
```
Diffstat (limited to 'src/bun.js/base.zig')
| -rw-r--r-- | src/bun.js/base.zig | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig index c1bfbf544..732f5ed97 100644 --- a/src/bun.js/base.zig +++ b/src/bun.js/base.zig @@ -3029,7 +3029,9 @@ pub const DOMEffect = struct { fn DOMCallArgumentType(comptime Type: type) []const u8 { const ChildType = if (@typeInfo(Type) == .Pointer) std.meta.Child(Type) else Type; return switch (ChildType) { - i32 => "JSC::SpecInt32Only", + i8, u8, i16, u16, i32 => "JSC::SpecInt32Only", + u32, i64, u64 => "JSC::SpecInt52Any", + f64 => "JSC::SpecDoubleReal", bool => "JSC::SpecBoolean", JSC.JSString => "JSC::SpecString", JSC.JSUint8Array => "JSC::SpecUint8Array", @@ -3041,6 +3043,9 @@ fn DOMCallArgumentTypeWrapper(comptime Type: type) []const u8 { const ChildType = if (@typeInfo(Type) == .Pointer) std.meta.Child(Type) else Type; return switch (ChildType) { i32 => "int32_t", + f64 => "double", + u64 => "uint64_t", + i64 => "int64_t", bool => "bool", JSC.JSString => "JSC::JSString*", JSC.JSUint8Array => "JSC::JSUint8Array*", @@ -3056,7 +3061,7 @@ fn DOMCallResultType(comptime Type: type) []const u8 { JSC.JSString => "JSC::SpecString", JSC.JSUint8Array => "JSC::SpecUint8Array", JSC.JSCell => "JSC::SpecCell", - f64 => "JSC::SpecNonIntAsDouble", + f64 => "JSC::SpecDoubleReal", else => "JSC::SpecHeapTop", }; } @@ -3165,7 +3170,7 @@ pub fn DOMCall( 2 => { try writer.writeAll(", "); try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[2].field_type)); - try writer.writeAll("arg1, "); + try writer.writeAll(" arg1, "); try writer.writeAll(DOMCallArgumentTypeWrapper(Fields[3].field_type)); try writer.writeAll(" arg2)) {\n"); }, |
