Skip to content

Commit 4e9f7c7

Browse files
committed
Intl and IFrame skeleton
1 parent 4c0437b commit 4e9f7c7

File tree

8 files changed

+65
-0
lines changed

8 files changed

+65
-0
lines changed

src/browser/js/bridge.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ pub const JsApis = flattenTypes(&.{
447447
@import("../webapi/Document.zig"),
448448
@import("../webapi/HTMLDocument.zig"),
449449
@import("../webapi/History.zig"),
450+
@import("../webapi/intl/Intl.zig"),
450451
@import("../webapi/KeyValueList.zig"),
451452
@import("../webapi/DocumentFragment.zig"),
452453
@import("../webapi/DocumentType.zig"),
@@ -458,6 +459,7 @@ pub const JsApis = flattenTypes(&.{
458459
@import("../webapi/Element.zig"),
459460
@import("../webapi/element/Attribute.zig"),
460461
@import("../webapi/element/Html.zig"),
462+
@import("../webapi/element/html/IFrame.zig"),
461463
@import("../webapi/element/html/Anchor.zig"),
462464
@import("../webapi/element/html/Body.zig"),
463465
@import("../webapi/element/html/BR.zig"),

src/browser/tests/document/document.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
testing.expectEqual(null, document.parentNode);
1212
testing.expectEqual(undefined, document.getCurrentScript);
1313
testing.expectEqual("http://127.0.0.1:9582/src/browser/tests/document/document.html", document.URL);
14+
testing.expectEqual(window, document.defaultView);
1415
</script>
1516

1617
<script id=headAndbody>

src/browser/webapi/Document.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ pub const JsApi = struct {
195195
pub const querySelectorAll = bridge.function(Document.querySelectorAll, .{ .dom_exception = true });
196196
pub const getElementsByTagName = bridge.function(Document.getElementsByTagName, .{});
197197
pub const getElementsByClassName = bridge.function(Document.getElementsByClassName, .{});
198+
pub const defaultView = bridge.accessor(struct{
199+
fn defaultView(_: *const Document, page: *Page) *@import("Window.zig") {
200+
return page.window;
201+
}
202+
}.defaultView, null, .{.cache = "defaultView"});
198203
};
199204

200205
const testing = @import("../../testing.zig");

src/browser/webapi/Element.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub fn getTagNameLower(self: *const Element) []const u8 {
107107
.head => "head",
108108
.html => "html",
109109
.hr => "hr",
110+
.iframe => "iframe",
110111
.img => "img",
111112
.input => "input",
112113
.li => "li",
@@ -148,6 +149,7 @@ pub fn getTagNameSpec(self: *const Element, buf: []u8) []const u8 {
148149
.head => "HEAD",
149150
.html => "HTML",
150151
.hr => "HR",
152+
.iframe => "IFRAME",
151153
.img => "IMG",
152154
.input => "INPUT",
153155
.li => "LI",
@@ -522,6 +524,7 @@ pub fn getTag(self: *const Element) Tag {
522524
.form => .form,
523525
.p => .p,
524526
.custom => .custom,
527+
.iframe => .iframe,
525528
.img => .img,
526529
.br => .br,
527530
.button => .button,
@@ -577,6 +580,7 @@ pub const Tag = enum {
577580
hr,
578581
html,
579582
i,
583+
iframe,
580584
img,
581585
input,
582586
li,

src/browser/webapi/Window.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const log = @import("../../log.zig");
66
const Page = @import("../Page.zig");
77
const Console = @import("Console.zig");
88
const History = @import("History.zig");
9+
const Intl = @import("intl/Intl.zig");
910
const Navigator = @import("Navigator.zig");
1011
const Document = @import("Document.zig");
1112
const Location = @import("Location.zig");
@@ -52,6 +53,10 @@ pub fn getNavigator(_: *const Window) Navigator {
5253
return .{};
5354
}
5455

56+
pub fn getIntl(_: *const Window) Intl {
57+
return .{};
58+
}
59+
5560
pub fn getLocalStorage(self: *const Window) *storage.Lookup {
5661
return &self._storage_bucket.local;
5762
}
@@ -266,6 +271,7 @@ pub const JsApi = struct {
266271
pub const parent = bridge.accessor(Window.getWindow, null, .{ .cache = "parent" });
267272
pub const console = bridge.accessor(Window.getConsole, null, .{ .cache = "console" });
268273
pub const navigator = bridge.accessor(Window.getNavigator, null, .{ .cache = "navigator" });
274+
pub const Intl = bridge.accessor(Window.getIntl, null, .{ .cache = "Intl" });
269275
pub const localStorage = bridge.accessor(Window.getLocalStorage, null, .{ .cache = "localStorage" });
270276
pub const sessionStorage = bridge.accessor(Window.getSessionStorage, null, .{ .cache = "sessionStorage" });
271277
pub const document = bridge.accessor(Window.getDocument, null, .{ .cache = "document" });

src/browser/webapi/element/Html.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub const TextArea = @import("html/TextArea.zig");
3131
pub const Paragraph = @import("html/Paragraph.zig");
3232
pub const Select = @import("html/Select.zig");
3333
pub const Option = @import("html/Option.zig");
34+
pub const IFrame = @import("html/IFrame.zig");
3435

3536
const HtmlElement = @This();
3637

@@ -51,6 +52,7 @@ pub const Type = union(enum) {
5152
html: Html,
5253
hr: HR,
5354
img: Image,
55+
iframe: IFrame,
5456
input: *Input,
5557
li: LI,
5658
link: Link,
@@ -89,6 +91,7 @@ pub fn className(self: *const HtmlElement) []const u8 {
8991
.p => "[object HtmlParagraphElement]",
9092
.custom => "[object CUSTOM-TODO]",
9193
.img => "[object HTMLImageElement]",
94+
.iframe => "[object HTMLIFrameElement]",
9295
.br => "[object HTMLBRElement]",
9396
.button => "[object HTMLButtonElement]",
9497
.heading => "[object HTMLHeadingElement]",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const js = @import("../../../js/js.zig");
2+
const Node = @import("../../Node.zig");
3+
const Element = @import("../../Element.zig");
4+
const HtmlElement = @import("../Html.zig");
5+
6+
const IFrame = @This();
7+
_proto: *HtmlElement,
8+
9+
pub fn asElement(self: *IFrame) *Element {
10+
return self._proto._proto;
11+
}
12+
pub fn asNode(self: *IFrame) *Node {
13+
return self.asElement().asNode();
14+
}
15+
16+
pub const JsApi = struct {
17+
pub const bridge = js.Bridge(IFrame);
18+
19+
pub const Meta = struct {
20+
pub const name = "HTMLIFrameElement";
21+
pub const prototype_chain = bridge.prototypeChain();
22+
pub var class_id: bridge.ClassId = undefined;
23+
};
24+
};

src/browser/webapi/intl/Intl.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const std = @import("std");
2+
const js = @import("../../js/js.zig");
3+
4+
const Intl = @This();
5+
6+
// Skeleton implementation with no actual functionality yet.
7+
// This allows `if (Intl)` checks to pass, while property checks
8+
// like `if (Intl.Locale)` will return undefined.
9+
// We can add actual implementations as we encounter real-world use cases.
10+
11+
pub const JsApi = struct {
12+
pub const bridge = js.Bridge(Intl);
13+
14+
pub const Meta = struct {
15+
pub const name = "Intl";
16+
pub var class_id: bridge.ClassId = undefined;
17+
pub const prototype_chain = bridge.prototypeChain();
18+
pub const empty_with_no_proto = true;
19+
};
20+
};

0 commit comments

Comments
 (0)