Skip to content

Commit 4c0437b

Browse files
committed
History placeholder
1 parent de71b97 commit 4c0437b

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

src/browser/Factory.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ _size_112_8: MemoryPoolAligned([112]u8, .@"8"),
4646
_size_120_8: MemoryPoolAligned([120]u8, .@"8"),
4747
_size_128_8: MemoryPoolAligned([128]u8, .@"8"),
4848
_size_144_8: MemoryPoolAligned([144]u8, .@"8"),
49+
_size_152_8: MemoryPoolAligned([152]u8, .@"8"),
4950
_size_456_8: MemoryPoolAligned([456]u8, .@"8"),
5051
_size_520_8: MemoryPoolAligned([520]u8, .@"8"),
5152
_size_648_8: MemoryPoolAligned([648]u8, .@"8"),
@@ -72,6 +73,7 @@ pub fn init(page: *Page) Factory {
7273
._size_120_8 = MemoryPoolAligned([120]u8, .@"8").init(page.arena),
7374
._size_128_8 = MemoryPoolAligned([128]u8, .@"8").init(page.arena),
7475
._size_144_8 = MemoryPoolAligned([144]u8, .@"8").init(page.arena),
76+
._size_152_8 = MemoryPoolAligned([152]u8, .@"8").init(page.arena),
7577
._size_456_8 = MemoryPoolAligned([456]u8, .@"8").init(page.arena),
7678
._size_520_8 = MemoryPoolAligned([520]u8, .@"8").init(page.arena),
7779
._size_648_8 = MemoryPoolAligned([648]u8, .@"8").init(page.arena),
@@ -231,6 +233,7 @@ pub fn createT(self: *Factory, comptime T: type) !*T {
231233
if (comptime SO == 120) return @ptrCast(try self._size_120_8.create());
232234
if (comptime SO == 128) return @ptrCast(try self._size_128_8.create());
233235
if (comptime SO == 144) return @ptrCast(try self._size_144_8.create());
236+
if (comptime SO == 152) return @ptrCast(try self._size_152_8.create());
234237
if (comptime SO == 456) return @ptrCast(try self._size_456_8.create());
235238
if (comptime SO == 520) return @ptrCast(try self._size_520_8.create());
236239
if (comptime SO == 648) return @ptrCast(try self._size_648_8.create());
@@ -311,6 +314,7 @@ fn destroyChain(self: *Factory, value: anytype, comptime first: bool) void {
311314
120 => self._size_120_8.destroy(@ptrCast(value)),
312315
128 => self._size_128_8.destroy(@ptrCast(value)),
313316
144 => self._size_144_8.destroy(@ptrCast(value)),
317+
152 => self._size_152_8.destroy(@ptrCast(value)),
314318
456 => self._size_456_8.destroy(@ptrCast(value)),
315319
520 => self._size_520_8.destroy(@ptrCast(value)),
316320
648 => self._size_648_8.destroy(@ptrCast(value)),

src/browser/Page.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const Mime = @import("Mime.zig");
1616
const Factory = @import("Factory.zig");
1717
const Session = @import("Session.zig");
1818
const Scheduler = @import("Scheduler.zig");
19+
const History = @import("webapi/History.zig");
1920
const EventManager = @import("EventManager.zig");
2021
const ScriptManager = @import("ScriptManager.zig");
2122
const polyfill = @import("polyfill/polyfill.zig");
@@ -142,6 +143,7 @@ fn reset(self: *Page, comptime initializing: bool) !void {
142143
self.window = try self._factory.eventTarget(Window{
143144
._document = self.document,
144145
._storage_bucket = storage_bucket,
146+
._history = History.init(self),
145147
._proto = undefined,
146148
._location = &default_location,
147149
});

src/browser/js/bridge.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ pub const JsApis = flattenTypes(&.{
446446
@import("../webapi/css/MediaQueryList.zig"),
447447
@import("../webapi/Document.zig"),
448448
@import("../webapi/HTMLDocument.zig"),
449+
@import("../webapi/History.zig"),
449450
@import("../webapi/KeyValueList.zig"),
450451
@import("../webapi/DocumentFragment.zig"),
451452
@import("../webapi/DocumentType.zig"),

src/browser/webapi/History.zig

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const std = @import("std");
2+
const js = @import("../js/js.zig");
3+
4+
const Page = @import("../Page.zig");
5+
6+
const History = @This();
7+
8+
_page: *Page,
9+
_length: u32 = 1,
10+
_state: ?js.Object = null,
11+
12+
pub fn init(page: *Page) History {
13+
return .{
14+
._page = page,
15+
};
16+
}
17+
18+
pub fn deinit(self: *History) void {
19+
if (self._state) |state| {
20+
js.q.JS_FreeValue(self._page.js.ctx, state.value);
21+
}
22+
}
23+
24+
pub fn getLength(self: *const History) u32 {
25+
return self._length;
26+
}
27+
28+
pub fn getState(self: *const History) ?js.Object {
29+
return self._state;
30+
}
31+
32+
pub fn pushState(self: *History, state: js.Object, _title: []const u8, url: ?[]const u8, page: *Page) !void {
33+
_ = _title; // title is ignored in modern browsers
34+
_ = url; // For minimal implementation, we don't actually navigate
35+
_ = page;
36+
37+
self._state = state;
38+
self._length += 1;
39+
}
40+
41+
pub fn replaceState(self: *History, state: js.Object, _title: []const u8, url: ?[]const u8, page: *Page) !void {
42+
_ = _title;
43+
_ = url;
44+
_ = page;
45+
self._state = state;
46+
// Note: replaceState doesn't change length
47+
}
48+
49+
pub fn back(self: *History, page: *Page) void {
50+
_ = self;
51+
_ = page;
52+
// Minimal implementation: no-op
53+
}
54+
55+
pub fn forward(self: *History, page: *Page) void {
56+
_ = self;
57+
_ = page;
58+
// Minimal implementation: no-op
59+
}
60+
61+
pub fn go(self: *History, delta: i32, page: *Page) void {
62+
_ = self;
63+
_ = delta;
64+
_ = page;
65+
// Minimal implementation: no-op
66+
}
67+
68+
pub const JsApi = struct {
69+
pub const bridge = js.Bridge(History);
70+
71+
pub const Meta = struct {
72+
pub const name = "History";
73+
pub var class_id: bridge.ClassId = 0;
74+
pub const prototype_chain = bridge.prototypeChain();
75+
};
76+
77+
pub const length = bridge.accessor(History.getLength, null, .{});
78+
pub const state = bridge.accessor(History.getState, null, .{});
79+
pub const pushState = bridge.function(History.pushState, .{});
80+
pub const replaceState = bridge.function(History.replaceState, .{});
81+
pub const back = bridge.function(History.back, .{});
82+
pub const forward = bridge.function(History.forward, .{});
83+
pub const go = bridge.function(History.go, .{});
84+
};

src/browser/webapi/Window.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const builtin = @import("builtin");
55
const log = @import("../../log.zig");
66
const Page = @import("../Page.zig");
77
const Console = @import("Console.zig");
8+
const History = @import("History.zig");
89
const Navigator = @import("Navigator.zig");
910
const Document = @import("Document.zig");
1011
const Location = @import("Location.zig");
@@ -20,6 +21,7 @@ _proto: *EventTarget,
2021
_document: *Document,
2122
_console: Console = .init,
2223
_navigator: Navigator = .init,
24+
_history: History,
2325
_storage_bucket: *storage.Bucket,
2426
_on_load: ?js.Function = null,
2527
_location: *Location,
@@ -62,6 +64,10 @@ pub fn getLocation(self: *const Window) *Location {
6264
return self._location;
6365
}
6466

67+
pub fn getHistory(self: *Window) *History {
68+
return &self._history;
69+
}
70+
6571
pub fn getOnLoad(self: *const Window) ?js.Function {
6672
return self._on_load;
6773
}
@@ -264,6 +270,7 @@ pub const JsApi = struct {
264270
pub const sessionStorage = bridge.accessor(Window.getSessionStorage, null, .{ .cache = "sessionStorage" });
265271
pub const document = bridge.accessor(Window.getDocument, null, .{ .cache = "document" });
266272
pub const location = bridge.accessor(Window.getLocation, null, .{ .cache = "location" });
273+
pub const history = bridge.accessor(Window.getHistory, null, .{ .cache = "history" });
267274
pub const onload = bridge.accessor(Window.getOnLoad, Window.setOnLoad, .{});
268275
pub const fetch = bridge.function(Window.fetch, .{});
269276
pub const setTimeout = bridge.function(Window.setTimeout, .{});

0 commit comments

Comments
 (0)