@@ -28,15 +28,67 @@ const checkCases = jsruntime.test_utils.checkCases;
2828pub const History = struct {
2929 pub const mem_guarantied = true ;
3030
31- const ScrollRestaurationMode = enum {
31+ const ScrollRestorationMode = enum {
3232 auto ,
3333 manual ,
3434 };
3535
36- scrollRestauration : ScrollRestaurationMode = .audio ,
36+ scrollRestoration : ScrollRestorationMode = .auto ,
37+ state : ? jsruntime.JSObject = null ,
3738
38- pub fn get_length (_ : * History ) u64 {
39- return 0 ;
39+ // count tracks the history length until we implement correctly pushstate.
40+ count : u32 = 0 ,
41+
42+ pub fn get_length (self : * History ) u32 {
43+ // TODO return the real histry length value.
44+ return self .count ;
45+ }
46+
47+ pub fn get_scrollRestoration (self : * History ) []const u8 {
48+ return switch (self .scrollRestoration ) {
49+ .auto = > "auto" ,
50+ .manual = > "manual" ,
51+ };
52+ }
53+
54+ pub fn set_scrollRestoration (self : * History , mode : []const u8 ) void {
55+ if (std .mem .eql (u8 , "manual" , mode )) self .scrollRestoration = .manual ;
56+ if (std .mem .eql (u8 , "auto" , mode )) self .scrollRestoration = .auto ;
57+ }
58+
59+ // TODO
60+ pub fn get_state (_ : * History ) ? void {
61+ return null ;
62+ }
63+
64+ // TODO
65+ pub fn _pushState (self : * History , data : []const u8 , _ : ? []const u8 , url : ? []const u8 ) void {
66+ self .count += 1 ;
67+ _ = url ;
68+ _ = data ;
69+ }
70+
71+ // TODO
72+ pub fn _replacetate (self : * History , data : []const u8 , _ : ? []const u8 , url : ? []const u8 ) void {
73+ _ = self ;
74+ _ = url ;
75+ _ = data ;
76+ }
77+
78+ // TODO
79+ pub fn _go (self : * History , delta : ? i32 ) void {
80+ _ = self ;
81+ _ = delta ;
82+ }
83+
84+ // TODO
85+ pub fn _back (self : * History ) void {
86+ _ = self ;
87+ }
88+
89+ // TODO
90+ pub fn _forward (self : * History ) void {
91+ _ = self ;
4092 }
4193};
4294
@@ -48,7 +100,26 @@ pub fn testExecFn(
48100 js_env : * jsruntime.Env ,
49101) anyerror ! void {
50102 var history = [_ ]Case {
51- .{ .src = "true" , .ex = "true" },
103+ .{ .src = "history.scrollRestoration" , .ex = "auto" },
104+ .{ .src = "history.scrollRestoration = 'manual'" , .ex = "manual" },
105+ .{ .src = "history.scrollRestoration = 'foo'" , .ex = "foo" },
106+ .{ .src = "history.scrollRestoration" , .ex = "manual" },
107+ .{ .src = "history.scrollRestoration = 'auto'" , .ex = "auto" },
108+ .{ .src = "history.scrollRestoration" , .ex = "auto" },
109+
110+ .{ .src = "history.state" , .ex = "null" },
111+
112+ .{ .src = "history.pushState({}, null, '')" , .ex = "undefined" },
113+
114+ .{ .src = "history.replaceState({}, null, '')" , .ex = "undefined" },
115+
116+ .{ .src = "history.go()" , .ex = "undefined" },
117+ .{ .src = "history.go(1)" , .ex = "undefined" },
118+ .{ .src = "history.go(-1)" , .ex = "undefined" },
119+
120+ .{ .src = "history.forward()" , .ex = "undefined" },
121+
122+ .{ .src = "history.back()" , .ex = "undefined" },
52123 };
53124 try checkCases (js_env , & history );
54125}
0 commit comments