From dc660327209e5662cf49590ec6c9c73bc3c80d88 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Sun, 15 Feb 2026 16:52:35 +0300 Subject: [PATCH 01/11] `ImageData`: initial support We're missing fancy HDR range currently, though, most websites stick to sRGB. --- src/browser/webapi/ImageData.zig | 123 +++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/browser/webapi/ImageData.zig diff --git a/src/browser/webapi/ImageData.zig b/src/browser/webapi/ImageData.zig new file mode 100644 index 00000000..e9020b77 --- /dev/null +++ b/src/browser/webapi/ImageData.zig @@ -0,0 +1,123 @@ +// Copyright (C) 2023-2026 Lightpanda (Selecy SAS) +// +// Francis Bouvier +// Pierre Tachoire +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +const std = @import("std"); + +const String = @import("../../string.zig").String; +const log = @import("../../log.zig"); + +const js = @import("../js/js.zig"); +const color = @import("../color.zig"); +const Page = @import("../Page.zig"); + +/// https://developer.mozilla.org/en-US/docs/Web/API/ImageData/ImageData +const ImageData = @This(); +_width: u32, +_height: u32, +/// Can be mutated from both Zig and JS ends; see `js.Uint8ClampedArray(.ref)`. +_data: []u8, + +pub const ConstructorSettings = struct { + /// Specifies the color space of the image data. + /// Can be set to "srgb" for the sRGB color space or "display-p3" for the display-p3 color space. + colorSpace: String = .wrap("srgb"), + /// Specifies the pixel format. + /// https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createImageData#pixelformat + pixelFormat: String = .wrap("rgba-unorm8"), +}; + +/// This has many constructors: +/// +/// ```js +/// new ImageData(width, height) +/// new ImageData(width, height, settings) +/// +/// new ImageData(dataArray, width) +/// new ImageData(dataArray, width, height) +/// new ImageData(dataArray, width, height, settings) +/// ``` +/// +/// We currently support only the first 2. +pub fn constructor( + width: u32, + height: u32, + maybe_settings: ?ConstructorSettings, + page: *Page, +) !*ImageData { + const settings: ConstructorSettings = maybe_settings orelse .{}; + if (settings.colorSpace.eql(comptime .wrap("srgb")) == false) { + return error.TypeError; + } + if (settings.pixelFormat.eql(comptime .wrap("rgba-unorm8")) == false) { + return error.TypeError; + } + + const size = width * height * 4; + const mem = try page.arena.alloc(u8, size); + // Zero-init since debug mode fills w/ char 170. + @memset(mem, 0); + + return page._factory.create(ImageData{ + ._width = width, + ._height = height, + ._data = mem, + }); +} + +pub fn getWidth(self: *const ImageData) u32 { + return self._width; +} + +pub fn getHeight(self: *const ImageData) u32 { + return self._height; +} + +pub fn getPixelFormat(_: *const ImageData) String { + return comptime .wrap("rgba-unorm8"); +} + +pub fn getColorSpace(_: *const ImageData) String { + return comptime .wrap("srgb"); +} + +pub fn getData(self: *const ImageData) js.Uint8ClampedArray(.ref) { + return .{ .values = self._data }; +} + +pub const JsApi = struct { + pub const bridge = js.Bridge(ImageData); + + pub const Meta = struct { + pub const name = "ImageData"; + pub const prototype_chain = bridge.prototypeChain(); + pub var class_id: bridge.ClassId = undefined; + }; + + pub const constructor = bridge.constructor(ImageData.constructor, .{}); + + pub const width = bridge.accessor(ImageData.getWidth, null, .{}); + pub const height = bridge.accessor(ImageData.getHeight, null, .{}); + pub const pixelFormat = bridge.accessor(ImageData.getPixelFormat, null, .{}); + pub const colorSpace = bridge.accessor(ImageData.getColorSpace, null, .{}); + pub const data = bridge.accessor(ImageData.getData, null, .{}); +}; + +const testing = @import("../../testing.zig"); +test "WebApi: ImageData" { + try testing.htmlRunner("image_data.html", .{}); +} From 2e8a9f809ef632c735cf09389eb31089391d9a11 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Sun, 15 Feb 2026 16:52:50 +0300 Subject: [PATCH 02/11] `ImageData`: add test --- src/browser/tests/image_data.html | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/browser/tests/image_data.html diff --git a/src/browser/tests/image_data.html b/src/browser/tests/image_data.html new file mode 100644 index 00000000..ccaef668 --- /dev/null +++ b/src/browser/tests/image_data.html @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + From 6554f80fad525788315cda8a2f7e91bd38c9f5ea Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Sun, 15 Feb 2026 16:59:02 +0300 Subject: [PATCH 03/11] `ImageData`: `constructor` can throw DOM exceptions --- src/browser/webapi/ImageData.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/webapi/ImageData.zig b/src/browser/webapi/ImageData.zig index e9020b77..faf65c29 100644 --- a/src/browser/webapi/ImageData.zig +++ b/src/browser/webapi/ImageData.zig @@ -108,7 +108,7 @@ pub const JsApi = struct { pub var class_id: bridge.ClassId = undefined; }; - pub const constructor = bridge.constructor(ImageData.constructor, .{}); + pub const constructor = bridge.constructor(ImageData.constructor, .{ .dom_exception = true }); pub const width = bridge.accessor(ImageData.getWidth, null, .{}); pub const height = bridge.accessor(ImageData.getHeight, null, .{}); From f80566e0cb1e7050ebcaa6ae6b7488a91d6805e7 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Mon, 16 Feb 2026 11:21:33 +0300 Subject: [PATCH 04/11] `ImageData`: add a type entry in `bridge.zig` --- src/browser/js/bridge.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/browser/js/bridge.zig b/src/browser/js/bridge.zig index c6f677a0..d817d33c 100644 --- a/src/browser/js/bridge.zig +++ b/src/browser/js/bridge.zig @@ -861,4 +861,5 @@ pub const JsApis = flattenTypes(&.{ @import("../webapi/canvas/WebGLRenderingContext.zig"), @import("../webapi/SubtleCrypto.zig"), @import("../webapi/Selection.zig"), + @import("../webapi/ImageData.zig"), }); From c30207ac631ff91e1a2522d75daad081e1376605 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Tue, 17 Feb 2026 01:45:19 +0300 Subject: [PATCH 05/11] introduce `js.createTypedArray` A new way to create typed arrays that allows using the same memory. --- src/browser/js/Context.zig | 6 +++ src/browser/js/Local.zig | 8 +++ src/browser/js/js.zig | 105 ++++++++++++++++++++++--------------- 3 files changed, 77 insertions(+), 42 deletions(-) diff --git a/src/browser/js/Context.zig b/src/browser/js/Context.zig index de9c4849..ca4e83d4 100644 --- a/src/browser/js/Context.zig +++ b/src/browser/js/Context.zig @@ -1045,6 +1045,12 @@ pub const FinalizerCallback = struct { } }; +/// Creates a new typed array. Memory is owned by JS context. +/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Typed_arrays +pub fn createTypedArray(self: *Context, comptime array_type: js.ArrayType, size: usize) js.ArrayBufferRef(array_type) { + return .init(self.isolate, size); +} + // == Profiler == pub fn startCpuProfiler(self: *Context) void { if (comptime !IS_DEBUG) { diff --git a/src/browser/js/Local.zig b/src/browser/js/Local.zig index 78ec45b0..281449a9 100644 --- a/src/browser/js/Local.zig +++ b/src/browser/js/Local.zig @@ -306,6 +306,14 @@ pub fn zigValueToJs(self: *const Local, value: anytype, comptime opts: CallOpts) js.Value => return value, js.Exception => return .{ .local = self, .handle = isolate.throwException(value.handle) }, + js.ArrayBufferRef(.Int8), js.ArrayBufferRef(.Uint8), js.ArrayBufferRef(.Uint8Clamped), + js.ArrayBufferRef(.Int16), js.ArrayBufferRef(.Uint16), + js.ArrayBufferRef(.Int32), js.ArrayBufferRef(.Uint32), + js.ArrayBufferRef(.Float16), js.ArrayBufferRef(.Float32), js.ArrayBufferRef(.Float64), + => { + return .{ .local = self, .handle = value.internal }; + }, + inline js.Function, js.Object, diff --git a/src/browser/js/js.zig b/src/browser/js/js.zig index 16f553a5..d76d2e7e 100644 --- a/src/browser/js/js.zig +++ b/src/browser/js/js.zig @@ -77,14 +77,69 @@ pub const ArrayBuffer = struct { } }; -/// `ref` indicates bytes are not copied by `simpleZigValueToJs`; -/// instead, `values` references an already allocated memory. Note that -/// this variant assumes memory is (de)allocated by an arena allocator. -/// -/// `copy` behaves the same as `TypedArray(T)`. -pub fn Uint8ClampedArray(comptime state: enum(u1) { ref, copy }) type { - return struct { - values: if (state == .ref) []u8 else []const u8, +pub const ArrayType = enum(u8) { + Int8, + Uint8, + Uint8Clamped, + Int16, + Uint16, + Int32, + Uint32, + Float16, + Float32, + Float64, +}; + +pub fn ArrayBufferRef(comptime kind: ArrayType) type { + return extern struct { + const Self = @This(); + + const BackingInt = switch (kind) { + .Int8 => i8, + .Uint8, .Uint8Clamped => u8, + .Int16 => i16, + .Uint16 => u16, + .Int32 => i32, + .Uint32 => u32, + .Float16 => f16, + .Float32 => f32, + .Float64 => f64, + }; + + internal: *const v8.Value, + + pub fn init(isolate: Isolate, size: usize) Self { + const bits = switch (@typeInfo(BackingInt)) { + .int => |n| n.bits, + .float => |f| f.bits, + else => unreachable, + }; + + var array_buffer: *const v8.ArrayBuffer = undefined; + if (size == 0) { + array_buffer = v8.v8__ArrayBuffer__New(isolate.handle, 0).?; + } else { + const buffer_len = size * bits / 8; + const backing_store = v8.v8__ArrayBuffer__NewBackingStore(isolate.handle, buffer_len).?; + const backing_store_ptr = v8.v8__BackingStore__TO_SHARED_PTR(backing_store); + array_buffer = v8.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?; + } + + const internal: *const v8.Value = switch (comptime kind) { + .Int8 => @ptrCast(v8.v8__Int8Array__New(array_buffer, 0, size).?), + .Uint8 => @ptrCast(v8.v8__Uint8Array__New(array_buffer, 0, size).?), + .Uint8Clamped => @ptrCast(v8.v8__Uint8ClampedArray__New(array_buffer, 0, size).?), + .Int16 => @ptrCast(v8.v8__Int16Array__New(array_buffer, 0, size).?), + .Uint16 => @ptrCast(v8.v8__Uint16Array__New(array_buffer, 0, size).?), + .Int32 => @ptrCast(v8.v8__Int32Array__New(array_buffer, 0, size).?), + .Uint32 => @ptrCast(v8.v8__Uint32Array__New(array_buffer, 0, size).?), + .Float16 => @ptrCast(v8.v8__Float16Array__New(array_buffer, 0, size).?), + .Float32 => @ptrCast(v8.v8__Float32Array__New(array_buffer, 0, size).?), + .Float64 => @ptrCast(v8.v8__Float64Array__New(array_buffer, 0, size).?), + }; + + return .{ .internal = internal }; + } }; } @@ -205,40 +260,6 @@ pub fn simpleZigValueToJs(isolate: Isolate, value: anytype, comptime fail: bool, // but this can never be valid. @compileError("Invalid TypeArray type: " ++ @typeName(value_type)); }, - Uint8ClampedArray(.ref) => { - const values = value.values; - const len = values.len; - var array_buffer: *const v8.ArrayBuffer = undefined; - if (len == 0) { - array_buffer = v8.v8__ArrayBuffer__New(isolate.handle, 0).?; - } else { - // `deleter` cannot be null. - const empty_deleter = struct { - fn deleter(_: ?*anyopaque, _: usize, _: ?*anyopaque) callconv(.c) void {} - }.deleter; - const backing_store = v8.v8__ArrayBuffer__NewBackingStore2(values.ptr, len, empty_deleter, null); - const backing_store_ptr = v8.v8__BackingStore__TO_SHARED_PTR(backing_store); - // Attach store to array buffer. - array_buffer = v8.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?; - } - return @ptrCast(v8.v8__Uint8ClampedArray__New(array_buffer, 0, len)); - }, - Uint8ClampedArray(.copy) => { - const values = value.values; - const len = values.len; - var array_buffer: *const v8.ArrayBuffer = undefined; - if (len == 0) { - array_buffer = v8.v8__ArrayBuffer__New(isolate.handle, 0).?; - } else { - const backing_store = v8.v8__ArrayBuffer__NewBackingStore(isolate.handle, len); - const data: [*]u8 = @ptrCast(@alignCast(v8.v8__BackingStore__Data(backing_store))); - @memcpy(data[0..len], @as([]const u8, @ptrCast(values))[0..len]); - const backing_store_ptr = v8.v8__BackingStore__TO_SHARED_PTR(backing_store); - // Attach store to array buffer. - array_buffer = v8.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?; - } - return @ptrCast(v8.v8__Uint8ClampedArray__New(array_buffer, 0, len)); - }, inline String, BigInt, Integer, Number, Value, Object => return value.handle, else => {}, } From 9a4cebaa1bdb71f64b3743d52676f2557a3214ca Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Tue, 17 Feb 2026 01:45:40 +0300 Subject: [PATCH 06/11] `ImageData`: prefer new typed array type --- src/browser/webapi/ImageData.zig | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/browser/webapi/ImageData.zig b/src/browser/webapi/ImageData.zig index faf65c29..ece60ec0 100644 --- a/src/browser/webapi/ImageData.zig +++ b/src/browser/webapi/ImageData.zig @@ -29,8 +29,7 @@ const Page = @import("../Page.zig"); const ImageData = @This(); _width: u32, _height: u32, -/// Can be mutated from both Zig and JS ends; see `js.Uint8ClampedArray(.ref)`. -_data: []u8, +_data: js.ArrayBufferRef(.Uint8Clamped), pub const ConstructorSettings = struct { /// Specifies the color space of the image data. @@ -68,14 +67,14 @@ pub fn constructor( } const size = width * height * 4; - const mem = try page.arena.alloc(u8, size); - // Zero-init since debug mode fills w/ char 170. - @memset(mem, 0); + //const mem = try page.arena.alloc(u8, size); + //// Zero-init since debug mode fills w/ char 170. + //@memset(mem, 0); return page._factory.create(ImageData{ ._width = width, ._height = height, - ._data = mem, + ._data = page.js.createTypedArray(.Uint8Clamped, size), }); } @@ -95,8 +94,8 @@ pub fn getColorSpace(_: *const ImageData) String { return comptime .wrap("srgb"); } -pub fn getData(self: *const ImageData) js.Uint8ClampedArray(.ref) { - return .{ .values = self._data }; +pub fn getData(self: *const ImageData) js.ArrayBufferRef(.Uint8Clamped) { + return self._data; } pub const JsApi = struct { From 3c01e24f02776989ec7b0db28bddd50a0000271c Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Tue, 17 Feb 2026 02:18:13 +0300 Subject: [PATCH 07/11] `ImageData`: remove unnecessary comments --- src/browser/webapi/ImageData.zig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/browser/webapi/ImageData.zig b/src/browser/webapi/ImageData.zig index ece60ec0..13948993 100644 --- a/src/browser/webapi/ImageData.zig +++ b/src/browser/webapi/ImageData.zig @@ -67,10 +67,6 @@ pub fn constructor( } const size = width * height * 4; - //const mem = try page.arena.alloc(u8, size); - //// Zero-init since debug mode fills w/ char 170. - //@memset(mem, 0); - return page._factory.create(ImageData{ ._width = width, ._height = height, From cfa9427d7cfe48e610ece6733b578e57c375a114 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Tue, 17 Feb 2026 02:18:43 +0300 Subject: [PATCH 08/11] `ImageData`: make sure that width and height are not 0 --- src/browser/webapi/ImageData.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/browser/webapi/ImageData.zig b/src/browser/webapi/ImageData.zig index 13948993..663aaf51 100644 --- a/src/browser/webapi/ImageData.zig +++ b/src/browser/webapi/ImageData.zig @@ -58,6 +58,10 @@ pub fn constructor( maybe_settings: ?ConstructorSettings, page: *Page, ) !*ImageData { + if (width == 0 or height == 0) { + return error.IndexSizeError; + } + const settings: ConstructorSettings = maybe_settings orelse .{}; if (settings.colorSpace.eql(comptime .wrap("srgb")) == false) { return error.TypeError; From 842df0d11275ff110cddcd9e4edfc9a4f14d9ba6 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Tue, 17 Feb 2026 02:46:36 +0300 Subject: [PATCH 09/11] `extern struct` -> `struct` --- src/browser/js/js.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/js/js.zig b/src/browser/js/js.zig index d76d2e7e..0abb3d86 100644 --- a/src/browser/js/js.zig +++ b/src/browser/js/js.zig @@ -91,7 +91,7 @@ pub const ArrayType = enum(u8) { }; pub fn ArrayBufferRef(comptime kind: ArrayType) type { - return extern struct { + return struct { const Self = @This(); const BackingInt = switch (kind) { From d4e24dabc23f829abc53f06cdde28ccab5b15dff Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Tue, 17 Feb 2026 02:47:51 +0300 Subject: [PATCH 10/11] `internal` -> `handle` --- src/browser/js/Local.zig | 2 +- src/browser/js/js.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser/js/Local.zig b/src/browser/js/Local.zig index 281449a9..5a7863ad 100644 --- a/src/browser/js/Local.zig +++ b/src/browser/js/Local.zig @@ -311,7 +311,7 @@ pub fn zigValueToJs(self: *const Local, value: anytype, comptime opts: CallOpts) js.ArrayBufferRef(.Int32), js.ArrayBufferRef(.Uint32), js.ArrayBufferRef(.Float16), js.ArrayBufferRef(.Float32), js.ArrayBufferRef(.Float64), => { - return .{ .local = self, .handle = value.internal }; + return .{ .local = self, .handle = value.handle }; }, inline diff --git a/src/browser/js/js.zig b/src/browser/js/js.zig index 0abb3d86..de1c8e61 100644 --- a/src/browser/js/js.zig +++ b/src/browser/js/js.zig @@ -106,7 +106,7 @@ pub fn ArrayBufferRef(comptime kind: ArrayType) type { .Float64 => f64, }; - internal: *const v8.Value, + handle: *const v8.Value, pub fn init(isolate: Isolate, size: usize) Self { const bits = switch (@typeInfo(BackingInt)) { From 094270dff72edecc7709cddfd919a0b27ab8bc55 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Tue, 17 Feb 2026 02:48:30 +0300 Subject: [PATCH 11/11] prefer snake case in enums --- src/browser/js/Local.zig | 8 ++--- src/browser/js/js.zig | 62 ++++++++++++++++---------------- src/browser/webapi/ImageData.zig | 6 ++-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/browser/js/Local.zig b/src/browser/js/Local.zig index 5a7863ad..334700e1 100644 --- a/src/browser/js/Local.zig +++ b/src/browser/js/Local.zig @@ -306,10 +306,10 @@ pub fn zigValueToJs(self: *const Local, value: anytype, comptime opts: CallOpts) js.Value => return value, js.Exception => return .{ .local = self, .handle = isolate.throwException(value.handle) }, - js.ArrayBufferRef(.Int8), js.ArrayBufferRef(.Uint8), js.ArrayBufferRef(.Uint8Clamped), - js.ArrayBufferRef(.Int16), js.ArrayBufferRef(.Uint16), - js.ArrayBufferRef(.Int32), js.ArrayBufferRef(.Uint32), - js.ArrayBufferRef(.Float16), js.ArrayBufferRef(.Float32), js.ArrayBufferRef(.Float64), + js.ArrayBufferRef(.int8), js.ArrayBufferRef(.uint8), js.ArrayBufferRef(.uint8_clamped), + js.ArrayBufferRef(.int16), js.ArrayBufferRef(.uint16), + js.ArrayBufferRef(.int32), js.ArrayBufferRef(.uint32), + js.ArrayBufferRef(.float16), js.ArrayBufferRef(.float32), js.ArrayBufferRef(.float64), => { return .{ .local = self, .handle = value.handle }; }, diff --git a/src/browser/js/js.zig b/src/browser/js/js.zig index de1c8e61..3b10ee59 100644 --- a/src/browser/js/js.zig +++ b/src/browser/js/js.zig @@ -78,16 +78,16 @@ pub const ArrayBuffer = struct { }; pub const ArrayType = enum(u8) { - Int8, - Uint8, - Uint8Clamped, - Int16, - Uint16, - Int32, - Uint32, - Float16, - Float32, - Float64, + int8, + uint8, + uint8_clamped, + int16, + uint16, + int32, + uint32, + float16, + float32, + float64, }; pub fn ArrayBufferRef(comptime kind: ArrayType) type { @@ -95,15 +95,15 @@ pub fn ArrayBufferRef(comptime kind: ArrayType) type { const Self = @This(); const BackingInt = switch (kind) { - .Int8 => i8, - .Uint8, .Uint8Clamped => u8, - .Int16 => i16, - .Uint16 => u16, - .Int32 => i32, - .Uint32 => u32, - .Float16 => f16, - .Float32 => f32, - .Float64 => f64, + .int8 => i8, + .uint8, .uint8_clamped => u8, + .int16 => i16, + .uint16 => u16, + .int32 => i32, + .uint32 => u32, + .float16 => f16, + .float32 => f32, + .float64 => f64, }; handle: *const v8.Value, @@ -125,20 +125,20 @@ pub fn ArrayBufferRef(comptime kind: ArrayType) type { array_buffer = v8.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?; } - const internal: *const v8.Value = switch (comptime kind) { - .Int8 => @ptrCast(v8.v8__Int8Array__New(array_buffer, 0, size).?), - .Uint8 => @ptrCast(v8.v8__Uint8Array__New(array_buffer, 0, size).?), - .Uint8Clamped => @ptrCast(v8.v8__Uint8ClampedArray__New(array_buffer, 0, size).?), - .Int16 => @ptrCast(v8.v8__Int16Array__New(array_buffer, 0, size).?), - .Uint16 => @ptrCast(v8.v8__Uint16Array__New(array_buffer, 0, size).?), - .Int32 => @ptrCast(v8.v8__Int32Array__New(array_buffer, 0, size).?), - .Uint32 => @ptrCast(v8.v8__Uint32Array__New(array_buffer, 0, size).?), - .Float16 => @ptrCast(v8.v8__Float16Array__New(array_buffer, 0, size).?), - .Float32 => @ptrCast(v8.v8__Float32Array__New(array_buffer, 0, size).?), - .Float64 => @ptrCast(v8.v8__Float64Array__New(array_buffer, 0, size).?), + const handle: *const v8.Value = switch (comptime kind) { + .int8 => @ptrCast(v8.v8__Int8Array__New(array_buffer, 0, size).?), + .uint8 => @ptrCast(v8.v8__Uint8Array__New(array_buffer, 0, size).?), + .uint8_clamped => @ptrCast(v8.v8__Uint8ClampedArray__New(array_buffer, 0, size).?), + .int16 => @ptrCast(v8.v8__Int16Array__New(array_buffer, 0, size).?), + .uint16 => @ptrCast(v8.v8__Uint16Array__New(array_buffer, 0, size).?), + .int32 => @ptrCast(v8.v8__Int32Array__New(array_buffer, 0, size).?), + .uint32 => @ptrCast(v8.v8__Uint32Array__New(array_buffer, 0, size).?), + .float16 => @ptrCast(v8.v8__Float16Array__New(array_buffer, 0, size).?), + .float32 => @ptrCast(v8.v8__Float32Array__New(array_buffer, 0, size).?), + .float64 => @ptrCast(v8.v8__Float64Array__New(array_buffer, 0, size).?), }; - return .{ .internal = internal }; + return .{ .handle = handle }; } }; } diff --git a/src/browser/webapi/ImageData.zig b/src/browser/webapi/ImageData.zig index 663aaf51..eed265fc 100644 --- a/src/browser/webapi/ImageData.zig +++ b/src/browser/webapi/ImageData.zig @@ -29,7 +29,7 @@ const Page = @import("../Page.zig"); const ImageData = @This(); _width: u32, _height: u32, -_data: js.ArrayBufferRef(.Uint8Clamped), +_data: js.ArrayBufferRef(.uint8_clamped), pub const ConstructorSettings = struct { /// Specifies the color space of the image data. @@ -74,7 +74,7 @@ pub fn constructor( return page._factory.create(ImageData{ ._width = width, ._height = height, - ._data = page.js.createTypedArray(.Uint8Clamped, size), + ._data = page.js.createTypedArray(.uint8_clamped, size), }); } @@ -94,7 +94,7 @@ pub fn getColorSpace(_: *const ImageData) String { return comptime .wrap("srgb"); } -pub fn getData(self: *const ImageData) js.ArrayBufferRef(.Uint8Clamped) { +pub fn getData(self: *const ImageData) js.ArrayBufferRef(.uint8_clamped) { return self._data; }