address review feedback: move stubs test, inline bridge functions, catch unreachable

This commit is contained in:
egrs
2026-02-18 15:40:59 +01:00
parent 07a87dfba7
commit c28afbf193
3 changed files with 16 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<script src="testing.js"></script> <script src="../testing.js"></script>
<script id="alert"> <script id="alert">
{ {

View File

@@ -704,14 +704,6 @@ fn getFunctionFromSetter(setter_: ?FunctionSetter) ?js.Function.Global {
}; };
} }
// Headless browser stubs: alert/confirm/prompt are no-ops
fn jsAlert(_: *Window, _: ?[]const u8) void {}
fn jsConfirm(_: *Window, _: ?[]const u8) bool {
return false;
}
fn jsPrompt(_: *Window, _: ?[]const u8, _: ?[]const u8) ?[]const u8 {
return null;
}
pub const JsApi = struct { pub const JsApi = struct {
pub const bridge = js.Bridge(Window); pub const bridge = js.Bridge(Window);
@@ -790,13 +782,23 @@ pub const JsApi = struct {
// pretty complicated to properly support I think. // pretty complicated to properly support I think.
pub const opener = bridge.property(null, .{ .template = false }); pub const opener = bridge.property(null, .{ .template = false });
pub const alert = bridge.function(Window.jsAlert, .{}); pub const alert = bridge.function(struct {
pub const confirm = bridge.function(Window.jsConfirm, .{}); fn alert(_: *const Window, _: ?[]const u8) void {}
pub const prompt = bridge.function(Window.jsPrompt, .{}); }.alert, .{});
pub const confirm = bridge.function(struct {
fn confirm(_: *const Window, _: ?[]const u8) bool {
return false;
}
}.confirm, .{});
pub const prompt = bridge.function(struct {
fn prompt(_: *const Window, _: ?[]const u8, _: ?[]const u8) ?[]const u8 {
return null;
}
}.prompt, .{});
}; };
const testing = @import("../../testing.zig"); const testing = @import("../../testing.zig");
test "WebApi: Window" { test "WebApi: Window" {
try testing.htmlRunner("window", .{}); try testing.htmlRunner("window", .{});
try testing.htmlRunner("window-stubs.html", .{}); try testing.htmlRunner("window/stubs.html", .{});
} }

View File

@@ -369,7 +369,7 @@ pub fn getTabIndex(self: *HtmlElement) i32 {
pub fn setTabIndex(self: *HtmlElement, value: i32, page: *Page) !void { pub fn setTabIndex(self: *HtmlElement, value: i32, page: *Page) !void {
var buf: [12]u8 = undefined; var buf: [12]u8 = undefined;
const str = std.fmt.bufPrint(&buf, "{d}", .{value}) catch return; const str = std.fmt.bufPrint(&buf, "{d}", .{value}) catch unreachable;
try self.asElement().setAttributeSafe(comptime .wrap("tabindex"), .wrap(str), page); try self.asElement().setAttributeSafe(comptime .wrap("tabindex"), .wrap(str), page);
} }