From 43678f8dc00d298c95ebaf6361a22367837fd2ac Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 10 Jan 2025 16:43:13 +0100 Subject: [PATCH] upgrade zig-js-runtime --- src/html/history.zig | 104 ++++++++++++++++++++++++++++++++++++++++++ vendor/zig-js-runtime | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/html/history.zig diff --git a/src/html/history.zig b/src/html/history.zig new file mode 100644 index 00000000..b507c3ab --- /dev/null +++ b/src/html/history.zig @@ -0,0 +1,104 @@ +// Copyright (C) 2023-2024 Lightpanda (Selecy SAS) +// +// Francis Bouvier +// Pierre Tachoire +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +const std = @import("std"); + +const builtin = @import("builtin"); +const jsruntime = @import("jsruntime"); + +const Case = jsruntime.test_utils.Case; +const checkCases = jsruntime.test_utils.checkCases; + +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-history-interface +pub const History = struct { + pub const mem_guarantied = true; + + const ScrollRestaurationMode = enum { + auto, + manual, + }; + + scrollRestauration: ScrollRestaurationMode = .audio, + + pub fn get_length(_: *History) u64 { + return 0; + } + + pub fn get_appCodeName(_: *Navigator) []const u8 { + return "Mozilla"; + } + pub fn get_appName(_: *Navigator) []const u8 { + return "Netscape"; + } + pub fn get_appVersion(self: *Navigator) []const u8 { + return self.version; + } + pub fn get_platform(self: *Navigator) []const u8 { + return self.platform; + } + pub fn get_product(_: *Navigator) []const u8 { + return "Gecko"; + } + pub fn get_productSub(_: *Navigator) []const u8 { + return "20030107"; + } + pub fn get_vendor(self: *Navigator) []const u8 { + return self.vendor; + } + pub fn get_vendorSub(_: *Navigator) []const u8 { + return ""; + } + pub fn get_language(self: *Navigator) []const u8 { + return self.language; + } + // TODO wait for arrays. + //pub fn get_languages(self: *Navigator) [][]const u8 { + // return .{self.language}; + //} + pub fn get_online(_: *Navigator) bool { + return true; + } + pub fn _registerProtocolHandler(_: *Navigator, scheme: []const u8, url: []const u8) void { + _ = scheme; + _ = url; + } + pub fn _unregisterProtocolHandler(_: *Navigator, scheme: []const u8, url: []const u8) void { + _ = scheme; + _ = url; + } + + pub fn get_cookieEnabled(_: *Navigator) bool { + return true; + } +}; + +// Tests +// ----- + +pub fn testExecFn( + _: std.mem.Allocator, + js_env: *jsruntime.Env, +) anyerror!void { + var navigator = [_]Case{ + .{ .src = "navigator.userAgent", .ex = "Lightpanda/1.0" }, + .{ .src = "navigator.appVersion", .ex = "1.0" }, + .{ .src = "navigator.language", .ex = "en-US" }, + }; + try checkCases(js_env, &navigator); +} + diff --git a/vendor/zig-js-runtime b/vendor/zig-js-runtime index 3be71ed6..1b1b3431 160000 --- a/vendor/zig-js-runtime +++ b/vendor/zig-js-runtime @@ -1 +1 @@ -Subproject commit 3be71ed62b8d1790a69958a143ec5f7fc5989068 +Subproject commit 1b1b3431ff8ca06c2344654fe2ca5e71d3be8845