Skip to content

Commit 4a6cee0

Browse files
committed
Fix HTMLImageElement
HTMLImageElement is the correct class name. However, it has a "legacy factory": Image (i.e. new Image()).
1 parent 7202d75 commit 4a6cee0

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/browser/html/elements.zig

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub const Interfaces = .{
5757
HTMLHtmlElement,
5858
HTMLIFrameElement,
5959
HTMLImageElement,
60+
HTMLImageElement.Factory,
6061
HTMLInputElement,
6162
HTMLLIElement,
6263
HTMLLabelElement,
@@ -565,15 +566,6 @@ pub const HTMLImageElement = struct {
565566
pub const Self = parser.Image;
566567
pub const prototype = *HTMLElement;
567568
pub const subtype = .node;
568-
pub const js_name = "Image";
569-
570-
pub fn constructor(width: ?u32, height: ?u32, page: *const Page) !*parser.Image {
571-
const element = try parser.documentCreateElement(parser.documentHTMLToDocument(page.window.document), "img");
572-
const image: *parser.Image = @ptrCast(element);
573-
if (width) |width_| try parser.imageSetWidth(image, width_);
574-
if (height) |height_| try parser.imageSetHeight(image, height_);
575-
return image;
576-
}
577569

578570
pub fn get_alt(self: *parser.Image) ![]const u8 {
579571
return try parser.imageGetAlt(self);
@@ -611,6 +603,21 @@ pub const HTMLImageElement = struct {
611603
pub fn set_isMap(self: *parser.Image, is_map: bool) !void {
612604
try parser.imageSetIsMap(self, is_map);
613605
}
606+
607+
pub const Factory = struct {
608+
pub const js_name = "Image";
609+
pub const subtype = .node;
610+
pub const js_legacy_factory = true;
611+
pub const prototype = *HTMLImageElement;
612+
613+
pub fn constructor(width: ?u32, height: ?u32, page: *const Page) !*parser.Image {
614+
const element = try parser.documentCreateElement(parser.documentHTMLToDocument(page.window.document), "img");
615+
const image: *parser.Image = @ptrCast(element);
616+
if (width) |width_| try parser.imageSetWidth(image, width_);
617+
if (height) |height_| try parser.imageSetHeight(image, height_);
618+
return image;
619+
}
620+
};
614621
};
615622

616623
pub const HTMLInputElement = struct {

src/runtime/js.zig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2222,8 +2222,14 @@ const TypeMeta = struct {
22222222
subtype: ?SubType,
22232223
};
22242224

2225+
// When we map a Zig instance into a JsObject, we'll normally store the a
2226+
// TaggedAnyOpaque (TAO) inside of the JsObject's internal field. This requires
2227+
// ensuring that the instance template has an InternalFieldCount of 1. However,
2228+
// for empty objects, we don't need to store the TAO, because we can't just cast
2229+
// one empty object to another, so for those, as an optimization, we do not set
2230+
// the InternalFieldCount.
22252231
fn isEmpty(comptime T: type) bool {
2226-
return @typeInfo(T) != .@"opaque" and @sizeOf(T) == 0;
2232+
return @typeInfo(T) != .@"opaque" and @sizeOf(T) == 0 and @hasDecl(T, "js_legacy_factory") == false;
22272233
}
22282234

22292235
// Responsible for calling Zig functions from JS invokations. This could

0 commit comments

Comments
 (0)