mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
address review feedback: move stubs test, inline bridge functions, catch unreachable
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<script src="testing.js"></script>
|
<script src="../testing.js"></script>
|
||||||
|
|
||||||
<script id="alert">
|
<script id="alert">
|
||||||
{
|
{
|
||||||
@@ -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", .{});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user