Skip to content

Commit e2c0fd9

Browse files
committed
Add functions to create all the typed arrays
1 parent f0c7eaa commit e2c0fd9

File tree

3 files changed

+344
-0
lines changed

3 files changed

+344
-0
lines changed

src/binding.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ const v8::Boolean* v8__False(v8::Isolate* isolate) {
143143
return local_to_ptr(v8::False(isolate));
144144
}
145145

146+
const v8::Uint8ClampedArray* v8__Uint8ClampedArray__New(
147+
const v8::ArrayBuffer& buf,
148+
size_t byte_offset,
149+
size_t length) {
150+
return local_to_ptr(
151+
v8::Uint8ClampedArray::New(ptr_to_local(&buf), byte_offset, length)
152+
);
153+
}
154+
146155
const v8::Uint8Array* v8__Uint8Array__New(
147156
const v8::ArrayBuffer& buf,
148157
size_t byte_offset,
@@ -152,6 +161,95 @@ const v8::Uint8Array* v8__Uint8Array__New(
152161
);
153162
}
154163

164+
const v8::Int8Array* v8__Int8Array__New(
165+
const v8::ArrayBuffer& buf,
166+
size_t byte_offset,
167+
size_t length) {
168+
return local_to_ptr(
169+
v8::Int8Array::New(ptr_to_local(&buf), byte_offset, length)
170+
);
171+
}
172+
173+
const v8::Uint16Array* v8__Uint16Array__New(
174+
const v8::ArrayBuffer& buf,
175+
size_t byte_offset,
176+
size_t length) {
177+
return local_to_ptr(
178+
v8::Uint16Array::New(ptr_to_local(&buf), byte_offset, length)
179+
);
180+
}
181+
182+
const v8::Int16Array* v8__Int16Array__New(
183+
const v8::ArrayBuffer& buf,
184+
size_t byte_offset,
185+
size_t length) {
186+
return local_to_ptr(
187+
v8::Int16Array::New(ptr_to_local(&buf), byte_offset, length)
188+
);
189+
}
190+
191+
const v8::Uint32Array* v8__Uint32Array__New(
192+
const v8::ArrayBuffer& buf,
193+
size_t byte_offset,
194+
size_t length) {
195+
return local_to_ptr(
196+
v8::Uint32Array::New(ptr_to_local(&buf), byte_offset, length)
197+
);
198+
}
199+
200+
const v8::Int32Array* v8__Int32Array__New(
201+
const v8::ArrayBuffer& buf,
202+
size_t byte_offset,
203+
size_t length) {
204+
return local_to_ptr(
205+
v8::Int32Array::New(ptr_to_local(&buf), byte_offset, length)
206+
);
207+
}
208+
209+
// const v8::Float16Array* v8__Float16Array__New(
210+
// const v8::ArrayBuffer& buf,
211+
// size_t byte_offset,
212+
// size_t length) {
213+
// return local_to_ptr(
214+
// v8::Float16Array::New(ptr_to_local(&buf), byte_offset, length)
215+
// );
216+
// }
217+
218+
const v8::Float32Array* v8__Float32Array__New(
219+
const v8::ArrayBuffer& buf,
220+
size_t byte_offset,
221+
size_t length) {
222+
return local_to_ptr(
223+
v8::Float32Array::New(ptr_to_local(&buf), byte_offset, length)
224+
);
225+
}
226+
227+
const v8::Float64Array* v8__Float64Array__New(
228+
const v8::ArrayBuffer& buf,
229+
size_t byte_offset,
230+
size_t length) {
231+
return local_to_ptr(
232+
v8::Float64Array::New(ptr_to_local(&buf), byte_offset, length)
233+
);
234+
}
235+
236+
const v8::BigUint64Array* v8__BigUint64Array__New(
237+
const v8::ArrayBuffer& buf,
238+
size_t byte_offset,
239+
size_t length) {
240+
return local_to_ptr(
241+
v8::BigUint64Array::New(ptr_to_local(&buf), byte_offset, length)
242+
);
243+
}
244+
245+
const v8::BigInt64Array* v8__BigInt64Array__New(
246+
const v8::ArrayBuffer& buf,
247+
size_t byte_offset,
248+
size_t length) {
249+
return local_to_ptr(
250+
v8::BigInt64Array::New(ptr_to_local(&buf), byte_offset, length)
251+
);
252+
}
155253
// V8
156254

157255
const char* v8__V8__GetVersion() { return v8::V8::GetVersion(); }

src/binding.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ typedef Value Primitive;
2727
typedef Value Integer;
2828
typedef Value BigInt;
2929
typedef Value Array;
30+
typedef Value Uint8ClampedArray;
3031
typedef Value Uint8Array;
32+
typedef Value Int8Array;
33+
typedef Value Uint16Array;
34+
typedef Value Int16Array;
35+
typedef Value Uint32Array;
36+
typedef Value Int32Array;
37+
typedef Value BigUint64Array;
38+
typedef Value BigInt64Array;
39+
// typedef Value Float16Array;
40+
typedef Value Float32Array;
41+
typedef Value Float64Array;
3142
typedef Value ArrayBufferView;
3243
typedef Value External;
3344
typedef Value Symbol;
@@ -120,11 +131,66 @@ const Primitive* v8__Undefined(Isolate* isolate);
120131
const Primitive* v8__Null(Isolate* isolate);
121132
const Boolean* v8__True(Isolate* isolate);
122133
const Boolean* v8__False(Isolate* isolate);
134+
const Uint8ClampedArray* v8__Uint8ClampedArray__New(
135+
const ArrayBuffer* buf,
136+
size_t byte_offset,
137+
size_t length);
138+
123139
const Uint8Array* v8__Uint8Array__New(
124140
const ArrayBuffer* buf,
125141
size_t byte_offset,
126142
size_t length);
127143

144+
const Int8Array* v8__Int8Array__New(
145+
const ArrayBuffer* buf,
146+
size_t byte_offset,
147+
size_t length);
148+
149+
const Uint16Array* v8__Uint16Array__New(
150+
const ArrayBuffer* buf,
151+
size_t byte_offset,
152+
size_t length);
153+
154+
const Int16Array* v8__Int16Array__New(
155+
const ArrayBuffer* buf,
156+
size_t byte_offset,
157+
size_t length);
158+
159+
const Uint32Array* v8__Uint32Array__New(
160+
const ArrayBuffer* buf,
161+
size_t byte_offset,
162+
size_t length);
163+
164+
const Int32Array* v8__Int32Array__New(
165+
const ArrayBuffer* buf,
166+
size_t byte_offset,
167+
size_t length);
168+
169+
// const Float16Array* v8__Float16Array__New(
170+
// const ArrayBuffer* buf,
171+
// size_t byte_offset,
172+
// size_t length);
173+
174+
const Float32Array* v8__Float32Array__New(
175+
const ArrayBuffer* buf,
176+
size_t byte_offset,
177+
size_t length);
178+
179+
const Float64Array* v8__Float64Array__New(
180+
const ArrayBuffer* buf,
181+
size_t byte_offset,
182+
size_t length);
183+
184+
const BigUint64Array* v8__BigUint64Array__New(
185+
const ArrayBuffer* buf,
186+
size_t byte_offset,
187+
size_t length);
188+
189+
const BigInt64Array* v8__BigInt64Array__New(
190+
const ArrayBuffer* buf,
191+
size_t byte_offset,
192+
size_t length);
193+
128194
// V8
129195
void v8__V8__InitializePlatform(Platform* platform);
130196
void v8__V8__Initialize();

src/v8.zig

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,22 @@ pub const FixedArray = struct {
24322432
}
24332433
};
24342434

2435+
pub const Uint8ClampedArray = struct {
2436+
const Self = @This();
2437+
2438+
handle: *const c.Uint8ClampedArray,
2439+
2440+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2441+
return .{
2442+
.handle = c.v8__Uint8ClampedArray__New(buf.handle, offset, len).?,
2443+
};
2444+
}
2445+
2446+
pub fn toValue(self: Self) Value {
2447+
return .{ .handle = self.handle };
2448+
}
2449+
};
2450+
24352451
pub const Uint8Array = struct {
24362452
const Self = @This();
24372453

@@ -2442,6 +2458,170 @@ pub const Uint8Array = struct {
24422458
.handle = c.v8__Uint8Array__New(buf.handle, offset, len).?,
24432459
};
24442460
}
2461+
2462+
pub fn toValue(self: Self) Value {
2463+
return .{ .handle = self.handle };
2464+
}
2465+
};
2466+
2467+
pub const Int8Array = struct {
2468+
const Self = @This();
2469+
2470+
handle: *const c.Int8Array,
2471+
2472+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2473+
return .{
2474+
.handle = c.v8__Int8Array__New(buf.handle, offset, len).?,
2475+
};
2476+
}
2477+
2478+
pub fn toValue(self: Self) Value {
2479+
return .{ .handle = self.handle };
2480+
}
2481+
};
2482+
2483+
pub const Uint16Array = struct {
2484+
const Self = @This();
2485+
2486+
handle: *const c.Uint16Array,
2487+
2488+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2489+
return .{
2490+
.handle = c.v8__Uint16Array__New(buf.handle, offset, len).?,
2491+
};
2492+
}
2493+
2494+
pub fn toValue(self: Self) Value {
2495+
return .{ .handle = self.handle };
2496+
}
2497+
};
2498+
2499+
pub const Int16Array = struct {
2500+
const Self = @This();
2501+
2502+
handle: *const c.Int16Array,
2503+
2504+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2505+
return .{
2506+
.handle = c.v8__Int16Array__New(buf.handle, offset, len).?,
2507+
};
2508+
}
2509+
2510+
pub fn toValue(self: Self) Value {
2511+
return .{ .handle = self.handle };
2512+
}
2513+
};
2514+
2515+
pub const Uint32Array = struct {
2516+
const Self = @This();
2517+
2518+
handle: *const c.Uint32Array,
2519+
2520+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2521+
return .{
2522+
.handle = c.v8__Uint32Array__New(buf.handle, offset, len).?,
2523+
};
2524+
}
2525+
2526+
pub fn toValue(self: Self) Value {
2527+
return .{ .handle = self.handle };
2528+
}
2529+
};
2530+
2531+
pub const Int32Array = struct {
2532+
const Self = @This();
2533+
2534+
handle: *const c.Int32Array,
2535+
2536+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2537+
return .{
2538+
.handle = c.v8__Int32Array__New(buf.handle, offset, len).?,
2539+
};
2540+
}
2541+
2542+
pub fn toValue(self: Self) Value {
2543+
return .{ .handle = self.handle };
2544+
}
2545+
};
2546+
2547+
pub const Float16Array = struct {
2548+
const Self = @This();
2549+
2550+
handle: *const c.Float16Array,
2551+
2552+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2553+
return .{
2554+
.handle = c.v8__Float16Array__New(buf.handle, offset, len).?,
2555+
};
2556+
}
2557+
2558+
pub fn toValue(self: Self) Value {
2559+
return .{ .handle = self.handle };
2560+
}
2561+
};
2562+
2563+
pub const Float32Array = struct {
2564+
const Self = @This();
2565+
2566+
handle: *const c.Float32Array,
2567+
2568+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2569+
return .{
2570+
.handle = c.v8__Float32Array__New(buf.handle, offset, len).?,
2571+
};
2572+
}
2573+
2574+
pub fn toValue(self: Self) Value {
2575+
return .{ .handle = self.handle };
2576+
}
2577+
};
2578+
2579+
pub const Float64Array = struct {
2580+
const Self = @This();
2581+
2582+
handle: *const c.Float64Array,
2583+
2584+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2585+
return .{
2586+
.handle = c.v8__Float64Array__New(buf.handle, offset, len).?,
2587+
};
2588+
}
2589+
2590+
pub fn toValue(self: Self) Value {
2591+
return .{ .handle = self.handle };
2592+
}
2593+
};
2594+
2595+
pub const BigInt64Array = struct {
2596+
const Self = @This();
2597+
2598+
handle: *const c.BigInt64Array,
2599+
2600+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2601+
return .{
2602+
.handle = c.v8__BigInt64Array__New(buf.handle, offset, len).?,
2603+
};
2604+
}
2605+
2606+
pub fn toValue(self: Self) Value {
2607+
return .{ .handle = self.handle };
2608+
}
2609+
};
2610+
2611+
pub const BigUint64Array = struct {
2612+
const Self = @This();
2613+
2614+
handle: *const c.BigUint64Array,
2615+
2616+
pub fn init(buf: ArrayBuffer, offset: usize, len: usize) Self {
2617+
return .{
2618+
.handle = c.v8__BigUint64Array__New(buf.handle, offset, len).?,
2619+
};
2620+
}
2621+
2622+
pub fn toValue(self: Self) Value {
2623+
return .{ .handle = self.handle };
2624+
}
24452625
};
24462626

24472627
pub const Json = struct {

0 commit comments

Comments
 (0)