@@ -563,6 +563,52 @@ pub const HTMLImageElement = struct {
563563 pub const Self = parser .Image ;
564564 pub const prototype = * HTMLElement ;
565565 pub const subtype = .node ;
566+ pub const js_name = "Image" ;
567+
568+ pub fn constructor (width : ? u32 , height : ? u32 , state : * const SessionState ) ! * parser.Image {
569+ const element = try parser .documentCreateElement (parser .documentHTMLToDocument (state .window .document ), "img" );
570+ const image : * parser.Image = @ptrCast (element );
571+ if (width ) | width_ | try parser .imageSetWidth (image , width_ );
572+ if (height ) | height_ | try parser .imageSetHeight (image , height_ );
573+ return image ;
574+ }
575+
576+ pub fn get_alt (self : * parser.Image ) ! []const u8 {
577+ return try parser .imageGetAlt (self );
578+ }
579+ pub fn set_alt (self : * parser.Image , alt : []const u8 ) ! void {
580+ try parser .imageSetAlt (self , alt );
581+ }
582+ pub fn get_src (self : * parser.Image ) ! []const u8 {
583+ return try parser .imageGetSrc (self );
584+ }
585+ pub fn set_src (self : * parser.Image , src : []const u8 ) ! void {
586+ try parser .imageSetSrc (self , src );
587+ }
588+ pub fn get_useMap (self : * parser.Image ) ! []const u8 {
589+ return try parser .imageGetUseMap (self );
590+ }
591+ pub fn set_useMap (self : * parser.Image , use_map : []const u8 ) ! void {
592+ try parser .imageSetUseMap (self , use_map );
593+ }
594+ pub fn get_height (self : * parser.Image ) ! u32 {
595+ return try parser .imageGetHeight (self );
596+ }
597+ pub fn set_height (self : * parser.Image , height : u32 ) ! void {
598+ try parser .imageSetHeight (self , height );
599+ }
600+ pub fn get_width (self : * parser.Image ) ! u32 {
601+ return try parser .imageGetWidth (self );
602+ }
603+ pub fn set_width (self : * parser.Image , width : u32 ) ! void {
604+ try parser .imageSetWidth (self , width );
605+ }
606+ pub fn get_isMap (self : * parser.Image ) ! bool {
607+ return try parser .imageGetIsMap (self );
608+ }
609+ pub fn set_isMap (self : * parser.Image , is_map : bool ) ! void {
610+ try parser .imageSetIsMap (self , is_map );
611+ }
566612};
567613
568614pub const HTMLInputElement = struct {
@@ -1059,4 +1105,31 @@ test "Browser.HTML.Element" {
10591105 .{ "document.getElementById('content').click()" , "undefined" },
10601106 .{ "click_count" , "1" },
10611107 }, .{});
1108+
1109+ // Image
1110+ try runner .testCases (&.{
1111+ // Testing constructors
1112+ .{ "(new Image).width" , "0" },
1113+ .{ "(new Image).height" , "0" },
1114+ .{ "(new Image(4)).width" , "4" },
1115+ .{ "(new Image(4, 6)).height" , "6" },
1116+
1117+ // Testing ulong property
1118+ .{ "let fruit = new Image" , null },
1119+ .{ "fruit.width" , "0" },
1120+ .{ "fruit.width = 5" , "5" },
1121+ .{ "fruit.width" , "5" },
1122+ .{ "fruit.width = '15'" , "15" },
1123+ .{ "fruit.width" , "15" },
1124+ .{ "fruit.width = 'apple'" , "apple" },
1125+ .{ "fruit.width;" , "0" },
1126+
1127+ // Testing string property
1128+ .{ "let lyric = new Image" , null },
1129+ .{ "lyric.src" , "" },
1130+ .{ "lyric.src = 'okay'" , "okay" },
1131+ .{ "lyric.src" , "okay" },
1132+ .{ "lyric.src = 15" , "15" },
1133+ .{ "lyric.src" , "15" },
1134+ }, .{});
10621135}
0 commit comments