diff --git a/src/browser/js/Object.zig b/src/browser/js/Object.zig index 082f135f..c60fe59d 100644 --- a/src/browser/js/Object.zig +++ b/src/browser/js/Object.zig @@ -114,11 +114,6 @@ pub fn format(self: Object, writer: *std.Io.Writer) !void { return writer.writeAll(str); } -pub fn toJson(self: Object, allocator: Allocator) ![]u8 { - const json_str_handle = v8.v8__JSON__Stringify(self.ctx.handle, @ptrCast(self.handle), null) orelse return error.JsException; - return self.ctx.jsStringToZig(json_str_handle, .{ .allocator = allocator }); -} - pub fn persist(self: Object) !Object { var ctx = self.ctx; diff --git a/src/browser/js/Value.zig b/src/browser/js/Value.zig index cce891a3..a4e28fe4 100644 --- a/src/browser/js/Value.zig +++ b/src/browser/js/Value.zig @@ -219,6 +219,11 @@ pub fn toStringZ(self: Value, opts: js.String.ToZigOpts) ![:0]u8 { return self._toString(true, opts); } +pub fn toJson(self: Value, allocator: Allocator) ![]u8 { + const json_str_handle = v8.v8__JSON__Stringify(self.ctx.handle, self.handle, null) orelse return error.JsException; + return self.ctx.jsStringToZig(json_str_handle, .{ .allocator = allocator }); +} + fn _toString(self: Value, comptime null_terminate: bool, opts: js.String.ToZigOpts) !(if (null_terminate) [:0]u8 else []u8) { const ctx: *js.Context = @constCast(self.ctx); diff --git a/src/browser/tests/history.html b/src/browser/tests/history.html index 2a6d3957..90df53bf 100644 --- a/src/browser/tests/history.html +++ b/src/browser/tests/history.html @@ -35,3 +35,4 @@ history.back(); + diff --git a/src/browser/webapi/History.zig b/src/browser/webapi/History.zig index 7106be56..124d57b0 100644 --- a/src/browser/webapi/History.zig +++ b/src/browser/webapi/History.zig @@ -49,7 +49,7 @@ pub fn setScrollRestoration(self: *History, str: []const u8) void { } } -pub fn pushState(_: *History, state: js.Object, _: []const u8, _url: ?[]const u8, page: *Page) !void { +pub fn pushState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8, page: *Page) !void { const arena = page._session.arena; const url = if (_url) |u| try arena.dupeZ(u8, u) else try arena.dupeZ(u8, page.url); @@ -57,7 +57,7 @@ pub fn pushState(_: *History, state: js.Object, _: []const u8, _url: ?[]const u8 _ = try page._session.navigation.pushEntry(url, .{ .source = .history, .value = json }, page, true); } -pub fn replaceState(_: *History, state: js.Object, _: []const u8, _url: ?[]const u8, page: *Page) !void { +pub fn replaceState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8, page: *Page) !void { const arena = page._session.arena; const url = if (_url) |u| try arena.dupeZ(u8, u) else try arena.dupeZ(u8, page.url); diff --git a/src/browser/webapi/PerformanceObserver.zig b/src/browser/webapi/PerformanceObserver.zig index 7e4d9c5d..0b8edd47 100644 --- a/src/browser/webapi/PerformanceObserver.zig +++ b/src/browser/webapi/PerformanceObserver.zig @@ -44,7 +44,7 @@ const DefaultDurationThreshold: f64 = 104; /// Creates a new PerformanceObserver object with the given observer callback. pub fn init(callback: js.Function, page: *Page) !*PerformanceObserver { return page._factory.create(PerformanceObserver{ - ._callback = callback, + ._callback = try callback.persist(), ._duration_threshold = DefaultDurationThreshold, ._interests = 0, ._entries = .{}, diff --git a/src/browser/webapi/navigation/Navigation.zig b/src/browser/webapi/navigation/Navigation.zig index e1afa334..c257d1d2 100644 --- a/src/browser/webapi/navigation/Navigation.zig +++ b/src/browser/webapi/navigation/Navigation.zig @@ -247,8 +247,8 @@ pub fn replaceEntry( } const NavigateOptions = struct { - state: ?js.Object = null, - info: ?js.Object = null, + state: ?js.Value = null, + info: ?js.Value = null, history: ?[]const u8 = null, }; @@ -346,8 +346,8 @@ pub fn navigate(self: *Navigation, _url: [:0]const u8, _opts: ?NavigateOptions, } pub const ReloadOptions = struct { - state: ?js.Object = null, - info: ?js.Object = null, + state: ?js.Value = null, + info: ?js.Value = null, }; pub fn reload(self: *Navigation, _opts: ?ReloadOptions, page: *Page) !NavigationReturn { @@ -371,7 +371,7 @@ pub fn reload(self: *Navigation, _opts: ?ReloadOptions, page: *Page) !Navigation } pub const TraverseToOptions = struct { - info: ?js.Object = null, + info: ?js.Value = null, }; pub fn traverseTo(self: *Navigation, key: []const u8, _opts: ?TraverseToOptions, page: *Page) !NavigationReturn { @@ -389,7 +389,7 @@ pub fn traverseTo(self: *Navigation, key: []const u8, _opts: ?TraverseToOptions, } pub const UpdateCurrentEntryOptions = struct { - state: js.Object, + state: js.Value, }; pub fn updateCurrentEntry(self: *Navigation, options: UpdateCurrentEntryOptions, page: *Page) !void {