Lightpanda: the headless browser designed for AI and automation
Reflect source width/height as unsigned long per spec
Karl Seguin67f947f606fb
diff --git a/src/browser/tests/element/html/source.html b/src/browser/tests/element/html/source.htmlindex 29c93c343..461cb55ab 100644--- a/src/browser/tests/element/html/source.html+++ b/src/browser/tests/element/html/source.html@@ -13,8 +13,8 @@testing.expectEqual('100vw', s1.sizes);testing.expectEqual('(min-width: 600px)', s1.media);testing.expectEqual('video/webm', s1.type);- testing.expectEqual('640', s1.width);- testing.expectEqual('480', s1.height);+ testing.expectEqual(640, s1.width);+ testing.expectEqual(480, s1.height);const s2 = document.getElementById('s2');testing.expectEqual('', s2.src);@@ -22,8 +22,8 @@testing.expectEqual('', s2.sizes);testing.expectEqual('', s2.media);testing.expectEqual('', s2.type);- testing.expectEqual('', s2.width);- testing.expectEqual('', s2.height);+ testing.expectEqual(0, s2.width);+ testing.expectEqual(0, s2.height);}</script>@@ -51,15 +51,17 @@s.setAttribute('type', 'image/svg+xml');testing.expectEqual('image/svg+xml', s.type);- s.width = '320';+ s.width = 320;testing.expectEqual('320', s.getAttribute('width'));s.setAttribute('width', '160');- testing.expectEqual('160', s.width);+ testing.expectEqual(160, s.width);+ s.setAttribute('width', 'not-a-number');+ testing.expectEqual(0, s.width);- s.height = '240';+ s.height = 240;testing.expectEqual('240', s.getAttribute('height'));s.setAttribute('height', '120');- testing.expectEqual('120', s.height);+ testing.expectEqual(120, s.height);}</script>diff --git a/src/browser/webapi/element/html/Source.zig b/src/browser/webapi/element/html/Source.zigindex f654959d7..24c24042a 100644--- a/src/browser/webapi/element/html/Source.zig+++ b/src/browser/webapi/element/html/Source.zig@@ -1,3 +1,4 @@+const std = @import("std");const js = @import("../../../js/js.zig");const Frame = @import("../../../Frame.zig");const Node = @import("../../Node.zig");@@ -63,20 +64,24 @@ pub fn setType(self: *Source, value: []const u8, frame: *Frame) !void {try self.asElement().setAttributeSafe(comptime .wrap("type"), .wrap(value), frame);}-pub fn getWidth(self: *const Source) []const u8 {- return self.asConstElement().getAttributeSafe(comptime .wrap("width")) orelse "";+pub fn getWidth(self: *const Source) u32 {+ const attr = self.asConstElement().getAttributeSafe(comptime .wrap("width")) orelse return 0;+ return std.fmt.parseUnsigned(u32, attr, 10) catch 0;}-pub fn setWidth(self: *Source, value: []const u8, frame: *Frame) !void {- try self.asElement().setAttributeSafe(comptime .wrap("width"), .wrap(value), frame);+pub fn setWidth(self: *Source, value: u32, frame: *Frame) !void {+ const str = try std.fmt.allocPrint(frame.call_arena, "{d}", .{value});+ try self.asElement().setAttributeSafe(comptime .wrap("width"), .wrap(str), frame);}-pub fn getHeight(self: *const Source) []const u8 {- return self.asConstElement().getAttributeSafe(comptime .wrap("height")) orelse "";+pub fn getHeight(self: *const Source) u32 {+ const attr = self.asConstElement().getAttributeSafe(comptime .wrap("height")) orelse return 0;+ return std.fmt.parseUnsigned(u32, attr, 10) catch 0;}-pub fn setHeight(self: *Source, value: []const u8, frame: *Frame) !void {- try self.asElement().setAttributeSafe(comptime .wrap("height"), .wrap(value), frame);+pub fn setHeight(self: *Source, value: u32, frame: *Frame) !void {+ const str = try std.fmt.allocPrint(frame.call_arena, "{d}", .{value});+ try self.asElement().setAttributeSafe(comptime .wrap("height"), .wrap(str), frame);}pub const JsApi = struct {