mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-28 23:50:05 +00:00
Compare commits
1 Commits
finalizers
...
url-userin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c04ccf5e87 |
@@ -18,7 +18,6 @@
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const log = @import("log.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
@@ -63,7 +62,7 @@ pub fn deinit(self: *ArenaPool) void {
|
||||
var it = self._leak_track.iterator();
|
||||
while (it.next()) |kv| {
|
||||
if (kv.value_ptr.* != 0) {
|
||||
log.err(.bug, "ArenaPool leak", .{ .name = kv.key_ptr.*, .count = kv.value_ptr.* });
|
||||
std.debug.print("ArenaPool leak detected: '{s}' count={d}\n", .{ kv.key_ptr.*, kv.value_ptr.* });
|
||||
has_leaks = true;
|
||||
}
|
||||
}
|
||||
@@ -130,11 +129,11 @@ pub fn release(self: *ArenaPool, allocator: Allocator) void {
|
||||
if (self._leak_track.getPtr(entry.debug)) |count| {
|
||||
count.* -= 1;
|
||||
if (count.* < 0) {
|
||||
log.err(.bug, "ArenaPool double-free", .{ .name = entry.debug });
|
||||
std.debug.print("ArenaPool double-free detected: '{s}'\n", .{entry.debug});
|
||||
@panic("ArenaPool: double-free detected");
|
||||
}
|
||||
} else {
|
||||
log.err(.bug, "ArenaPool release unknown", .{ .name = entry.debug });
|
||||
std.debug.print("ArenaPool release of untracked arena: '{s}'\n", .{entry.debug});
|
||||
@panic("ArenaPool: release of untracked arena");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ const net = std.net;
|
||||
const posix = std.posix;
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
|
||||
const log = @import("log.zig");
|
||||
const App = @import("App.zig");
|
||||
|
||||
@@ -19,13 +19,17 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
|
||||
const js = @import("js/js.zig");
|
||||
const log = @import("../log.zig");
|
||||
const App = @import("../App.zig");
|
||||
const HttpClient = @import("HttpClient.zig");
|
||||
|
||||
const ArenaPool = App.ArenaPool;
|
||||
|
||||
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
const Session = @import("Session.zig");
|
||||
const Notification = @import("../Notification.zig");
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ pub fn dispatch(self: *EventManager, target: *EventTarget, event: *Event) Dispat
|
||||
|
||||
pub fn dispatchOpts(self: *EventManager, target: *EventTarget, event: *Event, comptime opts: DispatchOpts) DispatchError!void {
|
||||
event.acquireRef();
|
||||
defer _ = event.releaseRef(self.page._session);
|
||||
defer event.deinit(false, self.page._session);
|
||||
|
||||
if (comptime IS_DEBUG) {
|
||||
log.debug(.event, "eventManager.dispatch", .{ .type = event._type_string.str(), .bubbles = event._bubbles });
|
||||
@@ -240,7 +240,7 @@ pub fn dispatchDirect(self: *EventManager, target: *EventTarget, event: *Event,
|
||||
defer window._current_event = prev_event;
|
||||
|
||||
event.acquireRef();
|
||||
defer _ = event.releaseRef(page._session);
|
||||
defer event.deinit(false, page._session);
|
||||
|
||||
if (comptime IS_DEBUG) {
|
||||
log.debug(.event, "dispatchDirect", .{ .type = event._type_string, .context = opts.context });
|
||||
@@ -425,7 +425,7 @@ fn dispatchNode(self: *EventManager, target: *Node, event: *Event, comptime opts
|
||||
ls.deinit();
|
||||
}
|
||||
|
||||
const activation_state = try ActivationState.create(event, target, page);
|
||||
const activation_state = ActivationState.create(event, target, page);
|
||||
|
||||
// Defer runs even on early return - ensures event phase is reset
|
||||
// and default actions execute (unless prevented)
|
||||
@@ -820,7 +820,7 @@ const ActivationState = struct {
|
||||
|
||||
const Input = Element.Html.Input;
|
||||
|
||||
fn create(event: *const Event, target: *Node, page: *Page) !?ActivationState {
|
||||
fn create(event: *const Event, target: *Node, page: *Page) ?ActivationState {
|
||||
if (event._type_string.eql(comptime .wrap("click")) == false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ fn eventInit(arena: Allocator, typ: String, value: anytype) !Event {
|
||||
const time_stamp = (raw_timestamp / 2) * 2;
|
||||
|
||||
return .{
|
||||
._rc = .{},
|
||||
._rc = 0,
|
||||
._arena = arena,
|
||||
._type = unionInit(Event.Type, value),
|
||||
._type_string = typ,
|
||||
@@ -255,7 +255,6 @@ pub fn blob(_: *const Factory, arena: Allocator, child: anytype) !*@TypeOf(child
|
||||
|
||||
const blob_ptr = chain.get(0);
|
||||
blob_ptr.* = .{
|
||||
._rc = .{},
|
||||
._arena = arena,
|
||||
._type = unionInit(Blob.Type, chain.get(1)),
|
||||
._slice = "",
|
||||
@@ -272,7 +271,7 @@ pub fn abstractRange(_: *const Factory, arena: Allocator, child: anytype, page:
|
||||
const doc = page.document.asNode();
|
||||
const abstract_range = chain.get(0);
|
||||
abstract_range.* = AbstractRange{
|
||||
._rc = .{},
|
||||
._rc = 0,
|
||||
._arena = arena,
|
||||
._page_id = page.id,
|
||||
._type = unionInit(AbstractRange.Type, chain.get(1)),
|
||||
|
||||
@@ -24,10 +24,13 @@ const lp = @import("lightpanda");
|
||||
const log = @import("../log.zig");
|
||||
const Net = @import("../network/http.zig");
|
||||
const Network = @import("../network/Runtime.zig");
|
||||
const Config = @import("../Config.zig");
|
||||
const URL = @import("../browser/URL.zig");
|
||||
const Notification = @import("../Notification.zig");
|
||||
const CookieJar = @import("../browser/webapi/storage/Cookie.zig").Jar;
|
||||
const Robots = @import("../network/Robots.zig");
|
||||
const RobotStore = Robots.RobotStore;
|
||||
const WebBotAuth = @import("../network/WebBotAuth.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
|
||||
@@ -27,6 +27,7 @@ const IS_DEBUG = builtin.mode == .Debug;
|
||||
|
||||
const log = @import("../log.zig");
|
||||
|
||||
const App = @import("../App.zig");
|
||||
const String = @import("../string.zig").String;
|
||||
|
||||
const Mime = @import("Mime.zig");
|
||||
@@ -42,6 +43,7 @@ const URL = @import("URL.zig");
|
||||
const Blob = @import("webapi/Blob.zig");
|
||||
const Node = @import("webapi/Node.zig");
|
||||
const Event = @import("webapi/Event.zig");
|
||||
const EventTarget = @import("webapi/EventTarget.zig");
|
||||
const CData = @import("webapi/CData.zig");
|
||||
const Element = @import("webapi/Element.zig");
|
||||
const HtmlElement = @import("webapi/element/Html.zig");
|
||||
@@ -57,6 +59,7 @@ const AbstractRange = @import("webapi/AbstractRange.zig");
|
||||
const MutationObserver = @import("webapi/MutationObserver.zig");
|
||||
const IntersectionObserver = @import("webapi/IntersectionObserver.zig");
|
||||
const CustomElementDefinition = @import("webapi/CustomElementDefinition.zig");
|
||||
const storage = @import("webapi/storage/storage.zig");
|
||||
const PageTransitionEvent = @import("webapi/event/PageTransitionEvent.zig");
|
||||
const SubmitEvent = @import("webapi/event/SubmitEvent.zig");
|
||||
const NavigationKind = @import("webapi/navigation/root.zig").NavigationKind;
|
||||
@@ -64,6 +67,7 @@ const KeyboardEvent = @import("webapi/event/KeyboardEvent.zig");
|
||||
const MouseEvent = @import("webapi/event/MouseEvent.zig");
|
||||
|
||||
const HttpClient = @import("HttpClient.zig");
|
||||
const ArenaPool = App.ArenaPool;
|
||||
|
||||
const timestamp = @import("../datetime.zig").timestamp;
|
||||
const milliTimestamp = @import("../datetime.zig").milliTimestamp;
|
||||
@@ -3395,7 +3399,7 @@ pub fn handleClick(self: *Page, target: *Node) !void {
|
||||
pub fn triggerKeyboard(self: *Page, keyboard_event: *KeyboardEvent) !void {
|
||||
const event = keyboard_event.asEvent();
|
||||
const element = self.window._document._active_element orelse {
|
||||
_ = event.releaseRef(self._session);
|
||||
keyboard_event.deinit(false, self._session);
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -3491,7 +3495,7 @@ pub fn submitForm(self: *Page, submitter_: ?*Element, form_: ?*Element.Html.Form
|
||||
|
||||
// so submit_event is still valid when we check _prevent_default
|
||||
submit_event.acquireRef();
|
||||
defer _ = submit_event.releaseRef(self._session);
|
||||
defer submit_event.deinit(false, self._session);
|
||||
|
||||
try self._event_manager.dispatch(form_element.asEventTarget(), submit_event);
|
||||
// If the submit event was prevented, don't submit the form
|
||||
|
||||
@@ -21,9 +21,12 @@ const lp = @import("lightpanda");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const log = @import("../log.zig");
|
||||
const App = @import("../App.zig");
|
||||
|
||||
const Page = @import("Page.zig");
|
||||
const Session = @import("Session.zig");
|
||||
const Browser = @import("Browser.zig");
|
||||
const Factory = @import("Factory.zig");
|
||||
const HttpClient = @import("HttpClient.zig");
|
||||
|
||||
const IS_DEBUG = builtin.mode == .Debug;
|
||||
|
||||
@@ -28,10 +28,12 @@ const String = @import("../string.zig").String;
|
||||
const js = @import("js/js.zig");
|
||||
const URL = @import("URL.zig");
|
||||
const Page = @import("Page.zig");
|
||||
const Browser = @import("Browser.zig");
|
||||
|
||||
const Element = @import("webapi/Element.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArrayList = std.ArrayList;
|
||||
|
||||
const IS_DEBUG = builtin.mode == .Debug;
|
||||
|
||||
|
||||
@@ -71,18 +71,6 @@ origins: std.StringHashMapUnmanaged(*js.Origin) = .empty,
|
||||
// ensuring object identity works across same-origin frames.
|
||||
identity: js.Identity = .{},
|
||||
|
||||
// Shared finalizer callbacks across all Identities. Keyed by Zig instance ptr.
|
||||
// This ensures objects are only freed when ALL v8 wrappers are gone.
|
||||
finalizer_callbacks: std.AutoHashMapUnmanaged(usize, *FinalizerCallback) = .empty,
|
||||
|
||||
// Tracked global v8 objects that need to be released on cleanup.
|
||||
// Lives at Session level so objects can outlive individual Identities.
|
||||
globals: std.ArrayList(v8.Global) = .empty,
|
||||
|
||||
// Temporary v8 globals that can be released early. Key is global.data_ptr.
|
||||
// Lives at Session level so objects holding Temps can outlive individual Identities.
|
||||
temps: std.AutoHashMapUnmanaged(usize, v8.Global) = .empty,
|
||||
|
||||
// Shared resources for all pages in this session.
|
||||
// These live for the duration of the page tree (root + frames).
|
||||
arena_pool: *ArenaPool,
|
||||
@@ -236,30 +224,6 @@ pub fn releaseOrigin(self: *Session, origin: *js.Origin) void {
|
||||
/// Reset page_arena and factory for a clean slate.
|
||||
/// Called when root page is removed.
|
||||
fn resetPageResources(self: *Session) void {
|
||||
// Force cleanup all remaining finalized objects
|
||||
{
|
||||
var it = self.finalizer_callbacks.valueIterator();
|
||||
while (it.next()) |fc| {
|
||||
fc.*.deinit(self);
|
||||
}
|
||||
self.finalizer_callbacks = .empty;
|
||||
}
|
||||
|
||||
{
|
||||
for (self.globals.items) |*global| {
|
||||
v8.v8__Global__Reset(global);
|
||||
}
|
||||
self.globals = .empty;
|
||||
}
|
||||
|
||||
{
|
||||
var it = self.temps.valueIterator();
|
||||
while (it.next()) |global| {
|
||||
v8.v8__Global__Reset(global);
|
||||
}
|
||||
self.temps = .empty;
|
||||
}
|
||||
|
||||
self.identity.deinit();
|
||||
self.identity = .{};
|
||||
|
||||
@@ -493,25 +457,35 @@ pub fn nextPageId(self: *Session) u32 {
|
||||
return id;
|
||||
}
|
||||
|
||||
// Every finalizable instance of Zig gets 1 FinalizerCallback registered in the
|
||||
// session. This is to ensure that, if v8 doesn't finalize the value, we can
|
||||
// release on page reset.
|
||||
// A type that has a finalizer can have its finalizer called one of two ways.
|
||||
// The first is from V8 via the WeakCallback we give to weakRef. But that isn't
|
||||
// guaranteed to fire, so we track this in finalizer_callbacks and call them on
|
||||
// page reset.
|
||||
pub const FinalizerCallback = struct {
|
||||
arena: Allocator,
|
||||
session: *Session,
|
||||
resolved_ptr_id: usize,
|
||||
finalizer_ptr_id: usize,
|
||||
_deinit: *const fn (ptr_id: usize, session: *Session) void,
|
||||
ptr: *anyopaque,
|
||||
global: v8.Global,
|
||||
identity: *js.Identity,
|
||||
zig_finalizer: *const fn (ptr: *anyopaque, session: *Session) void,
|
||||
|
||||
// For every FinalizerCallback we'll have 1+ FinalizerCallback.Identity: one
|
||||
// for every identity that gets the instance. In most cases, that'l be 1.
|
||||
pub const Identity = struct {
|
||||
identity: *js.Identity,
|
||||
fc: *Session.FinalizerCallback,
|
||||
};
|
||||
pub fn deinit(self: *FinalizerCallback) void {
|
||||
self.zig_finalizer(self.ptr, self.session);
|
||||
self.session.releaseArena(self.arena);
|
||||
}
|
||||
|
||||
/// Release this item from the identity tracking maps (called after finalizer runs from V8)
|
||||
pub fn releaseIdentity(self: *FinalizerCallback) void {
|
||||
const session = self.session;
|
||||
const id = @intFromPtr(self.ptr);
|
||||
|
||||
if (self.identity.identity_map.fetchRemove(id)) |kv| {
|
||||
var global = kv.value;
|
||||
v8.v8__Global__Reset(&global);
|
||||
}
|
||||
|
||||
_ = self.identity.finalizer_callbacks.remove(id);
|
||||
|
||||
fn deinit(self: *FinalizerCallback, session: *Session) void {
|
||||
self._deinit(self.finalizer_ptr_id, session);
|
||||
session.releaseArena(self.arena);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -357,38 +357,25 @@ pub fn isHTTPS(raw: [:0]const u8) bool {
|
||||
|
||||
pub fn getHostname(raw: [:0]const u8) []const u8 {
|
||||
const host = getHost(raw);
|
||||
const port_sep = findPortSeparator(host) orelse return host;
|
||||
return host[0..port_sep];
|
||||
const pos = std.mem.lastIndexOfScalar(u8, host, ':') orelse return host;
|
||||
return host[0..pos];
|
||||
}
|
||||
|
||||
pub fn getPort(raw: [:0]const u8) []const u8 {
|
||||
const host = getHost(raw);
|
||||
const port_sep = findPortSeparator(host) orelse return "";
|
||||
return host[port_sep + 1 ..];
|
||||
}
|
||||
const pos = std.mem.lastIndexOfScalar(u8, host, ':') orelse return "";
|
||||
|
||||
// Finds the colon separating host from port, handling IPv6 bracket notation.
|
||||
// For IPv6 like "[::1]:8080", returns position of ":" after "]".
|
||||
// For IPv6 like "[::1]" (no port), returns null.
|
||||
// For regular hosts, returns position of last ":" if followed by digits.
|
||||
fn findPortSeparator(host: []const u8) ?usize {
|
||||
if (host.len > 0 and host[0] == '[') {
|
||||
// IPv6: find closing bracket, port separator must be after it
|
||||
const bracket_end = std.mem.indexOfScalar(u8, host, ']') orelse return null;
|
||||
if (bracket_end + 1 < host.len and host[bracket_end + 1] == ':') {
|
||||
return bracket_end + 1;
|
||||
}
|
||||
return null;
|
||||
if (pos + 1 >= host.len) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// Regular host: find last colon and verify it's followed by digits
|
||||
const pos = std.mem.lastIndexOfScalar(u8, host, ':') orelse return null;
|
||||
if (pos + 1 >= host.len) return null;
|
||||
|
||||
for (host[pos + 1 ..]) |c| {
|
||||
if (c < '0' or c > '9') return null;
|
||||
if (c < '0' or c > '9') {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
|
||||
return host[pos + 1 ..];
|
||||
}
|
||||
|
||||
pub fn getSearch(raw: [:0]const u8) []const u8 {
|
||||
@@ -416,12 +403,23 @@ pub fn getOrigin(allocator: Allocator, raw: [:0]const u8) !?[]const u8 {
|
||||
return null;
|
||||
}
|
||||
|
||||
const auth = parseAuthority(raw) orelse return null;
|
||||
const has_user_info = auth.has_user_info;
|
||||
const authority_end = auth.host_end;
|
||||
var authority_start = scheme_end + 3;
|
||||
|
||||
// Find end of authority (start of path/query/fragment or end of string)
|
||||
const authority_end_relative = std.mem.indexOfAny(u8, raw[authority_start..], "/?#");
|
||||
const authority_end = if (authority_end_relative) |end|
|
||||
authority_start + end
|
||||
else
|
||||
raw.len;
|
||||
|
||||
// We mustn't search the `@` after the first path separator.
|
||||
const has_user_info = if (std.mem.indexOf(u8, raw[authority_start..authority_end], "@")) |pos| blk: {
|
||||
authority_start += pos + 1;
|
||||
break :blk true;
|
||||
} else false;
|
||||
|
||||
// Check for port in the host:port section
|
||||
const host_part = auth.getHost(raw);
|
||||
const host_part = raw[authority_start..authority_end];
|
||||
if (std.mem.lastIndexOfScalar(u8, host_part, ':')) |colon_pos_in_host| {
|
||||
const port = host_part[colon_pos_in_host + 1 ..];
|
||||
|
||||
@@ -462,18 +460,45 @@ pub fn getOrigin(allocator: Allocator, raw: [:0]const u8) !?[]const u8 {
|
||||
}
|
||||
|
||||
fn getUserInfo(raw: [:0]const u8) ?[]const u8 {
|
||||
const auth = parseAuthority(raw) orelse return null;
|
||||
if (!auth.has_user_info) return null;
|
||||
|
||||
// User info is from authority_start to host_start - 1 (excluding the @)
|
||||
const scheme_end = std.mem.indexOf(u8, raw, "://").?;
|
||||
const scheme_end = std.mem.indexOf(u8, raw, "://") orelse return null;
|
||||
const authority_start = scheme_end + 3;
|
||||
return raw[authority_start .. auth.host_start - 1];
|
||||
|
||||
// We mustn't search the `@` after the first path separator.
|
||||
const path_start = blk: {
|
||||
if (std.mem.indexOfAny(u8, raw[authority_start..], "/?#")) |idx| {
|
||||
break :blk authority_start + idx;
|
||||
}
|
||||
break :blk raw.len;
|
||||
};
|
||||
|
||||
const pos = std.mem.indexOfScalar(u8, raw[authority_start..path_start], '@') orelse return null;
|
||||
|
||||
const full_pos = authority_start + pos;
|
||||
if (full_pos < path_start) {
|
||||
return raw[authority_start..full_pos];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn getHost(raw: [:0]const u8) []const u8 {
|
||||
const auth = parseAuthority(raw) orelse return "";
|
||||
return auth.getHost(raw);
|
||||
const scheme_end = std.mem.indexOf(u8, raw, "://") orelse return "";
|
||||
|
||||
var authority_start = scheme_end + 3;
|
||||
|
||||
// We mustn't search the `@` after the first path separator.
|
||||
const path_start = blk: {
|
||||
if (std.mem.indexOfAny(u8, raw[authority_start..], "/?#")) |idx| {
|
||||
break :blk authority_start + idx;
|
||||
}
|
||||
break :blk raw.len;
|
||||
};
|
||||
|
||||
if (std.mem.indexOf(u8, raw[authority_start..path_start], "@")) |pos| {
|
||||
authority_start += pos + 1;
|
||||
}
|
||||
|
||||
return raw[authority_start..path_start];
|
||||
}
|
||||
|
||||
// Returns true if these two URLs point to the same document.
|
||||
@@ -752,47 +777,6 @@ pub fn unescape(arena: Allocator, input: []const u8) ![]const u8 {
|
||||
return result.items;
|
||||
}
|
||||
|
||||
const AuthorityInfo = struct {
|
||||
host_start: usize,
|
||||
host_end: usize,
|
||||
has_user_info: bool,
|
||||
|
||||
fn getHost(self: AuthorityInfo, raw: []const u8) []const u8 {
|
||||
return raw[self.host_start..self.host_end];
|
||||
}
|
||||
};
|
||||
|
||||
// Parses the authority component of a URL, correctly handling userinfo.
|
||||
// Returns null if the URL doesn't have a valid scheme (no "://").
|
||||
// SECURITY: Only looks for @ within the authority portion (before /?#)
|
||||
// to prevent path-based @ injection attacks.
|
||||
fn parseAuthority(raw: []const u8) ?AuthorityInfo {
|
||||
const scheme_end = std.mem.indexOf(u8, raw, "://") orelse return null;
|
||||
const authority_start = scheme_end + 3;
|
||||
|
||||
// Find end of authority FIRST (start of path/query/fragment or end of string)
|
||||
const authority_end = if (std.mem.indexOfAny(u8, raw[authority_start..], "/?#")) |end|
|
||||
authority_start + end
|
||||
else
|
||||
raw.len;
|
||||
|
||||
// Only look for @ within the authority portion, not in path/query/fragment
|
||||
const authority_portion = raw[authority_start..authority_end];
|
||||
if (std.mem.indexOf(u8, authority_portion, "@")) |pos| {
|
||||
return .{
|
||||
.host_start = authority_start + pos + 1,
|
||||
.host_end = authority_end,
|
||||
.has_user_info = true,
|
||||
};
|
||||
}
|
||||
|
||||
return .{
|
||||
.host_start = authority_start,
|
||||
.host_end = authority_end,
|
||||
.has_user_info = false,
|
||||
};
|
||||
}
|
||||
|
||||
const testing = @import("../testing.zig");
|
||||
test "URL: isCompleteHTTPUrl" {
|
||||
try testing.expectEqual(true, isCompleteHTTPUrl("http://example.com/about"));
|
||||
@@ -1461,42 +1445,6 @@ test "URL: getHost" {
|
||||
try testing.expectEqualSlices(u8, "example.com", getHost("https://user:pass@example.com/page"));
|
||||
try testing.expectEqualSlices(u8, "example.com:8080", getHost("https://user:pass@example.com:8080/page"));
|
||||
try testing.expectEqualSlices(u8, "", getHost("not-a-url"));
|
||||
|
||||
// SECURITY: @ in path must NOT be treated as userinfo separator
|
||||
try testing.expectEqualSlices(u8, "evil.example.com", getHost("http://evil.example.com/@victim.example.com/"));
|
||||
try testing.expectEqualSlices(u8, "evil.example.com", getHost("https://evil.example.com/path/@victim.example.com"));
|
||||
|
||||
// IPv6 addresses
|
||||
try testing.expectEqualSlices(u8, "[::1]:8080", getHost("http://[::1]:8080/path"));
|
||||
try testing.expectEqualSlices(u8, "[::1]", getHost("http://[::1]/path"));
|
||||
try testing.expectEqualSlices(u8, "[2001:db8::1]", getHost("https://[2001:db8::1]/"));
|
||||
}
|
||||
|
||||
test "URL: getHostname" {
|
||||
// Regular hosts
|
||||
try testing.expectEqualSlices(u8, "example.com", getHostname("https://example.com:8080/path"));
|
||||
try testing.expectEqualSlices(u8, "example.com", getHostname("https://example.com/path"));
|
||||
|
||||
// IPv6 with port
|
||||
try testing.expectEqualSlices(u8, "[::1]", getHostname("http://[::1]:8080/path"));
|
||||
|
||||
// IPv6 without port - must return full bracket notation
|
||||
try testing.expectEqualSlices(u8, "[::1]", getHostname("http://[::1]/path"));
|
||||
try testing.expectEqualSlices(u8, "[2001:db8::1]", getHostname("https://[2001:db8::1]/"));
|
||||
}
|
||||
|
||||
test "URL: getPort" {
|
||||
// Regular hosts
|
||||
try testing.expectEqualSlices(u8, "8080", getPort("https://example.com:8080/path"));
|
||||
try testing.expectEqualSlices(u8, "", getPort("https://example.com/path"));
|
||||
|
||||
// IPv6 with port
|
||||
try testing.expectEqualSlices(u8, "8080", getPort("http://[::1]:8080/path"));
|
||||
try testing.expectEqualSlices(u8, "3000", getPort("http://[2001:db8::1]:3000/"));
|
||||
|
||||
// IPv6 without port - colons inside brackets must not be treated as port separator
|
||||
try testing.expectEqualSlices(u8, "", getPort("http://[::1]/path"));
|
||||
try testing.expectEqualSlices(u8, "", getPort("https://[2001:db8::1]/"));
|
||||
}
|
||||
|
||||
test "URL: setPathname percent-encodes" {
|
||||
@@ -1519,54 +1467,34 @@ test "URL: setPathname percent-encodes" {
|
||||
}
|
||||
|
||||
test "URL: getOrigin" {
|
||||
defer testing.reset();
|
||||
|
||||
const Case = struct {
|
||||
url: [:0]const u8,
|
||||
expected: ?[]const u8,
|
||||
};
|
||||
|
||||
const cases = [_]Case{
|
||||
// Basic HTTP/HTTPS origins
|
||||
.{ .url = "http://example.com/path", .expected = "http://example.com" },
|
||||
.{ .url = "https://example.com/path", .expected = "https://example.com" },
|
||||
.{ .url = "https://example.com:8080/path", .expected = "https://example.com:8080" },
|
||||
|
||||
// Default ports should be stripped
|
||||
.{ .url = "http://example.com:80/path", .expected = "http://example.com" },
|
||||
.{ .url = "https://example.com:443/path", .expected = "https://example.com" },
|
||||
|
||||
// User info should be stripped from origin
|
||||
.{ .url = "http://user:pass@example.com/path", .expected = "http://example.com" },
|
||||
.{ .url = "https://user@example.com:8080/path", .expected = "https://example.com:8080" },
|
||||
|
||||
// Non-HTTP schemes return null
|
||||
.{ .url = "ftp://example.com/path", .expected = null },
|
||||
.{ .url = "file:///path/to/file", .expected = null },
|
||||
.{ .url = "about:blank", .expected = null },
|
||||
|
||||
// Query and fragment should not affect origin
|
||||
.{ .url = "https://example.com?query=1", .expected = "https://example.com" },
|
||||
.{ .url = "https://example.com#fragment", .expected = "https://example.com" },
|
||||
.{ .url = "https://example.com/path?q=1#frag", .expected = "https://example.com" },
|
||||
|
||||
// SECURITY: @ in path must NOT be treated as userinfo separator
|
||||
// This would be a Same-Origin Policy bypass if mishandled
|
||||
.{ .url = "http://evil.example.com/@victim.example.com/", .expected = "http://evil.example.com" },
|
||||
.{ .url = "https://evil.example.com/path/@victim.example.com/steal", .expected = "https://evil.example.com" },
|
||||
.{ .url = "http://evil.example.com/@victim.example.com:443/", .expected = "http://evil.example.com" },
|
||||
|
||||
// @ in query/fragment must also not affect origin
|
||||
.{ .url = "https://example.com/path?user=foo@bar.com", .expected = "https://example.com" },
|
||||
.{ .url = "https://example.com/path#user@host", .expected = "https://example.com" },
|
||||
};
|
||||
|
||||
for (cases) |case| {
|
||||
const result = try getOrigin(testing.arena_allocator, case.url);
|
||||
if (case.expected) |expected| {
|
||||
try testing.expectString(expected, result.?);
|
||||
} else {
|
||||
try testing.expectEqual(null, result);
|
||||
}
|
||||
}
|
||||
var arena = std.heap.ArenaAllocator.init(testing.allocator);
|
||||
defer arena.deinit();
|
||||
const allocator = arena.allocator();
|
||||
try testing.expectEqualSlices(u8, "http://example.com:8080", try getOrigin(allocator, "http://example.com:8080/path") orelse unreachable);
|
||||
try testing.expectEqualSlices(u8, "https://example.com:8080", try getOrigin(allocator, "https://example.com:8080/path") orelse unreachable);
|
||||
try testing.expectEqualSlices(u8, "https://example.com", try getOrigin(allocator, "https://example.com/path") orelse unreachable);
|
||||
try testing.expectEqualSlices(u8, "https://example.com", try getOrigin(allocator, "https://example.com:443/") orelse unreachable);
|
||||
try testing.expectEqualSlices(u8, "https://example.com", try getOrigin(allocator, "https://user:pass@example.com/page") orelse unreachable);
|
||||
try testing.expectEqualSlices(u8, "https://example.com:8080", try getOrigin(allocator, "https://user:pass@example.com:8080/page") orelse unreachable);
|
||||
try testing.expectEqual(null, try getOrigin(allocator, "not-a-url"));
|
||||
}
|
||||
|
||||
test "URL: SOP bypass" {
|
||||
// SOP Bypass
|
||||
try testing.expectEqualSlices(u8, "attacker.com", getHost("http://attacker.com/@bank.com/"));
|
||||
try testing.expectEqualSlices(u8, "attacker.com", getHost("https://attacker.com/@bank.com/"));
|
||||
try testing.expectEqualSlices(u8, "attacker.com", getHost("http://attacker.com?@bank.com/"));
|
||||
try testing.expectEqualSlices(u8, "attacker.com", getHost("http://attacker.com#@bank.com/"));
|
||||
try testing.expectEqualSlices(u8, "attacker.com", getHostname("http://attacker.com/@bank.com/"));
|
||||
try testing.expectEqualSlices(u8, "attacker.com", getHostname("https://attacker.com/@bank.com/"));
|
||||
try testing.expectEqualSlices(u8, "attacker.com", getHostname("http://attacker.com?@bank.com/"));
|
||||
try testing.expectEqualSlices(u8, "attacker.com", getHostname("http://attacker.com#@bank.com/"));
|
||||
|
||||
var arena = std.heap.ArenaAllocator.init(testing.allocator);
|
||||
defer arena.deinit();
|
||||
const allocator = arena.allocator();
|
||||
try testing.expectEqualSlices(u8, "http://attacker.com", try getOrigin(allocator, "http://attacker.com/@bank.com/") orelse unreachable);
|
||||
try testing.expectEqualSlices(u8, "https://attacker.com", try getOrigin(allocator, "https://attacker.com/@bank.com/") orelse unreachable);
|
||||
try testing.expectEqualSlices(u8, "http://attacker.com", try getOrigin(allocator, "http://attacker.com?bank.com/") orelse unreachable);
|
||||
try testing.expectEqualSlices(u8, "http://attacker.com", try getOrigin(allocator, "http://attacker.com#bank.com/") orelse unreachable);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ pub const InteractivityType = enum {
|
||||
};
|
||||
|
||||
pub const InteractiveElement = struct {
|
||||
backendNodeId: ?u32 = null,
|
||||
node: *Node,
|
||||
tag_name: []const u8,
|
||||
role: ?[]const u8,
|
||||
@@ -56,11 +55,6 @@ pub const InteractiveElement = struct {
|
||||
pub fn jsonStringify(self: *const InteractiveElement, jw: anytype) !void {
|
||||
try jw.beginObject();
|
||||
|
||||
if (self.backendNodeId) |id| {
|
||||
try jw.objectField("backendNodeId");
|
||||
try jw.write(id);
|
||||
}
|
||||
|
||||
try jw.objectField("tagName");
|
||||
try jw.write(self.tag_name);
|
||||
|
||||
@@ -129,15 +123,6 @@ pub const InteractiveElement = struct {
|
||||
}
|
||||
};
|
||||
|
||||
/// Populate backendNodeId on each interactive element by registering
|
||||
/// their nodes in the given registry. Works with both CDP and MCP registries.
|
||||
pub fn registerNodes(elements: []InteractiveElement, registry: anytype) !void {
|
||||
for (elements) |*el| {
|
||||
const registered = try registry.register(el.node);
|
||||
el.backendNodeId = registered.id;
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect all interactive elements under `root`.
|
||||
pub fn collectInteractiveElements(
|
||||
root: *Node,
|
||||
|
||||
@@ -128,7 +128,7 @@ fn _constructor(self: *Caller, func: anytype, info: FunctionCallbackInfo) !void
|
||||
const new_this_handle = info.getThis();
|
||||
var this = js.Object{ .local = local, .handle = new_this_handle };
|
||||
if (@typeInfo(ReturnType) == .error_union) {
|
||||
const non_error_res = try res;
|
||||
const non_error_res = res catch |err| return err;
|
||||
this = try local.mapZigInstanceToJs(new_this_handle, non_error_res);
|
||||
} else {
|
||||
this = try local.mapZigInstanceToJs(new_this_handle, res);
|
||||
|
||||
@@ -21,8 +21,8 @@ const lp = @import("lightpanda");
|
||||
const log = @import("../../log.zig");
|
||||
|
||||
const js = @import("js.zig");
|
||||
const bridge = @import("bridge.zig");
|
||||
const Env = @import("Env.zig");
|
||||
const bridge = @import("bridge.zig");
|
||||
const Origin = @import("Origin.zig");
|
||||
const Scheduler = @import("Scheduler.zig");
|
||||
|
||||
@@ -214,11 +214,48 @@ pub fn setOrigin(self: *Context, key: ?[]const u8) !void {
|
||||
}
|
||||
|
||||
pub fn trackGlobal(self: *Context, global: v8.Global) !void {
|
||||
return self.session.globals.append(self.session.page_arena, global);
|
||||
return self.identity.globals.append(self.identity_arena, global);
|
||||
}
|
||||
|
||||
pub fn trackTemp(self: *Context, global: v8.Global) !void {
|
||||
return self.session.temps.put(self.session.page_arena, global.data_ptr, global);
|
||||
return self.identity.temps.put(self.identity_arena, global.data_ptr, global);
|
||||
}
|
||||
|
||||
pub fn weakRef(self: *Context, obj: anytype) void {
|
||||
const resolved = js.Local.resolveValue(obj);
|
||||
const fc = self.identity.finalizer_callbacks.get(@intFromPtr(resolved.ptr)) orelse {
|
||||
if (comptime IS_DEBUG) {
|
||||
// should not be possible
|
||||
std.debug.assert(false);
|
||||
}
|
||||
return;
|
||||
};
|
||||
v8.v8__Global__SetWeakFinalizer(&fc.global, fc, resolved.finalizer_from_v8, v8.kParameter);
|
||||
}
|
||||
|
||||
pub fn safeWeakRef(self: *Context, obj: anytype) void {
|
||||
const resolved = js.Local.resolveValue(obj);
|
||||
const fc = self.identity.finalizer_callbacks.get(@intFromPtr(resolved.ptr)) orelse {
|
||||
if (comptime IS_DEBUG) {
|
||||
// should not be possible
|
||||
std.debug.assert(false);
|
||||
}
|
||||
return;
|
||||
};
|
||||
v8.v8__Global__ClearWeak(&fc.global);
|
||||
v8.v8__Global__SetWeakFinalizer(&fc.global, fc, resolved.finalizer_from_v8, v8.kParameter);
|
||||
}
|
||||
|
||||
pub fn strongRef(self: *Context, obj: anytype) void {
|
||||
const resolved = js.Local.resolveValue(obj);
|
||||
const fc = self.identity.finalizer_callbacks.get(@intFromPtr(resolved.ptr)) orelse {
|
||||
if (comptime IS_DEBUG) {
|
||||
// should not be possible
|
||||
std.debug.assert(false);
|
||||
}
|
||||
return;
|
||||
};
|
||||
v8.v8__Global__ClearWeak(&fc.global);
|
||||
}
|
||||
|
||||
pub const IdentityResult = struct {
|
||||
@@ -234,6 +271,35 @@ pub fn addIdentity(self: *Context, ptr: usize) !IdentityResult {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn releaseTemp(self: *Context, global: v8.Global) void {
|
||||
if (self.identity.temps.fetchRemove(global.data_ptr)) |kv| {
|
||||
var g = kv.value;
|
||||
v8.v8__Global__Reset(&g);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn createFinalizerCallback(
|
||||
self: *Context,
|
||||
global: v8.Global,
|
||||
ptr: *anyopaque,
|
||||
zig_finalizer: *const fn (ptr: *anyopaque, session: *Session) void,
|
||||
) !*Session.FinalizerCallback {
|
||||
const session = self.session;
|
||||
const arena = try session.getArena(.{ .debug = "FinalizerCallback" });
|
||||
errdefer session.releaseArena(arena);
|
||||
const fc = try arena.create(Session.FinalizerCallback);
|
||||
fc.* = .{
|
||||
.arena = arena,
|
||||
.session = session,
|
||||
.ptr = ptr,
|
||||
.global = global,
|
||||
.zig_finalizer = zig_finalizer,
|
||||
// Store identity pointer for cleanup when V8 GCs the object
|
||||
.identity = self.identity,
|
||||
};
|
||||
return fc;
|
||||
}
|
||||
|
||||
// Any operation on the context have to be made from a local.
|
||||
pub fn localScope(self: *Context, ls: *js.Local.Scope) void {
|
||||
const isolate = self.isolate;
|
||||
|
||||
@@ -26,6 +26,7 @@ const App = @import("../../App.zig");
|
||||
const log = @import("../../log.zig");
|
||||
|
||||
const bridge = @import("bridge.zig");
|
||||
const Origin = @import("Origin.zig");
|
||||
const Context = @import("Context.zig");
|
||||
const Isolate = @import("Isolate.zig");
|
||||
const Platform = @import("Platform.zig");
|
||||
@@ -33,6 +34,7 @@ const Snapshot = @import("Snapshot.zig");
|
||||
const Inspector = @import("Inspector.zig");
|
||||
|
||||
const Page = @import("../Page.zig");
|
||||
const Session = @import("../Session.zig");
|
||||
const Window = @import("../webapi/Window.zig");
|
||||
|
||||
const JsApis = bridge.JsApis;
|
||||
|
||||
@@ -21,6 +21,7 @@ const js = @import("js.zig");
|
||||
const v8 = js.v8;
|
||||
|
||||
const log = @import("../../log.zig");
|
||||
const Session = @import("../Session.zig");
|
||||
|
||||
const Function = @This();
|
||||
|
||||
@@ -213,7 +214,7 @@ fn _persist(self: *const Function, comptime is_global: bool) !(if (is_global) Gl
|
||||
return .{ .handle = global, .temps = {} };
|
||||
}
|
||||
try ctx.trackTemp(global);
|
||||
return .{ .handle = global, .temps = &ctx.session.temps };
|
||||
return .{ .handle = global, .temps = &ctx.identity.temps };
|
||||
}
|
||||
|
||||
pub fn tempWithThis(self: *const Function, value: anytype) !Temp {
|
||||
|
||||
@@ -32,15 +32,45 @@ const js = @import("js.zig");
|
||||
const Session = @import("../Session.zig");
|
||||
|
||||
const v8 = js.v8;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const Identity = @This();
|
||||
|
||||
// Maps Zig instance pointers to their v8::Global(Object) wrappers.
|
||||
identity_map: std.AutoHashMapUnmanaged(usize, v8.Global) = .empty,
|
||||
|
||||
// Tracked global v8 objects that need to be released on cleanup.
|
||||
globals: std.ArrayList(v8.Global) = .empty,
|
||||
|
||||
// Temporary v8 globals that can be released early. Key is global.data_ptr.
|
||||
temps: std.AutoHashMapUnmanaged(usize, v8.Global) = .empty,
|
||||
|
||||
// Finalizer callbacks for weak references. Key is @intFromPtr of the Zig instance.
|
||||
finalizer_callbacks: std.AutoHashMapUnmanaged(usize, *Session.FinalizerCallback) = .empty,
|
||||
|
||||
pub fn deinit(self: *Identity) void {
|
||||
var it = self.identity_map.valueIterator();
|
||||
while (it.next()) |global| {
|
||||
{
|
||||
var it = self.finalizer_callbacks.valueIterator();
|
||||
while (it.next()) |finalizer| {
|
||||
finalizer.*.deinit();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var it = self.identity_map.valueIterator();
|
||||
while (it.next()) |global| {
|
||||
v8.v8__Global__Reset(global);
|
||||
}
|
||||
}
|
||||
|
||||
for (self.globals.items) |*global| {
|
||||
v8.v8__Global__Reset(global);
|
||||
}
|
||||
|
||||
{
|
||||
var it = self.temps.valueIterator();
|
||||
while (it.next()) |global| {
|
||||
v8.v8__Global__Reset(global);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const Page = @import("../Page.zig");
|
||||
const Session = @import("../Session.zig");
|
||||
const log = @import("../../log.zig");
|
||||
const string = @import("../../string.zig");
|
||||
|
||||
const Session = @import("../Session.zig");
|
||||
|
||||
const js = @import("js.zig");
|
||||
const bridge = @import("bridge.zig");
|
||||
const Caller = @import("Caller.zig");
|
||||
@@ -33,6 +33,7 @@ const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
const v8 = js.v8;
|
||||
const CallOpts = Caller.CallOpts;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
// Where js.Context has a lifetime tied to the page, and holds the
|
||||
// v8::Global<v8::Context>, this has a much shorter lifetime and holds a
|
||||
@@ -214,8 +215,7 @@ pub fn mapZigInstanceToJs(self: *const Local, js_obj_handle: ?*const v8.Object,
|
||||
.pointer => |ptr| {
|
||||
const resolved = resolveValue(value);
|
||||
|
||||
const resolved_ptr_id = @intFromPtr(resolved.ptr);
|
||||
const gop = try ctx.addIdentity(resolved_ptr_id);
|
||||
const gop = try ctx.addIdentity(@intFromPtr(resolved.ptr));
|
||||
if (gop.found_existing) {
|
||||
// we've seen this instance before, return the same object
|
||||
return (js.Object.Global{ .handle = gop.value_ptr.* }).local(self);
|
||||
@@ -264,27 +264,31 @@ pub fn mapZigInstanceToJs(self: *const Local, js_obj_handle: ?*const v8.Object,
|
||||
// dont' use js_obj.persist(), because we don't want to track this in
|
||||
// context.global_objects, we want to track it in context.identity_map.
|
||||
v8.v8__Global__New(isolate.handle, js_obj.handle, gop.value_ptr);
|
||||
if (resolved.finalizer) |finalizer| {
|
||||
const finalizer_ptr_id = finalizer.ptr_id;
|
||||
finalizer.acquireRef(finalizer_ptr_id);
|
||||
|
||||
const session = ctx.session;
|
||||
const finalizer_gop = try session.finalizer_callbacks.getOrPut(session.page_arena, finalizer_ptr_id);
|
||||
if (finalizer_gop.found_existing == false) {
|
||||
// This is the first context (and very likely only one) to
|
||||
// see this Zig instance. We need to create the FinalizerCallback
|
||||
// so that we can cleanup on page reset if v8 doesn't finalize.
|
||||
errdefer _ = session.finalizer_callbacks.remove(finalizer_ptr_id);
|
||||
finalizer_gop.value_ptr.* = try self.createFinalizerCallback(resolved_ptr_id, finalizer_ptr_id, finalizer.deinit);
|
||||
if (@hasDecl(JsApi.Meta, "finalizer")) {
|
||||
// It would be great if resolved knew the resolved type, but I
|
||||
// can't figure out how to make that work, since it depends on
|
||||
// the [runtime] `value`.
|
||||
// We need the resolved finalizer, which we have in resolved.
|
||||
//
|
||||
// The above if statement would be more clear as:
|
||||
// if (resolved.finalizer_from_v8) |finalizer| {
|
||||
// But that's a runtime check.
|
||||
// Instead, we check if the base has finalizer. The assumption
|
||||
// here is that if a resolve type has a finalizer, then the base
|
||||
// should have a finalizer too.
|
||||
const fc = try ctx.createFinalizerCallback(gop.value_ptr.*, resolved.ptr, resolved.finalizer_from_zig.?);
|
||||
{
|
||||
errdefer fc.deinit();
|
||||
try ctx.identity.finalizer_callbacks.put(ctx.identity_arena, @intFromPtr(resolved.ptr), fc);
|
||||
}
|
||||
const fc = finalizer_gop.value_ptr.*;
|
||||
const identity_finalizer = try fc.arena.create(Session.FinalizerCallback.Identity);
|
||||
identity_finalizer.* = .{
|
||||
.fc = fc,
|
||||
.identity = ctx.identity,
|
||||
};
|
||||
|
||||
v8.v8__Global__SetWeakFinalizer(gop.value_ptr, identity_finalizer, finalizer.release, v8.kParameter);
|
||||
conditionallyReference(value);
|
||||
if (@hasDecl(JsApi.Meta, "weak")) {
|
||||
if (comptime IS_DEBUG) {
|
||||
std.debug.assert(JsApi.Meta.weak == true);
|
||||
}
|
||||
v8.v8__Global__SetWeakFinalizer(gop.value_ptr, fc, resolved.finalizer_from_v8, v8.kParameter);
|
||||
}
|
||||
}
|
||||
return js_obj;
|
||||
},
|
||||
@@ -1119,19 +1123,12 @@ fn jsUnsignedIntToZig(comptime T: type, max: comptime_int, maybe: u32) !T {
|
||||
// This function recursively walks the _type union field (if there is one) to
|
||||
// get the most specific class_id possible.
|
||||
const Resolved = struct {
|
||||
weak: bool,
|
||||
ptr: *anyopaque,
|
||||
class_id: u16,
|
||||
prototype_chain: []const @import("TaggedOpaque.zig").PrototypeChainEntry,
|
||||
finalizer: ?Finalizer,
|
||||
|
||||
const Finalizer = struct {
|
||||
// Resolved.ptr is the most specific value in a chain (e.g. IFrame, not EventTarget, Node, ...)
|
||||
// Finalizer.ptr_id is the most specific value in a chain that defines an acquireRef
|
||||
ptr_id: usize,
|
||||
deinit: *const fn (ptr_id: usize, session: *Session) void,
|
||||
acquireRef: *const fn (ptr_id: usize) void,
|
||||
release: *const fn (handle: ?*const v8.WeakCallbackInfo) callconv(.c) void,
|
||||
};
|
||||
finalizer_from_v8: ?*const fn (handle: ?*const v8.WeakCallbackInfo) callconv(.c) void = null,
|
||||
finalizer_from_zig: ?*const fn (ptr: *anyopaque, session: *Session) void = null,
|
||||
};
|
||||
pub fn resolveValue(value: anytype) Resolved {
|
||||
const T = bridge.Struct(@TypeOf(value));
|
||||
@@ -1158,85 +1155,27 @@ pub fn resolveValue(value: anytype) Resolved {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
fn resolveT(comptime T: type, value: *T) Resolved {
|
||||
fn resolveT(comptime T: type, value: *anyopaque) Resolved {
|
||||
const Meta = T.JsApi.Meta;
|
||||
return .{
|
||||
.ptr = value,
|
||||
.class_id = Meta.class_id,
|
||||
.prototype_chain = &Meta.prototype_chain,
|
||||
.finalizer = blk: {
|
||||
const FT = (comptime findFinalizerType(T)) orelse break :blk null;
|
||||
const getFinalizerPtr = comptime finalizerPtrGetter(T, FT);
|
||||
const finalizer_ptr = getFinalizerPtr(value);
|
||||
|
||||
const Wrap = struct {
|
||||
fn deinit(ptr_id: usize, session: *Session) void {
|
||||
FT.deinit(@ptrFromInt(ptr_id), session);
|
||||
}
|
||||
|
||||
fn acquireRef(ptr_id: usize) void {
|
||||
FT.acquireRef(@ptrFromInt(ptr_id));
|
||||
}
|
||||
|
||||
fn release(handle: ?*const v8.WeakCallbackInfo) callconv(.c) void {
|
||||
const ptr = v8.v8__WeakCallbackInfo__GetParameter(handle.?).?;
|
||||
const identity_finalizer: *Session.FinalizerCallback.Identity = @ptrCast(@alignCast(ptr));
|
||||
|
||||
const fc = identity_finalizer.fc;
|
||||
if (identity_finalizer.identity.identity_map.fetchRemove(fc.resolved_ptr_id)) |kv| {
|
||||
var global = kv.value;
|
||||
v8.v8__Global__Reset(&global);
|
||||
}
|
||||
|
||||
FT.releaseRef(@ptrFromInt(fc.finalizer_ptr_id), fc.session);
|
||||
}
|
||||
};
|
||||
break :blk .{
|
||||
.ptr_id = @intFromPtr(finalizer_ptr),
|
||||
.deinit = Wrap.deinit,
|
||||
.acquireRef = Wrap.acquireRef,
|
||||
.release = Wrap.release,
|
||||
};
|
||||
},
|
||||
.weak = if (@hasDecl(Meta, "weak")) Meta.weak else false,
|
||||
.finalizer_from_v8 = if (@hasDecl(Meta, "finalizer")) Meta.finalizer.from_v8 else null,
|
||||
.finalizer_from_zig = if (@hasDecl(Meta, "finalizer")) Meta.finalizer.from_zig else null,
|
||||
};
|
||||
}
|
||||
|
||||
// Start at the "resolved" type (the most specific) and work our way up the
|
||||
// prototype chain looking for the type that defines acquireRef
|
||||
fn findFinalizerType(comptime T: type) ?type {
|
||||
const S = bridge.Struct(T);
|
||||
if (@hasDecl(S, "acquireRef")) {
|
||||
return S;
|
||||
fn conditionallyReference(value: anytype) void {
|
||||
const T = bridge.Struct(@TypeOf(value));
|
||||
if (@hasDecl(T, "acquireRef")) {
|
||||
value.acquireRef();
|
||||
return;
|
||||
}
|
||||
if (@hasField(S, "_proto")) {
|
||||
const ProtoPtr = std.meta.fieldInfo(S, ._proto).type;
|
||||
const ProtoChild = @typeInfo(ProtoPtr).pointer.child;
|
||||
return findFinalizerType(ProtoChild);
|
||||
if (@hasField(T, "_proto")) {
|
||||
conditionallyReference(value._proto);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Generate a function that follows the _proto pointer chain to get to the finalizer type
|
||||
fn finalizerPtrGetter(comptime T: type, comptime FT: type) *const fn (*T) *FT {
|
||||
const S = bridge.Struct(T);
|
||||
if (S == FT) {
|
||||
return struct {
|
||||
fn get(v: *T) *FT {
|
||||
return v;
|
||||
}
|
||||
}.get;
|
||||
}
|
||||
if (@hasField(S, "_proto")) {
|
||||
const ProtoPtr = std.meta.fieldInfo(S, ._proto).type;
|
||||
const ProtoChild = @typeInfo(ProtoPtr).pointer.child;
|
||||
const childGetter = comptime finalizerPtrGetter(ProtoChild, FT);
|
||||
return struct {
|
||||
fn get(v: *T) *FT {
|
||||
return childGetter(v._proto);
|
||||
}
|
||||
}.get;
|
||||
}
|
||||
@compileError("Cannot find path from " ++ @typeName(T) ++ " to " ++ @typeName(FT));
|
||||
}
|
||||
|
||||
pub fn stackTrace(self: *const Local) !?[]const u8 {
|
||||
@@ -1444,34 +1383,6 @@ pub fn debugContextId(self: *const Local) i32 {
|
||||
return v8.v8__Context__DebugContextId(self.handle);
|
||||
}
|
||||
|
||||
fn createFinalizerCallback(
|
||||
self: *const Local,
|
||||
|
||||
// Key in identity map
|
||||
// The most specific value (KeyboardEvent, not Event)
|
||||
resolved_ptr_id: usize,
|
||||
|
||||
// The most specific value where finalizers are defined
|
||||
// What actually gets acquired / released / deinit
|
||||
finalizer_ptr_id: usize,
|
||||
deinit: *const fn (ptr_id: usize, session: *Session) void,
|
||||
) !*Session.FinalizerCallback {
|
||||
const session = self.ctx.session;
|
||||
|
||||
const arena = try session.getArena(.{ .debug = "FinalizerCallback" });
|
||||
errdefer session.releaseArena(arena);
|
||||
|
||||
const fc = try arena.create(Session.FinalizerCallback);
|
||||
fc.* = .{
|
||||
.arena = arena,
|
||||
.session = session,
|
||||
._deinit = deinit,
|
||||
.resolved_ptr_id = resolved_ptr_id,
|
||||
.finalizer_ptr_id = finalizer_ptr_id,
|
||||
};
|
||||
return fc;
|
||||
}
|
||||
|
||||
// Encapsulates a Local and a HandleScope. When we're going from V8->Zig
|
||||
// we easily get both a Local and a HandleScope via Caller.init.
|
||||
// But when we're going from Zig -> V8, things are more complicated.
|
||||
|
||||
@@ -20,6 +20,8 @@ const std = @import("std");
|
||||
const js = @import("js.zig");
|
||||
const v8 = js.v8;
|
||||
|
||||
const Session = @import("../Session.zig");
|
||||
|
||||
const Promise = @This();
|
||||
|
||||
local: *const js.Local,
|
||||
@@ -67,7 +69,7 @@ fn _persist(self: *const Promise, comptime is_global: bool) !(if (is_global) Glo
|
||||
return .{ .handle = global, .temps = {} };
|
||||
}
|
||||
try ctx.trackTemp(global);
|
||||
return .{ .handle = global, .temps = &ctx.session.temps };
|
||||
return .{ .handle = global, .temps = &ctx.identity.temps };
|
||||
}
|
||||
|
||||
pub const Temp = G(.temp);
|
||||
|
||||
@@ -25,6 +25,7 @@ const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
const v8 = js.v8;
|
||||
const JsApis = bridge.JsApis;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const Snapshot = @This();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ const v8 = js.v8;
|
||||
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Session = @import("../Session.zig");
|
||||
|
||||
const Value = @This();
|
||||
|
||||
@@ -303,7 +304,7 @@ fn _persist(self: *const Value, comptime is_global: bool) !(if (is_global) Globa
|
||||
return .{ .handle = global, .temps = {} };
|
||||
}
|
||||
try ctx.trackTemp(global);
|
||||
return .{ .handle = global, .temps = &ctx.session.temps };
|
||||
return .{ .handle = global, .temps = &ctx.identity.temps };
|
||||
}
|
||||
|
||||
pub fn toZig(self: Value, comptime T: type) !T {
|
||||
|
||||
@@ -18,12 +18,15 @@
|
||||
|
||||
const std = @import("std");
|
||||
const js = @import("js.zig");
|
||||
const lp = @import("lightpanda");
|
||||
const log = @import("../../log.zig");
|
||||
const Page = @import("../Page.zig");
|
||||
const Session = @import("../Session.zig");
|
||||
|
||||
const v8 = js.v8;
|
||||
|
||||
const Caller = @import("Caller.zig");
|
||||
const Context = @import("Context.zig");
|
||||
|
||||
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
@@ -101,19 +104,34 @@ pub fn Builder(comptime T: type) type {
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn releaseRef(comptime T: type, ptr_id: usize, session: *Session) void {
|
||||
if (@hasDecl(T, "releaseRef")) {
|
||||
T.releaseRef(@ptrFromInt(ptr_id), session);
|
||||
return;
|
||||
}
|
||||
if (@hasField(T, "_proto")) {
|
||||
releaseRef(Struct(std.meta.fieldInfo(T, ._proto).type), ptr_id, session);
|
||||
return;
|
||||
}
|
||||
@compileError(@typeName(T) ++ " marked with finalizer without an acquireRef in its prototype chain");
|
||||
pub fn finalizer(comptime func: *const fn (self: *T, shutdown: bool, session: *Session) void) Finalizer {
|
||||
return .{
|
||||
.from_zig = struct {
|
||||
fn wrap(ptr: *anyopaque, session: *Session) void {
|
||||
func(@ptrCast(@alignCast(ptr)), true, session);
|
||||
}
|
||||
}.wrap,
|
||||
|
||||
.from_v8 = struct {
|
||||
fn wrap(handle: ?*const v8.WeakCallbackInfo) callconv(.c) void {
|
||||
const ptr = v8.v8__WeakCallbackInfo__GetParameter(handle.?).?;
|
||||
const fc: *Session.FinalizerCallback = @ptrCast(@alignCast(ptr));
|
||||
|
||||
const value_ptr = fc.ptr;
|
||||
if (fc.identity.finalizer_callbacks.contains(@intFromPtr(value_ptr))) {
|
||||
func(@ptrCast(@alignCast(value_ptr)), false, fc.session);
|
||||
fc.releaseIdentity();
|
||||
} else {
|
||||
// A bit weird, but v8 _requires_ that we release it
|
||||
// If we don't. We'll 100% crash.
|
||||
v8.v8__Global__Reset(&fc.global);
|
||||
}
|
||||
}
|
||||
}.wrap,
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub const Constructor = struct {
|
||||
@@ -396,6 +414,17 @@ pub const Property = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const Finalizer = struct {
|
||||
// The finalizer wrapper when called from Zig. This is only called on
|
||||
// Origin.deinit
|
||||
from_zig: *const fn (ctx: *anyopaque, session: *Session) void,
|
||||
|
||||
// The finalizer wrapper when called from V8. This may never be called
|
||||
// (hence why we fallback to calling in Origin.deinit). If it is called,
|
||||
// it is only ever called after we SetWeak on the Global.
|
||||
from_v8: *const fn (?*const v8.WeakCallbackInfo) callconv(.c) void,
|
||||
};
|
||||
|
||||
pub fn unknownWindowPropertyCallback(c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 {
|
||||
const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
||||
var caller: Caller = undefined;
|
||||
@@ -824,7 +853,6 @@ pub const JsApis = flattenTypes(&.{
|
||||
@import("../webapi/event/InputEvent.zig"),
|
||||
@import("../webapi/event/PromiseRejectionEvent.zig"),
|
||||
@import("../webapi/event/SubmitEvent.zig"),
|
||||
@import("../webapi/event/FormDataEvent.zig"),
|
||||
@import("../webapi/MessageChannel.zig"),
|
||||
@import("../webapi/MessagePort.zig"),
|
||||
@import("../webapi/media/MediaError.zig"),
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
|
||||
//
|
||||
// Francis Bouvier <francis@lightpanda.io>
|
||||
// Pierre Tachoire <pierre@lightpanda.io>
|
||||
//
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const Element = @import("webapi/Element.zig");
|
||||
const Node = @import("webapi/Node.zig");
|
||||
const Page = @import("Page.zig");
|
||||
const Selector = @import("webapi/selector/Selector.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
/// Collect all links (href attributes from anchor tags) under `root`.
|
||||
/// Returns a slice of strings allocated with `arena`.
|
||||
pub fn collectLinks(arena: Allocator, root: *Node, page: *Page) ![]const []const u8 {
|
||||
var links: std.ArrayList([]const u8) = .empty;
|
||||
|
||||
if (Selector.querySelectorAll(root, "a[href]", page)) |list| {
|
||||
defer list.deinit(page._session);
|
||||
|
||||
for (list._nodes) |node| {
|
||||
if (node.is(Element.Html.Anchor)) |anchor| {
|
||||
const href = anchor.getHref(page) catch |err| {
|
||||
@import("../lightpanda.zig").log.err(.app, "resolve href failed", .{ .err = err });
|
||||
continue;
|
||||
};
|
||||
|
||||
if (href.len > 0) {
|
||||
try links.append(arena, href);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else |err| {
|
||||
@import("../lightpanda.zig").log.err(.app, "query links failed", .{ .err = err });
|
||||
return err;
|
||||
}
|
||||
|
||||
return links.items;
|
||||
}
|
||||
@@ -21,6 +21,7 @@ const std = @import("std");
|
||||
const Page = @import("Page.zig");
|
||||
const URL = @import("URL.zig");
|
||||
const TreeWalker = @import("webapi/TreeWalker.zig");
|
||||
const CData = @import("webapi/CData.zig");
|
||||
const Element = @import("webapi/Element.zig");
|
||||
const Node = @import("webapi/Node.zig");
|
||||
const isAllWhitespace = @import("../string.zig").isAllWhitespace;
|
||||
|
||||
@@ -125,19 +125,6 @@
|
||||
</script>
|
||||
|
||||
|
||||
<script id="CanvasRenderingContext2D#canvas">
|
||||
{
|
||||
const element = document.createElement("canvas");
|
||||
const ctx = element.getContext("2d");
|
||||
testing.expectEqual(ctx.canvas, element);
|
||||
// Setting dimensions via ctx.canvas should update the element.
|
||||
ctx.canvas.width = 40;
|
||||
ctx.canvas.height = 25;
|
||||
testing.expectEqual(element.width, 40);
|
||||
testing.expectEqual(element.height, 25);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="getter">
|
||||
{
|
||||
const element = document.createElement("canvas");
|
||||
|
||||
@@ -734,101 +734,3 @@
|
||||
testing.expectEqual([['field', 'data'], ['x', '0'], ['y', '0']], entries);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=formDataEventFires>
|
||||
{
|
||||
// formdata event fires on the form when FormData is constructed with a form
|
||||
const form = document.createElement('form');
|
||||
|
||||
const input = document.createElement('input');
|
||||
input.name = 'field';
|
||||
input.value = 'hello';
|
||||
form.appendChild(input);
|
||||
|
||||
let eventFired = false;
|
||||
let receivedFormData = null;
|
||||
|
||||
form.addEventListener('formdata', (e) => {
|
||||
eventFired = true;
|
||||
receivedFormData = e.formData;
|
||||
});
|
||||
|
||||
const fd = new FormData(form);
|
||||
testing.expectEqual(true, eventFired);
|
||||
testing.expectEqual(fd, receivedFormData);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=formDataEventNotFiredWithoutForm>
|
||||
{
|
||||
// formdata event should NOT fire when FormData is constructed without a form
|
||||
const fd = new FormData();
|
||||
fd.append('a', '1');
|
||||
testing.expectEqual('1', fd.get('a'));
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=formDataEventBubbles>
|
||||
{
|
||||
// formdata event should bubble
|
||||
const container = document.createElement('div');
|
||||
const form = document.createElement('form');
|
||||
container.appendChild(form);
|
||||
document.body.appendChild(container);
|
||||
|
||||
const input = document.createElement('input');
|
||||
input.name = 'x';
|
||||
input.value = '1';
|
||||
form.appendChild(input);
|
||||
|
||||
let bubbled = false;
|
||||
container.addEventListener('formdata', () => {
|
||||
bubbled = true;
|
||||
});
|
||||
|
||||
const fd = new FormData(form);
|
||||
testing.expectEqual(true, bubbled);
|
||||
|
||||
document.body.removeChild(container);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=formDataEventNotCancelable>
|
||||
{
|
||||
// formdata event should not be cancelable
|
||||
const form = document.createElement('form');
|
||||
|
||||
const input = document.createElement('input');
|
||||
input.name = 'key';
|
||||
input.value = 'val';
|
||||
form.appendChild(input);
|
||||
|
||||
let cancelable = null;
|
||||
form.addEventListener('formdata', (e) => {
|
||||
cancelable = e.cancelable;
|
||||
});
|
||||
|
||||
const fd = new FormData(form);
|
||||
testing.expectEqual(false, cancelable);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=formDataEventModifyFormData>
|
||||
{
|
||||
// Listeners can modify formData during the event
|
||||
const form = document.createElement('form');
|
||||
|
||||
const input = document.createElement('input');
|
||||
input.name = 'original';
|
||||
input.value = 'data';
|
||||
form.appendChild(input);
|
||||
|
||||
form.addEventListener('formdata', (e) => {
|
||||
e.formData.append('added', 'by-listener');
|
||||
});
|
||||
|
||||
const fd = new FormData(form);
|
||||
testing.expectEqual('data', fd.get('original'));
|
||||
testing.expectEqual('by-listener', fd.get('added'));
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -871,3 +871,33 @@
|
||||
testing.expectEqual('', url.search);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="SOP Bypass">
|
||||
{
|
||||
const url = new URL('http://example.com/@bank.com');
|
||||
testing.expectEqual('http:', url.protocol);
|
||||
testing.expectEqual('example.com', url.hostname);
|
||||
testing.expectEqual('', url.port);
|
||||
testing.expectEqual('http://example.com', url.origin);
|
||||
testing.expectEqual('', url.username);
|
||||
testing.expectEqual('', url.password);
|
||||
}
|
||||
{
|
||||
const url = new URL('http://example.com?@bank.com');
|
||||
testing.expectEqual('http:', url.protocol);
|
||||
testing.expectEqual('example.com', url.hostname);
|
||||
testing.expectEqual('', url.port);
|
||||
testing.expectEqual('http://example.com', url.origin);
|
||||
testing.expectEqual('', url.username);
|
||||
testing.expectEqual('', url.password);
|
||||
}
|
||||
{
|
||||
const url = new URL('http://example.com#@bank.com');
|
||||
testing.expectEqual('http:', url.protocol);
|
||||
testing.expectEqual('example.com', url.hostname);
|
||||
testing.expectEqual('', url.port);
|
||||
testing.expectEqual('http://example.com', url.origin);
|
||||
testing.expectEqual('', url.username);
|
||||
testing.expectEqual('', url.password);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
|
||||
const Session = @import("../Session.zig");
|
||||
@@ -33,7 +31,7 @@ const AbstractRange = @This();
|
||||
|
||||
pub const _prototype_root = true;
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_rc: u8,
|
||||
_type: Type,
|
||||
_page_id: u32,
|
||||
_arena: Allocator,
|
||||
@@ -46,18 +44,24 @@ _start_container: *Node,
|
||||
_range_link: std.DoublyLinkedList.Node = .{},
|
||||
|
||||
pub fn acquireRef(self: *AbstractRange) void {
|
||||
self._rc.acquire();
|
||||
self._rc += 1;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *AbstractRange, session: *Session) void {
|
||||
if (session.findPageById(self._page_id)) |page| {
|
||||
page._live_ranges.remove(&self._range_link);
|
||||
pub fn deinit(self: *AbstractRange, shutdown: bool, session: *Session) void {
|
||||
_ = shutdown;
|
||||
const rc = self._rc;
|
||||
if (comptime IS_DEBUG) {
|
||||
std.debug.assert(rc != 0);
|
||||
}
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *AbstractRange, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
if (rc == 1) {
|
||||
if (session.findPageById(self._page_id)) |page| {
|
||||
page._live_ranges.remove(&self._range_link);
|
||||
}
|
||||
session.releaseArena(self._arena);
|
||||
return;
|
||||
}
|
||||
self._rc = rc - 1;
|
||||
}
|
||||
|
||||
pub const Type = union(enum) {
|
||||
@@ -334,6 +338,8 @@ pub const JsApi = struct {
|
||||
pub const name = "AbstractRange";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(AbstractRange.deinit);
|
||||
};
|
||||
|
||||
pub const startContainer = bridge.accessor(AbstractRange.getStartContainer, null, .{});
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const Writer = std.Io.Writer;
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
const Page = @import("../Page.zig");
|
||||
@@ -25,7 +25,6 @@ const Session = @import("../Session.zig");
|
||||
|
||||
const Mime = @import("../Mime.zig");
|
||||
|
||||
const Writer = std.Io.Writer;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
/// https://w3c.github.io/FileAPI/#blob-section
|
||||
@@ -35,7 +34,6 @@ const Blob = @This();
|
||||
pub const _prototype_root = true;
|
||||
|
||||
_type: Type,
|
||||
_rc: lp.RC(u32),
|
||||
|
||||
_arena: Allocator,
|
||||
|
||||
@@ -122,7 +120,6 @@ pub fn initWithMimeValidation(
|
||||
|
||||
const self = try arena.create(Blob);
|
||||
self.* = .{
|
||||
._rc = .{},
|
||||
._arena = arena,
|
||||
._type = .generic,
|
||||
._slice = data,
|
||||
@@ -131,18 +128,11 @@ pub fn initWithMimeValidation(
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Blob, session: *Session) void {
|
||||
pub fn deinit(self: *Blob, shutdown: bool, session: *Session) void {
|
||||
_ = shutdown;
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *Blob, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *Blob) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
const largest_vector = @max(std.simd.suggestVectorLength(u8) orelse 1, 8);
|
||||
/// Array of possible vector sizes for the current arch in decrementing order.
|
||||
/// We may move this to some file for SIMD helpers in the future.
|
||||
@@ -335,6 +325,8 @@ pub const JsApi = struct {
|
||||
pub const name = "Blob";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(Blob.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(Blob.init, .{});
|
||||
|
||||
@@ -24,6 +24,7 @@ const Page = @import("../Page.zig");
|
||||
|
||||
const Node = @import("Node.zig");
|
||||
const Element = @import("Element.zig");
|
||||
const DOMException = @import("DOMException.zig");
|
||||
const Custom = @import("element/html/Custom.zig");
|
||||
const CustomElementDefinition = @import("CustomElementDefinition.zig");
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ _fonts: ?*FontFaceSet = null,
|
||||
_write_insertion_point: ?*Node = null,
|
||||
_script_created_parser: ?Parser.Streaming = null,
|
||||
_adopted_style_sheets: ?js.Object.Global = null,
|
||||
_selection: Selection = .{ ._rc = .init(1) },
|
||||
_selection: Selection = .init,
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#throw-on-dynamic-markup-insertion-counter
|
||||
// Incremented during custom element reactions when parsing. When > 0,
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
|
||||
const Page = @import("../Page.zig");
|
||||
@@ -57,7 +55,7 @@ _is_trusted: bool = false,
|
||||
// - 0: no reference, always a transient state going to either 1 or about to be deinit'd
|
||||
// - 1: either zig or v8 have a reference
|
||||
// - 2: both zig and v8 have a reference
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_rc: u8 = 0,
|
||||
|
||||
pub const EventPhase = enum(u8) {
|
||||
none = 0,
|
||||
@@ -79,7 +77,6 @@ pub const Type = union(enum) {
|
||||
ui_event: *@import("event/UIEvent.zig"),
|
||||
promise_rejection_event: *@import("event/PromiseRejectionEvent.zig"),
|
||||
submit_event: *@import("event/SubmitEvent.zig"),
|
||||
form_data_event: *@import("event/FormDataEvent.zig"),
|
||||
};
|
||||
|
||||
pub const Options = struct {
|
||||
@@ -141,16 +138,25 @@ pub fn initEvent(
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *Event) void {
|
||||
self._rc.acquire();
|
||||
self._rc += 1;
|
||||
}
|
||||
|
||||
/// Force cleanup on Session shutdown.
|
||||
pub fn deinit(self: *Event, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
pub fn deinit(self: *Event, shutdown: bool, session: *Session) void {
|
||||
if (shutdown) {
|
||||
session.releaseArena(self._arena);
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *Event, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
const rc = self._rc;
|
||||
if (comptime IS_DEBUG) {
|
||||
std.debug.assert(rc != 0);
|
||||
}
|
||||
|
||||
if (rc == 1) {
|
||||
session.releaseArena(self._arena);
|
||||
} else {
|
||||
self._rc = rc - 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as(self: *Event, comptime T: type) *T {
|
||||
@@ -170,7 +176,6 @@ pub fn is(self: *Event, comptime T: type) ?*T {
|
||||
.pop_state_event => |e| return if (T == @import("event/PopStateEvent.zig")) e else null,
|
||||
.promise_rejection_event => |e| return if (T == @import("event/PromiseRejectionEvent.zig")) e else null,
|
||||
.submit_event => |e| return if (T == @import("event/SubmitEvent.zig")) e else null,
|
||||
.form_data_event => |e| return if (T == @import("event/FormDataEvent.zig")) e else null,
|
||||
.ui_event => |e| {
|
||||
if (T == @import("event/UIEvent.zig")) {
|
||||
return e;
|
||||
@@ -433,6 +438,8 @@ pub const JsApi = struct {
|
||||
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(Event.deinit);
|
||||
pub const enumerable = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn dispatchEvent(self: *EventTarget, event: *Event, page: *Page) !bool {
|
||||
event._is_trusted = false;
|
||||
|
||||
event.acquireRef();
|
||||
defer _ = event.releaseRef(page._session);
|
||||
defer event.deinit(false, page._session);
|
||||
try page._event_manager.dispatch(self, event);
|
||||
return !event._cancelable or !event._prevent_default;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
const Page = @import("../Page.zig");
|
||||
@@ -27,6 +26,7 @@ const Blob = @import("Blob.zig");
|
||||
|
||||
const File = @This();
|
||||
|
||||
/// `File` inherits `Blob`.
|
||||
_proto: *Blob,
|
||||
|
||||
// TODO: Implement File API.
|
||||
@@ -36,6 +36,10 @@ pub fn init(page: *Page) !*File {
|
||||
return page._factory.blob(arena, File{ ._proto = undefined });
|
||||
}
|
||||
|
||||
pub fn deinit(self: *File, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub const JsApi = struct {
|
||||
pub const bridge = js.Bridge(File);
|
||||
|
||||
@@ -43,6 +47,8 @@ pub const JsApi = struct {
|
||||
pub const name = "File";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(File.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(File.init, .{});
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
|
||||
const Page = @import("../Page.zig");
|
||||
@@ -33,7 +31,6 @@ const Allocator = std.mem.Allocator;
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/FileReader
|
||||
const FileReader = @This();
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_page: *Page,
|
||||
_proto: *EventTarget,
|
||||
_arena: Allocator,
|
||||
@@ -73,7 +70,7 @@ pub fn init(page: *Page) !*FileReader {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn deinit(self: *FileReader, session: *Session) void {
|
||||
pub fn deinit(self: *FileReader, _: bool, session: *Session) void {
|
||||
if (self._on_abort) |func| func.release();
|
||||
if (self._on_error) |func| func.release();
|
||||
if (self._on_load) |func| func.release();
|
||||
@@ -84,14 +81,6 @@ pub fn deinit(self: *FileReader, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *FileReader, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *FileReader) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
fn asEventTarget(self: *FileReader) *EventTarget {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -320,6 +309,8 @@ pub const JsApi = struct {
|
||||
pub const name = "FileReader";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(FileReader.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(FileReader.init, .{});
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
const std = @import("std");
|
||||
const js = @import("../js/js.zig");
|
||||
const String = @import("../../string.zig").String;
|
||||
|
||||
const Page = @import("../Page.zig");
|
||||
const Node = @import("Node.zig");
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
const std = @import("std");
|
||||
|
||||
const String = @import("../../string.zig").String;
|
||||
const log = @import("../../log.zig");
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
const color = @import("../color.zig");
|
||||
const Page = @import("../Page.zig");
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/ImageData/ImageData
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
const log = @import("../../log.zig");
|
||||
|
||||
@@ -41,7 +39,6 @@ pub fn registerTypes() []const type {
|
||||
|
||||
const IntersectionObserver = @This();
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_arena: Allocator,
|
||||
_callback: js.Function.Temp,
|
||||
_observing: std.ArrayList(*Element) = .{},
|
||||
@@ -111,22 +108,15 @@ pub fn init(callback: js.Function.Temp, options: ?ObserverInit, page: *Page) !*I
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *IntersectionObserver, session: *Session) void {
|
||||
pub fn deinit(self: *IntersectionObserver, shutdown: bool, session: *Session) void {
|
||||
self._callback.release();
|
||||
for (self._pending_entries.items) |entry| {
|
||||
entry.deinitIfUnused(session);
|
||||
if ((comptime IS_DEBUG) and !shutdown) {
|
||||
std.debug.assert(self._observing.items.len == 0);
|
||||
}
|
||||
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *IntersectionObserver, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *IntersectionObserver) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn observe(self: *IntersectionObserver, target: *Element, page: *Page) !void {
|
||||
// Check if already observing this target
|
||||
for (self._observing.items) |elem| {
|
||||
@@ -137,7 +127,7 @@ pub fn observe(self: *IntersectionObserver, target: *Element, page: *Page) !void
|
||||
|
||||
// Register with page if this is our first observation
|
||||
if (self._observing.items.len == 0) {
|
||||
self._rc._refs += 1;
|
||||
page.js.strongRef(self);
|
||||
try page.registerIntersectionObserver(self);
|
||||
}
|
||||
|
||||
@@ -154,19 +144,17 @@ pub fn observe(self: *IntersectionObserver, target: *Element, page: *Page) !void
|
||||
}
|
||||
|
||||
pub fn unobserve(self: *IntersectionObserver, target: *Element, page: *Page) void {
|
||||
const original_length = self._observing.items.len;
|
||||
for (self._observing.items, 0..) |elem, i| {
|
||||
if (elem == target) {
|
||||
_ = self._observing.swapRemove(i);
|
||||
_ = self._previous_states.remove(target);
|
||||
|
||||
// Remove any pending entries for this target.
|
||||
// Entries will be cleaned up by V8 GC via the finalizer.
|
||||
// Remove any pending entries for this target
|
||||
var j: usize = 0;
|
||||
while (j < self._pending_entries.items.len) {
|
||||
if (self._pending_entries.items[j]._target == target) {
|
||||
const entry = self._pending_entries.swapRemove(j);
|
||||
entry.deinitIfUnused(page._session);
|
||||
entry.deinit(false, page._session);
|
||||
} else {
|
||||
j += 1;
|
||||
}
|
||||
@@ -175,26 +163,21 @@ pub fn unobserve(self: *IntersectionObserver, target: *Element, page: *Page) voi
|
||||
}
|
||||
}
|
||||
|
||||
if (original_length > 0 and self._observing.items.len == 0) {
|
||||
self._rc._refs -= 1;
|
||||
if (self._observing.items.len == 0) {
|
||||
page.js.safeWeakRef(self);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(self: *IntersectionObserver, page: *Page) void {
|
||||
for (self._pending_entries.items) |entry| {
|
||||
entry.deinitIfUnused(page._session);
|
||||
}
|
||||
self._pending_entries.clearRetainingCapacity();
|
||||
page.unregisterIntersectionObserver(self);
|
||||
self._observing.clearRetainingCapacity();
|
||||
self._previous_states.clearRetainingCapacity();
|
||||
|
||||
const observing_count = self._observing.items.len;
|
||||
self._observing.clearRetainingCapacity();
|
||||
|
||||
if (observing_count > 0) {
|
||||
_ = self.releaseRef(page._session);
|
||||
for (self._pending_entries.items) |entry| {
|
||||
entry.deinit(false, page._session);
|
||||
}
|
||||
|
||||
page.unregisterIntersectionObserver(self);
|
||||
self._pending_entries.clearRetainingCapacity();
|
||||
page.js.safeWeakRef(self);
|
||||
}
|
||||
|
||||
pub fn takeRecords(self: *IntersectionObserver, page: *Page) ![]*IntersectionObserverEntry {
|
||||
@@ -285,6 +268,7 @@ fn checkIntersection(self: *IntersectionObserver, target: *Element, page: *Page)
|
||||
._bounding_client_rect = try page._factory.create(data.bounding_client_rect),
|
||||
._intersection_ratio = data.intersection_ratio,
|
||||
};
|
||||
|
||||
try self._pending_entries.append(self._arena, entry);
|
||||
}
|
||||
|
||||
@@ -326,7 +310,6 @@ pub fn deliverEntries(self: *IntersectionObserver, page: *Page) !void {
|
||||
}
|
||||
|
||||
pub const IntersectionObserverEntry = struct {
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_arena: Allocator,
|
||||
_time: f64,
|
||||
_target: *Element,
|
||||
@@ -336,25 +319,10 @@ pub const IntersectionObserverEntry = struct {
|
||||
_intersection_ratio: f64,
|
||||
_is_intersecting: bool,
|
||||
|
||||
pub fn deinit(self: *IntersectionObserverEntry, session: *Session) void {
|
||||
pub fn deinit(self: *IntersectionObserverEntry, _: bool, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
fn deinitIfUnused(self: *IntersectionObserverEntry, session: *Session) void {
|
||||
if (self._rc._refs == 0) {
|
||||
// hasn't been handed to JS yet.
|
||||
self.deinit(session);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *IntersectionObserverEntry, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *IntersectionObserverEntry) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn getTarget(self: *const IntersectionObserverEntry) *Element {
|
||||
return self._target;
|
||||
}
|
||||
@@ -390,6 +358,8 @@ pub const IntersectionObserverEntry = struct {
|
||||
pub const name = "IntersectionObserverEntry";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(IntersectionObserverEntry.deinit);
|
||||
};
|
||||
|
||||
pub const target = bridge.accessor(IntersectionObserverEntry.getTarget, null, .{});
|
||||
@@ -409,6 +379,8 @@ pub const JsApi = struct {
|
||||
pub const name = "IntersectionObserver";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(IntersectionObserver.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(init, .{});
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const String = @import("../../string.zig").String;
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
@@ -40,7 +39,6 @@ pub fn registerTypes() []const type {
|
||||
|
||||
const MutationObserver = @This();
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_arena: Allocator,
|
||||
_callback: js.Function.Temp,
|
||||
_observing: std.ArrayList(Observing) = .{},
|
||||
@@ -87,20 +85,15 @@ pub fn init(callback: js.Function.Temp, page: *Page) !*MutationObserver {
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Force cleanup on Session shutdown.
|
||||
pub fn deinit(self: *MutationObserver, session: *Session) void {
|
||||
pub fn deinit(self: *MutationObserver, shutdown: bool, session: *Session) void {
|
||||
self._callback.release();
|
||||
if ((comptime IS_DEBUG) and !shutdown) {
|
||||
std.debug.assert(self._observing.items.len == 0);
|
||||
}
|
||||
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *MutationObserver, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *MutationObserver) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn observe(self: *MutationObserver, target: *Node, options: ObserveOptions, page: *Page) !void {
|
||||
const arena = self._arena;
|
||||
|
||||
@@ -165,7 +158,7 @@ pub fn observe(self: *MutationObserver, target: *Node, options: ObserveOptions,
|
||||
|
||||
// Register with page if this is our first observation
|
||||
if (self._observing.items.len == 0) {
|
||||
self._rc._refs += 1;
|
||||
page.js.strongRef(self);
|
||||
try page.registerMutationObserver(self);
|
||||
}
|
||||
|
||||
@@ -176,17 +169,13 @@ pub fn observe(self: *MutationObserver, target: *Node, options: ObserveOptions,
|
||||
}
|
||||
|
||||
pub fn disconnect(self: *MutationObserver, page: *Page) void {
|
||||
page.unregisterMutationObserver(self);
|
||||
self._observing.clearRetainingCapacity();
|
||||
for (self._pending_records.items) |record| {
|
||||
_ = record.releaseRef(page._session);
|
||||
record.deinit(false, page._session);
|
||||
}
|
||||
self._pending_records.clearRetainingCapacity();
|
||||
const observing_count = self._observing.items.len;
|
||||
self._observing.clearRetainingCapacity();
|
||||
|
||||
if (observing_count > 0) {
|
||||
_ = self.releaseRef(page._session);
|
||||
}
|
||||
page.unregisterMutationObserver(self);
|
||||
page.js.safeWeakRef(self);
|
||||
}
|
||||
|
||||
pub fn takeRecords(self: *MutationObserver, page: *Page) ![]*MutationRecord {
|
||||
@@ -359,7 +348,6 @@ pub fn deliverRecords(self: *MutationObserver, page: *Page) !void {
|
||||
}
|
||||
|
||||
pub const MutationRecord = struct {
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_type: Type,
|
||||
_target: *Node,
|
||||
_arena: Allocator,
|
||||
@@ -376,18 +364,10 @@ pub const MutationRecord = struct {
|
||||
characterData,
|
||||
};
|
||||
|
||||
pub fn deinit(self: *MutationRecord, session: *Session) void {
|
||||
pub fn deinit(self: *MutationRecord, _: bool, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *MutationRecord, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *MutationRecord) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn getType(self: *const MutationRecord) []const u8 {
|
||||
return switch (self._type) {
|
||||
.attributes => "attributes",
|
||||
@@ -438,6 +418,8 @@ pub const MutationRecord = struct {
|
||||
pub const name = "MutationRecord";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(MutationRecord.deinit);
|
||||
};
|
||||
|
||||
pub const @"type" = bridge.accessor(MutationRecord.getType, null, .{});
|
||||
@@ -459,6 +441,8 @@ pub const JsApi = struct {
|
||||
pub const name = "MutationObserver";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(MutationObserver.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(MutationObserver.init, .{});
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const js = @import("../js/js.zig");
|
||||
const Page = @import("../Page.zig");
|
||||
const Session = @import("../Session.zig");
|
||||
@@ -51,23 +50,14 @@ pub fn query(_: *const Permissions, qd: QueryDescriptor, page: *Page) !js.Promis
|
||||
}
|
||||
|
||||
const PermissionStatus = struct {
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_arena: Allocator,
|
||||
_name: []const u8,
|
||||
_state: []const u8,
|
||||
|
||||
pub fn deinit(self: *PermissionStatus, session: *Session) void {
|
||||
pub fn deinit(self: *PermissionStatus, _: bool, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *PermissionStatus, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *PermissionStatus) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
fn getName(self: *const PermissionStatus) []const u8 {
|
||||
return self._name;
|
||||
}
|
||||
@@ -82,6 +72,8 @@ const PermissionStatus = struct {
|
||||
pub const name = "PermissionStatus";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(PermissionStatus.deinit);
|
||||
};
|
||||
pub const name = bridge.accessor(getName, null, .{});
|
||||
pub const state = bridge.accessor(getState, null, .{});
|
||||
|
||||
@@ -28,6 +28,8 @@ const DocumentFragment = @import("DocumentFragment.zig");
|
||||
const AbstractRange = @import("AbstractRange.zig");
|
||||
const DOMRect = @import("DOMRect.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const Range = @This();
|
||||
|
||||
_proto: *AbstractRange,
|
||||
@@ -38,6 +40,10 @@ pub fn init(page: *Page) !*Range {
|
||||
return page._factory.abstractRange(arena, Range{ ._proto = undefined }, page);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Range, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asAbstractRange(self: *Range) *AbstractRange {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -693,6 +699,8 @@ pub const JsApi = struct {
|
||||
pub const name = "Range";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(Range.deinit);
|
||||
};
|
||||
|
||||
// Constants for compareBoundaryPoints
|
||||
|
||||
@@ -62,6 +62,5 @@ pub const JsApi = struct {
|
||||
|
||||
pub const constructor = bridge.constructor(ResizeObserver.init, .{});
|
||||
pub const observe = bridge.function(ResizeObserver.observe, .{});
|
||||
pub const unobserve = bridge.function(ResizeObserver.unobserve, .{});
|
||||
pub const disconnect = bridge.function(ResizeObserver.disconnect, .{});
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const log = @import("../../log.zig");
|
||||
|
||||
const js = @import("../js/js.zig");
|
||||
const Page = @import("../Page.zig");
|
||||
@@ -27,33 +27,25 @@ const Range = @import("Range.zig");
|
||||
const AbstractRange = @import("AbstractRange.zig");
|
||||
const Node = @import("Node.zig");
|
||||
const Event = @import("Event.zig");
|
||||
const Document = @import("Document.zig");
|
||||
|
||||
/// https://w3c.github.io/selection-api/
|
||||
const Selection = @This();
|
||||
|
||||
pub const SelectionDirection = enum { backward, forward, none };
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_range: ?*Range = null,
|
||||
_direction: SelectionDirection = .none,
|
||||
|
||||
pub const init: Selection = .{};
|
||||
|
||||
pub fn deinit(self: *Selection, session: *Session) void {
|
||||
pub fn deinit(self: *Selection, shutdown: bool, session: *Session) void {
|
||||
if (self._range) |r| {
|
||||
r.asAbstractRange().releaseRef(session);
|
||||
r.deinit(shutdown, session);
|
||||
self._range = null;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *Selection, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *Selection) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
fn dispatchSelectionChangeEvent(page: *Page) !void {
|
||||
const event = try Event.init("selectionchange", .{}, page);
|
||||
try page._event_manager.dispatch(page.document.asEventTarget(), event);
|
||||
@@ -703,7 +695,7 @@ pub fn toString(self: *const Selection, page: *Page) ![]const u8 {
|
||||
|
||||
fn setRange(self: *Selection, new_range: ?*Range, page: *Page) void {
|
||||
if (self._range) |existing| {
|
||||
_ = existing.asAbstractRange().releaseRef(page._session);
|
||||
existing.deinit(false, page._session);
|
||||
}
|
||||
if (new_range) |nr| {
|
||||
nr.asAbstractRange().acquireRef();
|
||||
@@ -718,6 +710,7 @@ pub const JsApi = struct {
|
||||
pub const name = "Selection";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const finalizer = bridge.finalizer(Selection.deinit);
|
||||
};
|
||||
|
||||
pub const anchorNode = bridge.accessor(Selection.getAnchorNode, null, .{});
|
||||
|
||||
@@ -256,7 +256,8 @@ pub fn createObjectURL(blob: *Blob, page: *Page) ![]const u8 {
|
||||
.{ page.origin orelse "null", uuid_buf },
|
||||
);
|
||||
try page._blob_urls.put(page.arena, blob_url, blob);
|
||||
blob.acquireRef();
|
||||
// prevent GC from cleaning up the blob while it's in the registry
|
||||
page.js.strongRef(blob);
|
||||
return blob_url;
|
||||
}
|
||||
|
||||
@@ -266,8 +267,9 @@ pub fn revokeObjectURL(url: []const u8, page: *Page) void {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove from registry and release strong ref (no-op if not found)
|
||||
if (page._blob_urls.fetchRemove(url)) |entry| {
|
||||
entry.value.releaseRef(page._session);
|
||||
page.js.weakRef(entry.value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
const js = @import("../js/js.zig");
|
||||
const Page = @import("../Page.zig");
|
||||
const EventTarget = @import("EventTarget.zig");
|
||||
const Window = @import("Window.zig");
|
||||
|
||||
const VisualViewport = @This();
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const log = @import("../../../log.zig");
|
||||
const js = @import("../../js/js.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
@@ -34,7 +33,6 @@ const PlayState = enum {
|
||||
finished,
|
||||
};
|
||||
|
||||
_rc: lp.RC(u32) = .{},
|
||||
_page: *Page,
|
||||
_arena: Allocator,
|
||||
|
||||
@@ -64,18 +62,10 @@ pub fn init(page: *Page) !*Animation {
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Animation, session: *Session) void {
|
||||
pub fn deinit(self: *Animation, _: bool, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *Animation, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *Animation) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn play(self: *Animation, page: *Page) !void {
|
||||
if (self._playState == .running) {
|
||||
return;
|
||||
@@ -85,7 +75,7 @@ pub fn play(self: *Animation, page: *Page) !void {
|
||||
self._playState = .running;
|
||||
|
||||
// Schedule the transition from .running => .finished in 10ms.
|
||||
self.acquireRef();
|
||||
page.js.strongRef(self);
|
||||
try page.js.scheduler.add(
|
||||
self,
|
||||
Animation.update,
|
||||
@@ -211,7 +201,7 @@ fn update(ctx: *anyopaque) !?u32 {
|
||||
}
|
||||
|
||||
// No future change scheduled, set the object weak for garbage collection.
|
||||
self.releaseRef(self._page._session);
|
||||
self._page.js.weakRef(self);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -230,6 +220,8 @@ pub const JsApi = struct {
|
||||
pub const name = "Animation";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(Animation.deinit);
|
||||
};
|
||||
|
||||
pub const play = bridge.function(Animation.play, .{});
|
||||
|
||||
@@ -23,24 +23,16 @@ const js = @import("../../js/js.zig");
|
||||
const color = @import("../../color.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
|
||||
const Canvas = @import("../element/html/Canvas.zig");
|
||||
const ImageData = @import("../ImageData.zig");
|
||||
|
||||
/// This class doesn't implement a `constructor`.
|
||||
/// It can be obtained with a call to `HTMLCanvasElement#getContext`.
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
|
||||
const CanvasRenderingContext2D = @This();
|
||||
/// Reference to the parent canvas element.
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/canvas
|
||||
_canvas: *Canvas,
|
||||
/// Fill color.
|
||||
/// TODO: Add support for `CanvasGradient` and `CanvasPattern`.
|
||||
_fill_style: color.RGBA = color.RGBA.Named.black,
|
||||
|
||||
pub fn getCanvas(self: *const CanvasRenderingContext2D) *Canvas {
|
||||
return self._canvas;
|
||||
}
|
||||
|
||||
pub fn getFillStyle(self: *const CanvasRenderingContext2D, page: *Page) ![]const u8 {
|
||||
var w = std.Io.Writer.Allocating.init(page.call_arena);
|
||||
try self._fill_style.format(&w.writer);
|
||||
@@ -133,7 +125,6 @@ pub const JsApi = struct {
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
};
|
||||
|
||||
pub const canvas = bridge.accessor(CanvasRenderingContext2D.getCanvas, null, .{});
|
||||
pub const font = bridge.property("10px sans-serif", .{ .template = false, .readonly = false });
|
||||
pub const globalAlpha = bridge.property(1.0, .{ .template = false, .readonly = false });
|
||||
pub const globalCompositeOperation = bridge.property("source-over", .{ .template = false, .readonly = false });
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const String = @import("../../../string.zig").String;
|
||||
const js = @import("../../js/js.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
const CData = @import("../CData.zig");
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
|
||||
const log = @import("../../../log.zig");
|
||||
const js = @import("../../js/js.zig");
|
||||
@@ -38,9 +37,15 @@ _data: union(enum) {
|
||||
radio_node_list: *RadioNodeList,
|
||||
name: NodeLive(.name),
|
||||
},
|
||||
_rc: lp.RC(u32) = .{},
|
||||
_rc: usize = 0,
|
||||
|
||||
pub fn deinit(self: *NodeList, _: bool, session: *Session) void {
|
||||
const rc = self._rc;
|
||||
if (rc > 1) {
|
||||
self._rc = rc - 1;
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *NodeList, session: *Session) void {
|
||||
switch (self._data) {
|
||||
.selector_list => |list| list.deinit(session),
|
||||
.child_nodes => |cn| cn.deinit(session),
|
||||
@@ -48,12 +53,8 @@ pub fn deinit(self: *NodeList, session: *Session) void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *NodeList, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *NodeList) void {
|
||||
self._rc.acquire();
|
||||
self._rc += 1;
|
||||
}
|
||||
|
||||
pub fn length(self: *NodeList, page: *Page) !u32 {
|
||||
@@ -118,12 +119,8 @@ const Iterator = struct {
|
||||
|
||||
const Entry = struct { u32, *Node };
|
||||
|
||||
pub fn deinit(self: *Iterator, session: *Session) void {
|
||||
self.list.deinit(session);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *Iterator, session: *Session) void {
|
||||
self.list.releaseRef(session);
|
||||
pub fn deinit(self: *Iterator, shutdown: bool, session: *Session) void {
|
||||
self.list.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *Iterator) void {
|
||||
@@ -146,6 +143,8 @@ pub const JsApi = struct {
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const enumerable = false;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(NodeList.deinit);
|
||||
};
|
||||
|
||||
pub const length = bridge.accessor(NodeList.length, null, .{});
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const js = @import("../../js/js.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
const Session = @import("../../Session.zig");
|
||||
@@ -41,15 +40,9 @@ pub fn Entry(comptime Inner: type, comptime field: ?[]const u8) type {
|
||||
return page._factory.create(Self{ .inner = inner });
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, session: *Session) void {
|
||||
_ = self;
|
||||
_ = session;
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *Self, session: *Session) void {
|
||||
// Release the reference to the inner type that we acquired
|
||||
if (@hasDecl(Inner, "releaseRef")) {
|
||||
self.inner.releaseRef(session);
|
||||
pub fn deinit(self: *Self, shutdown: bool, session: *Session) void {
|
||||
if (@hasDecl(Inner, "deinit")) {
|
||||
self.inner.deinit(shutdown, session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +73,8 @@ pub fn Entry(comptime Inner: type, comptime field: ?[]const u8) type {
|
||||
pub const Meta = struct {
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(Self.deinit);
|
||||
};
|
||||
|
||||
pub const next = bridge.function(Self.next, .{ .null_as_undefined = true });
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const log = @import("../../../log.zig");
|
||||
const crypto = @import("../../../sys/libcrypto.zig");
|
||||
|
||||
const Page = @import("../../Page.zig");
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const log = @import("../../../log.zig");
|
||||
const crypto = @import("../../../sys/libcrypto.zig");
|
||||
|
||||
const Page = @import("../../Page.zig");
|
||||
const js = @import("../../js/js.zig");
|
||||
const Algorithm = @import("algorithm.zig").Algorithm;
|
||||
|
||||
const CryptoKey = @import("../CryptoKey.zig");
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const js = @import("../../js/js.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
const Session = @import("../../Session.zig");
|
||||
@@ -26,7 +25,6 @@ const Allocator = std.mem.Allocator;
|
||||
|
||||
const FontFace = @This();
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_arena: Allocator,
|
||||
_family: []const u8,
|
||||
|
||||
@@ -44,18 +42,10 @@ pub fn init(family: []const u8, source: []const u8, page: *Page) !*FontFace {
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *FontFace, session: *Session) void {
|
||||
pub fn deinit(self: *FontFace, _: bool, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *FontFace, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *FontFace) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn getFamily(self: *const FontFace) []const u8 {
|
||||
return self._family;
|
||||
}
|
||||
@@ -77,6 +67,8 @@ pub const JsApi = struct {
|
||||
pub const name = "FontFace";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(FontFace.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(FontFace.init, .{});
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const js = @import("../../js/js.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
const Session = @import("../../Session.zig");
|
||||
@@ -29,7 +28,6 @@ const Allocator = std.mem.Allocator;
|
||||
|
||||
const FontFaceSet = @This();
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_proto: *EventTarget,
|
||||
_arena: Allocator,
|
||||
|
||||
@@ -43,18 +41,10 @@ pub fn init(page: *Page) !*FontFaceSet {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn deinit(self: *FontFaceSet, session: *Session) void {
|
||||
pub fn deinit(self: *FontFaceSet, _: bool, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *FontFaceSet, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *FontFaceSet) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn asEventTarget(self: *FontFaceSet) *EventTarget {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -105,6 +95,8 @@ pub const JsApi = struct {
|
||||
pub const name = "FontFaceSet";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(FontFaceSet.deinit);
|
||||
};
|
||||
|
||||
pub const size = bridge.property(0, .{ .template = false, .readonly = true });
|
||||
|
||||
@@ -22,6 +22,7 @@ const reflect = @import("../../reflect.zig");
|
||||
const log = @import("../../../log.zig");
|
||||
|
||||
const global_event_handlers = @import("../global_event_handlers.zig");
|
||||
const GlobalEventHandlersLookup = global_event_handlers.Lookup;
|
||||
const GlobalEventHandler = global_event_handlers.Handler;
|
||||
|
||||
const Page = @import("../../Page.zig");
|
||||
|
||||
@@ -67,9 +67,9 @@ const DrawingContext = union(enum) {
|
||||
webgl: *WebGLRenderingContext,
|
||||
};
|
||||
|
||||
pub fn getContext(self: *Canvas, context_type: []const u8, page: *Page) !?DrawingContext {
|
||||
pub fn getContext(_: *Canvas, context_type: []const u8, page: *Page) !?DrawingContext {
|
||||
if (std.mem.eql(u8, context_type, "2d")) {
|
||||
const ctx = try page._factory.create(CanvasRenderingContext2D{ ._canvas = self });
|
||||
const ctx = try page._factory.create(CanvasRenderingContext2D{});
|
||||
return .{ .@"2d" = ctx };
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const log = @import("../../../../log.zig");
|
||||
const js = @import("../../../js/js.zig");
|
||||
const Page = @import("../../../Page.zig");
|
||||
const Window = @import("../../Window.zig");
|
||||
|
||||
@@ -5,6 +5,10 @@ const URL = @import("../../../URL.zig");
|
||||
const Node = @import("../../Node.zig");
|
||||
const Element = @import("../../Element.zig");
|
||||
const HtmlElement = @import("../Html.zig");
|
||||
const Event = @import("../../Event.zig");
|
||||
const log = @import("../../../../log.zig");
|
||||
|
||||
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
const Image = @This();
|
||||
_proto: *HtmlElement,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
const std = @import("std");
|
||||
|
||||
const log = @import("../../../../log.zig");
|
||||
const js = @import("../../../js/js.zig");
|
||||
const Page = @import("../../../Page.zig");
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const js = @import("../../js/js.zig");
|
||||
|
||||
const Page = @import("../../Page.zig");
|
||||
@@ -26,7 +25,6 @@ const Allocator = std.mem.Allocator;
|
||||
|
||||
const TextDecoder = @This();
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_fatal: bool,
|
||||
_arena: Allocator,
|
||||
_ignore_bom: bool,
|
||||
@@ -62,18 +60,10 @@ pub fn init(label_: ?[]const u8, opts_: ?InitOpts, page: *Page) !*TextDecoder {
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *TextDecoder, session: *Session) void {
|
||||
pub fn deinit(self: *TextDecoder, _: bool, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *TextDecoder, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *TextDecoder) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn getIgnoreBOM(self: *const TextDecoder) bool {
|
||||
return self._ignore_bom;
|
||||
}
|
||||
@@ -119,6 +109,8 @@ pub const JsApi = struct {
|
||||
pub const name = "TextDecoder";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(TextDecoder.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(TextDecoder.init, .{});
|
||||
|
||||
@@ -22,6 +22,7 @@ const js = @import("../../js/js.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
const Session = @import("../../Session.zig");
|
||||
const Event = @import("../Event.zig");
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const CompositionEvent = @This();
|
||||
|
||||
@@ -53,6 +54,10 @@ pub fn init(typ: []const u8, opts_: ?Options, page: *Page) !*CompositionEvent {
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *CompositionEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *CompositionEvent) *Event {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -68,6 +73,8 @@ pub const JsApi = struct {
|
||||
pub const name = "CompositionEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(CompositionEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(CompositionEvent.init, .{});
|
||||
|
||||
@@ -73,19 +73,11 @@ pub fn initCustomEvent(
|
||||
self._detail = detail_;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *CustomEvent, session: *Session) void {
|
||||
pub fn deinit(self: *CustomEvent, shutdown: bool, session: *Session) void {
|
||||
if (self._detail) |d| {
|
||||
d.release();
|
||||
}
|
||||
self._proto.deinit(session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *CustomEvent) void {
|
||||
self._proto.acquireRef();
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *CustomEvent, session: *Session) void {
|
||||
self._proto._rc.release(self, session);
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *CustomEvent) *Event {
|
||||
@@ -103,6 +95,8 @@ pub const JsApi = struct {
|
||||
pub const name = "CustomEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(CustomEvent.deinit);
|
||||
pub const enumerable = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -80,19 +80,11 @@ fn initWithTrusted(arena: Allocator, typ: String, opts_: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *ErrorEvent, session: *Session) void {
|
||||
pub fn deinit(self: *ErrorEvent, shutdown: bool, session: *Session) void {
|
||||
if (self._error) |e| {
|
||||
e.release();
|
||||
}
|
||||
self._proto.deinit(session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *ErrorEvent) void {
|
||||
self._proto.acquireRef();
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *ErrorEvent, session: *Session) void {
|
||||
self._proto._rc.release(self, session);
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *ErrorEvent) *Event {
|
||||
|
||||
@@ -70,6 +70,10 @@ fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *FocusEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *FocusEvent) *Event {
|
||||
return self._proto.asEvent();
|
||||
}
|
||||
@@ -85,6 +89,8 @@ pub const JsApi = struct {
|
||||
pub const name = "FocusEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(FocusEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(FocusEvent.init, .{});
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
|
||||
//
|
||||
// Francis Bouvier <francis@lightpanda.io>
|
||||
// Pierre Tachoire <pierre@lightpanda.io>
|
||||
//
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const String = @import("../../../string.zig").String;
|
||||
const Page = @import("../../Page.zig");
|
||||
const Session = @import("../../Session.zig");
|
||||
const js = @import("../../js/js.zig");
|
||||
|
||||
const Event = @import("../Event.zig");
|
||||
|
||||
const FormData = @import("../net/FormData.zig");
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/FormDataEvent
|
||||
const FormDataEvent = @This();
|
||||
|
||||
_proto: *Event,
|
||||
_form_data: ?*FormData = null,
|
||||
|
||||
const Options = Event.inheritOptions(FormDataEvent, struct {
|
||||
formData: ?*FormData = null,
|
||||
});
|
||||
|
||||
pub fn init(typ: []const u8, maybe_options: Options, page: *Page) !*FormDataEvent {
|
||||
const arena = try page.getArena(.{ .debug = "FormDataEvent" });
|
||||
errdefer page.releaseArena(arena);
|
||||
const type_string = try String.init(arena, typ, .{});
|
||||
return initWithTrusted(arena, type_string, maybe_options, false, page);
|
||||
}
|
||||
|
||||
pub fn initTrusted(typ: String, _opts: ?Options, page: *Page) !*FormDataEvent {
|
||||
const arena = try page.getArena(.{ .debug = "FormDataEvent.trusted" });
|
||||
errdefer page.releaseArena(arena);
|
||||
return initWithTrusted(arena, typ, _opts, true, page);
|
||||
}
|
||||
|
||||
fn initWithTrusted(arena: Allocator, typ: String, maybe_options: ?Options, trusted: bool, page: *Page) !*FormDataEvent {
|
||||
const options = maybe_options orelse Options{};
|
||||
|
||||
const event = try page._factory.event(
|
||||
arena,
|
||||
typ,
|
||||
FormDataEvent{
|
||||
._proto = undefined,
|
||||
._form_data = options.formData,
|
||||
},
|
||||
);
|
||||
|
||||
Event.populatePrototypes(event, options, trusted);
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *FormDataEvent) *Event {
|
||||
return self._proto;
|
||||
}
|
||||
|
||||
pub fn getFormData(self: *const FormDataEvent) ?*FormData {
|
||||
return self._form_data;
|
||||
}
|
||||
|
||||
pub const JsApi = struct {
|
||||
pub const bridge = js.Bridge(FormDataEvent);
|
||||
|
||||
pub const Meta = struct {
|
||||
pub const name = "FormDataEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(FormDataEvent.init, .{});
|
||||
pub const formData = bridge.accessor(FormDataEvent.getFormData, null, .{});
|
||||
};
|
||||
@@ -83,6 +83,10 @@ fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *InputEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *InputEvent) *Event {
|
||||
return self._proto.asEvent();
|
||||
}
|
||||
@@ -106,6 +110,8 @@ pub const JsApi = struct {
|
||||
pub const name = "InputEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(InputEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(InputEvent.init, .{});
|
||||
|
||||
@@ -229,6 +229,10 @@ fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *KeyboardEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *KeyboardEvent) *Event {
|
||||
return self._proto.asEvent();
|
||||
}
|
||||
@@ -292,6 +296,8 @@ pub const JsApi = struct {
|
||||
pub const name = "KeyboardEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(KeyboardEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(KeyboardEvent.init, .{});
|
||||
|
||||
@@ -73,19 +73,11 @@ fn initWithTrusted(arena: Allocator, typ: String, opts_: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *MessageEvent, session: *Session) void {
|
||||
pub fn deinit(self: *MessageEvent, shutdown: bool, session: *Session) void {
|
||||
if (self._data) |d| {
|
||||
d.release();
|
||||
}
|
||||
self._proto.deinit(session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *MessageEvent) void {
|
||||
self._proto.acquireRef();
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *MessageEvent, session: *Session) void {
|
||||
self._proto._rc.release(self, session);
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *MessageEvent) *Event {
|
||||
@@ -111,6 +103,8 @@ pub const JsApi = struct {
|
||||
pub const name = "MessageEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(MessageEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(MessageEvent.init, .{});
|
||||
|
||||
@@ -121,6 +121,10 @@ fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *MouseEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *MouseEvent) *Event {
|
||||
return self._proto.asEvent();
|
||||
}
|
||||
@@ -199,6 +203,8 @@ pub const JsApi = struct {
|
||||
pub const name = "MouseEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(MouseEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(MouseEvent.init, .{});
|
||||
|
||||
@@ -83,6 +83,10 @@ fn initWithTrusted(
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *NavigationCurrentEntryChangeEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *NavigationCurrentEntryChangeEvent) *Event {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -102,6 +106,8 @@ pub const JsApi = struct {
|
||||
pub const name = "NavigationCurrentEntryChangeEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(NavigationCurrentEntryChangeEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(NavigationCurrentEntryChangeEvent.init, .{});
|
||||
|
||||
@@ -66,6 +66,10 @@ fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *PageTransitionEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *PageTransitionEvent) *Event {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -81,6 +85,8 @@ pub const JsApi = struct {
|
||||
pub const name = "PageTransitionEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(PageTransitionEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(PageTransitionEvent.init, .{});
|
||||
|
||||
@@ -128,6 +128,10 @@ pub fn init(typ: []const u8, _opts: ?Options, page: *Page) !*PointerEvent {
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *PointerEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *PointerEvent) *Event {
|
||||
return self._proto.asEvent();
|
||||
}
|
||||
@@ -187,6 +191,8 @@ pub const JsApi = struct {
|
||||
pub const name = "PointerEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(PointerEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(PointerEvent.init, .{});
|
||||
|
||||
@@ -67,6 +67,10 @@ fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *PopStateEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *PopStateEvent) *Event {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -88,6 +92,8 @@ pub const JsApi = struct {
|
||||
pub const name = "PopStateEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(PopStateEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(PopStateEvent.init, .{});
|
||||
|
||||
@@ -68,6 +68,10 @@ fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *ProgressEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *ProgressEvent) *Event {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -92,6 +96,8 @@ pub const JsApi = struct {
|
||||
pub const name = "ProgressEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(ProgressEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(ProgressEvent.init, .{});
|
||||
|
||||
@@ -22,6 +22,7 @@ const js = @import("../../js/js.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
const Session = @import("../../Session.zig");
|
||||
const Event = @import("../Event.zig");
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const PromiseRejectionEvent = @This();
|
||||
|
||||
@@ -56,22 +57,14 @@ pub fn init(typ: []const u8, opts_: ?Options, page: *Page) !*PromiseRejectionEve
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *PromiseRejectionEvent, session: *Session) void {
|
||||
pub fn deinit(self: *PromiseRejectionEvent, shutdown: bool, session: *Session) void {
|
||||
if (self._reason) |r| {
|
||||
r.release();
|
||||
}
|
||||
if (self._promise) |p| {
|
||||
p.release();
|
||||
}
|
||||
self._proto.deinit(session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *PromiseRejectionEvent) void {
|
||||
self._proto.acquireRef();
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *PromiseRejectionEvent, session: *Session) void {
|
||||
self._proto._rc.release(self, session);
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *PromiseRejectionEvent) *Event {
|
||||
@@ -93,6 +86,8 @@ pub const JsApi = struct {
|
||||
pub const name = "PromiseRejectionEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(PromiseRejectionEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(PromiseRejectionEvent.init, .{});
|
||||
|
||||
@@ -26,7 +26,7 @@ const Event = @import("../Event.zig");
|
||||
const HtmlElement = @import("../element/Html.zig");
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent
|
||||
const SubmitEvent = @This();
|
||||
|
||||
_proto: *Event,
|
||||
@@ -67,6 +67,10 @@ fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *SubmitEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *SubmitEvent) *Event {
|
||||
return self._proto;
|
||||
}
|
||||
@@ -82,6 +86,8 @@ pub const JsApi = struct {
|
||||
pub const name = "SubmitEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(SubmitEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(SubmitEvent.init, .{});
|
||||
|
||||
@@ -59,6 +59,10 @@ pub fn init(typ: []const u8, _opts: ?Options, page: *Page) !*TextEvent {
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *TextEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *TextEvent) *Event {
|
||||
return self._proto.asEvent();
|
||||
}
|
||||
@@ -97,6 +101,8 @@ pub const JsApi = struct {
|
||||
pub const name = "TextEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(TextEvent.deinit);
|
||||
};
|
||||
|
||||
// No constructor - TextEvent is created via document.createEvent('TextEvent')
|
||||
|
||||
@@ -71,6 +71,10 @@ pub fn init(typ: []const u8, _opts: ?Options, page: *Page) !*UIEvent {
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *UIEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn as(self: *UIEvent, comptime T: type) *T {
|
||||
return self.is(T).?;
|
||||
}
|
||||
@@ -118,6 +122,8 @@ pub const JsApi = struct {
|
||||
pub const name = "UIEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(UIEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(UIEvent.init, .{});
|
||||
|
||||
@@ -87,6 +87,10 @@ pub fn init(typ: []const u8, _opts: ?Options, page: *Page) !*WheelEvent {
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *WheelEvent, shutdown: bool, session: *Session) void {
|
||||
self._proto.deinit(shutdown, session);
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *WheelEvent) *Event {
|
||||
return self._proto.asEvent();
|
||||
}
|
||||
@@ -114,6 +118,8 @@ pub const JsApi = struct {
|
||||
pub const name = "WheelEvent";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(WheelEvent.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(WheelEvent.init, .{});
|
||||
|
||||
@@ -27,6 +27,8 @@ const Page = @import("../../Page.zig");
|
||||
const Event = @import("../Event.zig");
|
||||
const EventTarget = @import("../EventTarget.zig");
|
||||
|
||||
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Navigation
|
||||
const Navigation = @This();
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
const std = @import("std");
|
||||
const URL = @import("../URL.zig");
|
||||
const EventTarget = @import("../EventTarget.zig");
|
||||
const NavigationState = @import("root.zig").NavigationState;
|
||||
const Page = @import("../../Page.zig");
|
||||
const js = @import("../../js/js.zig");
|
||||
|
||||
@@ -62,7 +62,7 @@ pub fn init(input: Input, options: ?InitOpts, page: *Page) !js.Promise {
|
||||
}
|
||||
|
||||
const response = try Response.init(null, .{ .status = 0 }, page);
|
||||
errdefer response.deinit(page._session);
|
||||
errdefer response.deinit(true, page._session);
|
||||
|
||||
const fetch = try response._arena.create(Fetch);
|
||||
fetch.* = .{
|
||||
@@ -225,7 +225,7 @@ fn httpDoneCallback(ctx: *anyopaque) !void {
|
||||
return ls.toLocal(self._resolver).resolve("fetch done", js_val);
|
||||
}
|
||||
|
||||
fn httpErrorCallback(ctx: *anyopaque, _: anyerror) void {
|
||||
fn httpErrorCallback(ctx: *anyopaque, err: anyerror) void {
|
||||
const self: *Fetch = @ptrCast(@alignCast(ctx));
|
||||
|
||||
var response = self._response;
|
||||
@@ -234,7 +234,7 @@ fn httpErrorCallback(ctx: *anyopaque, _: anyerror) void {
|
||||
// clear this. (defer since `self is in the response's arena).
|
||||
|
||||
defer if (self._owns_response) {
|
||||
response.deinit(self._page._session);
|
||||
response.deinit(err == error.Abort, self._page._session);
|
||||
self._owns_response = false;
|
||||
};
|
||||
|
||||
@@ -256,7 +256,7 @@ fn httpShutdownCallback(ctx: *anyopaque) void {
|
||||
if (self._owns_response) {
|
||||
var response = self._response;
|
||||
response._transfer = null;
|
||||
response.deinit(self._page._session);
|
||||
response.deinit(true, self._page._session);
|
||||
// Do not access `self` after this point: the Fetch struct was
|
||||
// allocated from response._arena which has been released.
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ const log = @import("../../../log.zig");
|
||||
|
||||
const js = @import("../../js/js.zig");
|
||||
const Page = @import("../../Page.zig");
|
||||
const Node = @import("../Node.zig");
|
||||
const Form = @import("../element/html/Form.zig");
|
||||
const Element = @import("../Element.zig");
|
||||
const KeyValueList = @import("../KeyValueList.zig");
|
||||
@@ -34,22 +35,10 @@ _arena: Allocator,
|
||||
_list: KeyValueList,
|
||||
|
||||
pub fn init(form: ?*Form, submitter: ?*Element, page: *Page) !*FormData {
|
||||
const form_data = try page._factory.create(FormData{
|
||||
return page._factory.create(FormData{
|
||||
._arena = page.arena,
|
||||
._list = try collectForm(page.arena, form, submitter, page),
|
||||
});
|
||||
|
||||
// Dispatch `formdata` event if form provided.
|
||||
if (form) |_form| {
|
||||
const form_data_event = try (@import("../event/FormDataEvent.zig")).initTrusted(
|
||||
comptime .wrap("formdata"),
|
||||
.{ .bubbles = true, .cancelable = false, .formData = form_data },
|
||||
page,
|
||||
);
|
||||
try page._event_manager.dispatch(_form.asNode().asEventTarget(), form_data_event.asEvent());
|
||||
}
|
||||
|
||||
return form_data;
|
||||
}
|
||||
|
||||
pub fn get(self: *const FormData, name: []const u8) ?[]const u8 {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const js = @import("../../js/js.zig");
|
||||
const HttpClient = @import("../../HttpClient.zig");
|
||||
|
||||
@@ -39,7 +38,6 @@ pub const Type = enum {
|
||||
opaqueredirect,
|
||||
};
|
||||
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_status: u16,
|
||||
_arena: Allocator,
|
||||
_headers: *Headers,
|
||||
@@ -80,22 +78,18 @@ pub fn init(body_: ?[]const u8, opts_: ?InitOpts, page: *Page) !*Response {
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Response, session: *Session) void {
|
||||
pub fn deinit(self: *Response, shutdown: bool, session: *Session) void {
|
||||
if (self._transfer) |transfer| {
|
||||
transfer.abort(error.Abort);
|
||||
if (shutdown) {
|
||||
transfer.terminate();
|
||||
} else {
|
||||
transfer.abort(error.Abort);
|
||||
}
|
||||
self._transfer = null;
|
||||
}
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *Response, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *Response) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
pub fn getStatus(self: *const Response) u16 {
|
||||
return self._status;
|
||||
}
|
||||
@@ -203,6 +197,8 @@ pub const JsApi = struct {
|
||||
pub const name = "Response";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(Response.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(Response.init, .{});
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const js = @import("../../js/js.zig");
|
||||
|
||||
const log = @import("../../../log.zig");
|
||||
@@ -30,6 +29,7 @@ const Page = @import("../../Page.zig");
|
||||
const Session = @import("../../Session.zig");
|
||||
|
||||
const Node = @import("../Node.zig");
|
||||
const Blob = @import("../Blob.zig");
|
||||
const Event = @import("../Event.zig");
|
||||
const Headers = @import("Headers.zig");
|
||||
const EventTarget = @import("../EventTarget.zig");
|
||||
@@ -39,7 +39,6 @@ const Allocator = std.mem.Allocator;
|
||||
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
const XMLHttpRequest = @This();
|
||||
_rc: lp.RC(u8) = .{},
|
||||
_page: *Page,
|
||||
_proto: *XMLHttpRequestEventTarget,
|
||||
_arena: Allocator,
|
||||
@@ -89,18 +88,21 @@ const ResponseType = enum {
|
||||
pub fn init(page: *Page) !*XMLHttpRequest {
|
||||
const arena = try page.getArena(.{ .debug = "XMLHttpRequest" });
|
||||
errdefer page.releaseArena(arena);
|
||||
const xhr = try page._factory.xhrEventTarget(arena, XMLHttpRequest{
|
||||
return page._factory.xhrEventTarget(arena, XMLHttpRequest{
|
||||
._page = page,
|
||||
._arena = arena,
|
||||
._proto = undefined,
|
||||
._request_headers = try Headers.init(null, page),
|
||||
});
|
||||
return xhr;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *XMLHttpRequest, session: *Session) void {
|
||||
pub fn deinit(self: *XMLHttpRequest, shutdown: bool, session: *Session) void {
|
||||
if (self._transfer) |transfer| {
|
||||
transfer.abort(error.Abort);
|
||||
if (shutdown) {
|
||||
transfer.terminate();
|
||||
} else {
|
||||
transfer.abort(error.Abort);
|
||||
}
|
||||
self._transfer = null;
|
||||
}
|
||||
|
||||
@@ -136,14 +138,6 @@ pub fn deinit(self: *XMLHttpRequest, session: *Session) void {
|
||||
session.releaseArena(self._arena);
|
||||
}
|
||||
|
||||
pub fn releaseRef(self: *XMLHttpRequest, session: *Session) void {
|
||||
self._rc.release(self, session);
|
||||
}
|
||||
|
||||
pub fn acquireRef(self: *XMLHttpRequest) void {
|
||||
self._rc.acquire();
|
||||
}
|
||||
|
||||
fn asEventTarget(self: *XMLHttpRequest) *EventTarget {
|
||||
return self._proto._proto;
|
||||
}
|
||||
@@ -251,6 +245,8 @@ pub fn send(self: *XMLHttpRequest, body_: ?[]const u8) !void {
|
||||
.error_callback = httpErrorCallback,
|
||||
.shutdown_callback = httpShutdownCallback,
|
||||
});
|
||||
|
||||
page.js.strongRef(self);
|
||||
}
|
||||
|
||||
fn handleBlobUrl(self: *XMLHttpRequest, page: *Page) !void {
|
||||
@@ -392,7 +388,6 @@ fn httpStartCallback(transfer: *HttpClient.Transfer) !void {
|
||||
log.debug(.http, "request start", .{ .method = self._method, .url = self._url, .source = "xhr" });
|
||||
}
|
||||
self._transfer = transfer;
|
||||
self.acquireRef();
|
||||
}
|
||||
|
||||
fn httpHeaderCallback(transfer: *HttpClient.Transfer, header: net_http.Header) !void {
|
||||
@@ -491,17 +486,15 @@ fn httpDoneCallback(ctx: *anyopaque) !void {
|
||||
.loaded = loaded,
|
||||
}, page);
|
||||
|
||||
self.releaseRef(page._session);
|
||||
page.js.weakRef(self);
|
||||
}
|
||||
|
||||
fn httpErrorCallback(ctx: *anyopaque, err: anyerror) void {
|
||||
const self: *XMLHttpRequest = @ptrCast(@alignCast(ctx));
|
||||
// http client will close it after an error, it isn't safe to keep around
|
||||
self._transfer = null;
|
||||
self.handleError(err);
|
||||
if (self._transfer != null) {
|
||||
self._transfer = null;
|
||||
self.releaseRef(self._page._session);
|
||||
}
|
||||
self._page.js.weakRef(self);
|
||||
}
|
||||
|
||||
fn httpShutdownCallback(ctx: *anyopaque) void {
|
||||
@@ -512,10 +505,10 @@ fn httpShutdownCallback(ctx: *anyopaque) void {
|
||||
pub fn abort(self: *XMLHttpRequest) void {
|
||||
self.handleError(error.Abort);
|
||||
if (self._transfer) |transfer| {
|
||||
self._transfer = null;
|
||||
transfer.abort(error.Abort);
|
||||
self.releaseRef(self._page._session);
|
||||
self._transfer = null;
|
||||
}
|
||||
self._page.js.weakRef(self);
|
||||
}
|
||||
|
||||
fn handleError(self: *XMLHttpRequest, err: anyerror) void {
|
||||
@@ -589,6 +582,8 @@ pub const JsApi = struct {
|
||||
pub const name = "XMLHttpRequest";
|
||||
pub const prototype_chain = bridge.prototypeChain();
|
||||
pub var class_id: bridge.ClassId = undefined;
|
||||
pub const weak = true;
|
||||
pub const finalizer = bridge.finalizer(XMLHttpRequest.deinit);
|
||||
};
|
||||
|
||||
pub const constructor = bridge.constructor(XMLHttpRequest.init, .{});
|
||||
|
||||
@@ -25,6 +25,7 @@ const json = std.json;
|
||||
const Incrementing = @import("id.zig").Incrementing;
|
||||
|
||||
const log = @import("../log.zig");
|
||||
const App = @import("../App.zig");
|
||||
const Notification = @import("../Notification.zig");
|
||||
|
||||
const Client = @import("../Server.zig").Client;
|
||||
@@ -34,6 +35,7 @@ const Browser = @import("../browser/Browser.zig");
|
||||
const Session = @import("../browser/Session.zig");
|
||||
const Page = @import("../browser/Page.zig");
|
||||
const Mime = @import("../browser/Mime.zig");
|
||||
const HttpClient = @import("../browser/HttpClient.zig");
|
||||
|
||||
const InterceptState = @import("domains/fetch.zig").InterceptState;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const log = @import("../../log.zig");
|
||||
const markdown = lp.markdown;
|
||||
const SemanticTree = lp.SemanticTree;
|
||||
const interactive = lp.interactive;
|
||||
@@ -134,10 +135,17 @@ fn getInteractiveElements(cmd: anytype) !void {
|
||||
page.document.asNode();
|
||||
|
||||
const elements = try interactive.collectInteractiveElements(root, cmd.arena, page);
|
||||
try interactive.registerNodes(elements, &bc.node_registry);
|
||||
|
||||
// Register nodes so nodeIds are valid for subsequent CDP calls.
|
||||
var node_ids: std.ArrayList(Node.Id) = try .initCapacity(cmd.arena, elements.len);
|
||||
for (elements) |el| {
|
||||
const registered = try bc.node_registry.register(el.node);
|
||||
node_ids.appendAssumeCapacity(registered.id);
|
||||
}
|
||||
|
||||
return cmd.sendResult(.{
|
||||
.elements = elements,
|
||||
.nodeIds = node_ids.items,
|
||||
}, .{});
|
||||
}
|
||||
|
||||
@@ -300,6 +308,7 @@ test "cdp.lp: getInteractiveElements" {
|
||||
|
||||
const result = (try ctx.getSentMessage(0)).?.object.get("result").?.object;
|
||||
try testing.expect(result.get("elements") != null);
|
||||
try testing.expect(result.get("nodeIds") != null);
|
||||
}
|
||||
|
||||
test "cdp.lp: getStructuredData" {
|
||||
|
||||
@@ -24,6 +24,9 @@ const log = @import("../../log.zig");
|
||||
const URL = @import("../../browser/URL.zig");
|
||||
const js = @import("../../browser/js/js.zig");
|
||||
|
||||
// TODO: hard coded IDs
|
||||
const LOADER_ID = "LOADERID42AA389647D702B4D805F49A";
|
||||
|
||||
pub fn processMessage(cmd: anytype) !void {
|
||||
const action = std.meta.stringToEnum(enum {
|
||||
getTargets,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
pub fn toPageId(comptime id_type: enum { frame_id, loader_id }, input: []const u8) !u32 {
|
||||
const err = switch (comptime id_type) {
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
const std = @import("std");
|
||||
const json = std.json;
|
||||
const posix = std.posix;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
|
||||
const Testing = @This();
|
||||
|
||||
const CDP = @import("CDP.zig");
|
||||
const Server = @import("../Server.zig");
|
||||
|
||||
@@ -158,13 +158,13 @@ pub extern "C" fn html5ever_attribute_iterator_next(
|
||||
|
||||
let attr = &iter.vec[pos];
|
||||
iter.pos += 1;
|
||||
CNullable::<CAttribute>::some(CAttribute {
|
||||
return CNullable::<CAttribute>::some(CAttribute {
|
||||
name: CQualName::create(&attr.name),
|
||||
value: StringSlice {
|
||||
ptr: attr.value.as_ptr(),
|
||||
len: attr.value.len(),
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -186,12 +186,12 @@ pub extern "C" fn html5ever_get_memory_usage() -> Memory {
|
||||
use tikv_jemalloc_ctl::{epoch, stats};
|
||||
|
||||
// many statistics are cached and only updated when the epoch is advanced.
|
||||
drop(epoch::advance());
|
||||
epoch::advance().unwrap();
|
||||
|
||||
Memory {
|
||||
resident: stats::resident::read().unwrap_or(0),
|
||||
allocated: stats::allocated::read().unwrap_or(0),
|
||||
}
|
||||
return Memory {
|
||||
resident: stats::resident::read().unwrap(),
|
||||
allocated: stats::allocated::read().unwrap(),
|
||||
};
|
||||
}
|
||||
|
||||
// Streaming parser API
|
||||
@@ -325,7 +325,7 @@ pub extern "C" fn html5ever_streaming_parser_destroy(parser_ptr: *mut c_void) {
|
||||
// Drop the parser box without finishing
|
||||
// This is for cases where you want to cancel parsing
|
||||
unsafe {
|
||||
drop(Box::from_raw(parser_ptr as *mut StreamingParser));
|
||||
let _ = Box::from_raw(parser_ptr as *mut StreamingParser);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ pub struct ElementData {
|
||||
}
|
||||
impl ElementData {
|
||||
fn new(qname: QualName, flags: ElementFlags) -> Self {
|
||||
Self {
|
||||
return Self {
|
||||
qname: qname,
|
||||
mathml_annotation_xml_integration_point: flags.mathml_annotation_xml_integration_point,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,12 +130,12 @@ impl<'arena> TreeSink for Sink<'arena> {
|
||||
unsafe {
|
||||
let mut attribute_iterator = CAttributeIterator { vec: attrs, pos: 0 };
|
||||
|
||||
(self.create_element_callback)(
|
||||
return (self.create_element_callback)(
|
||||
self.ctx,
|
||||
data as *mut _ as *mut c_void,
|
||||
CQualName::create(&name),
|
||||
&mut attribute_iterator as *mut _ as *mut c_void,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,21 +126,21 @@ impl CQualName {
|
||||
None => CNullable::<StringSlice>::none(),
|
||||
Some(prefix) => CNullable::<StringSlice>::some(StringSlice { ptr: prefix.as_ptr(), len: prefix.len()}),
|
||||
};
|
||||
CQualName{
|
||||
return CQualName{
|
||||
// inner: q as *const _ as *const c_void,
|
||||
ns: ns,
|
||||
local: local,
|
||||
prefix: prefix,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
impl Default for CQualName {
|
||||
fn default() -> Self {
|
||||
Self{
|
||||
return Self{
|
||||
prefix: CNullable::<StringSlice>::none(),
|
||||
ns: StringSlice::default(),
|
||||
local: StringSlice::default(),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ pub const markdown = @import("browser/markdown.zig");
|
||||
pub const SemanticTree = @import("SemanticTree.zig");
|
||||
pub const CDPNode = @import("cdp/Node.zig");
|
||||
pub const interactive = @import("browser/interactive.zig");
|
||||
pub const links = @import("browser/links.zig");
|
||||
pub const forms = @import("browser/forms.zig");
|
||||
pub const actions = @import("browser/actions.zig");
|
||||
pub const structured_data = @import("browser/structured_data.zig");
|
||||
@@ -209,37 +208,6 @@ noinline fn assertionFailure(comptime ctx: []const u8, args: anytype) noreturn {
|
||||
@import("crash_handler.zig").crash(ctx, args, @returnAddress());
|
||||
}
|
||||
|
||||
// Reference counting helper
|
||||
pub fn RC(comptime T: type) type {
|
||||
return struct {
|
||||
_refs: T = 0,
|
||||
|
||||
pub fn init(refs: T) @This() {
|
||||
return .{ ._refs = refs };
|
||||
}
|
||||
|
||||
pub fn acquire(self: *@This()) void {
|
||||
self._refs += 1;
|
||||
}
|
||||
|
||||
pub fn release(self: *@This(), value: anytype, session: *Session) void {
|
||||
if (comptime IS_DEBUG) {
|
||||
std.debug.assert(self._refs > 0);
|
||||
}
|
||||
|
||||
const refs = self._refs - 1;
|
||||
self._refs = refs;
|
||||
if (refs > 0) {
|
||||
return;
|
||||
}
|
||||
value.deinit(session);
|
||||
if (session.finalizer_callbacks.fetchRemove(@intFromPtr(value))) |kv| {
|
||||
session.releaseArena(kv.value.arena);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test {
|
||||
std.testing.refAllDecls(@This());
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ const Opts = struct {
|
||||
|
||||
pub var opts = Opts{};
|
||||
|
||||
// synchronizes writes to the output
|
||||
var out_lock: Thread.Mutex = .{};
|
||||
|
||||
// synchronizes access to last_log
|
||||
var last_log_lock: Thread.Mutex = .{};
|
||||
|
||||
|
||||
@@ -22,14 +22,12 @@ pub const resource_list = [_]protocol.Resource{
|
||||
};
|
||||
|
||||
pub fn handleList(server: *Server, req: protocol.Request) !void {
|
||||
const id = req.id orelse return;
|
||||
try server.sendResult(id, .{ .resources = &resource_list });
|
||||
try server.sendResult(req.id.?, .{ .resources = &resource_list });
|
||||
}
|
||||
|
||||
const ReadParams = struct {
|
||||
uri: []const u8,
|
||||
};
|
||||
const Format = enum { html, markdown };
|
||||
|
||||
const ResourceStreamingResult = struct {
|
||||
contents: []const struct {
|
||||
@@ -40,7 +38,7 @@ const ResourceStreamingResult = struct {
|
||||
|
||||
const StreamingText = struct {
|
||||
page: *lp.Page,
|
||||
format: Format,
|
||||
format: enum { html, markdown },
|
||||
|
||||
pub fn jsonStringify(self: @This(), jw: *std.json.Stringify) !void {
|
||||
try jw.beginWriteRaw();
|
||||
@@ -49,11 +47,9 @@ const ResourceStreamingResult = struct {
|
||||
switch (self.format) {
|
||||
.html => lp.dump.root(self.page.document, .{}, &escaped.writer, self.page) catch |err| {
|
||||
log.err(.mcp, "html dump failed", .{ .err = err });
|
||||
return error.WriteFailed;
|
||||
},
|
||||
.markdown => lp.markdown.dump(self.page.document.asNode(), .{}, &escaped.writer, self.page) catch |err| {
|
||||
log.err(.mcp, "markdown dump failed", .{ .err = err });
|
||||
return error.WriteFailed;
|
||||
},
|
||||
}
|
||||
try jw.writer.writeByte('"');
|
||||
@@ -90,23 +86,28 @@ pub fn handleRead(server: *Server, arena: std.mem.Allocator, req: protocol.Reque
|
||||
return server.sendError(req_id, .PageNotLoaded, "Page not loaded");
|
||||
};
|
||||
|
||||
const format: Format = switch (uri) {
|
||||
.@"mcp://page/html" => .html,
|
||||
.@"mcp://page/markdown" => .markdown,
|
||||
};
|
||||
const mime_type: []const u8 = switch (uri) {
|
||||
.@"mcp://page/html" => "text/html",
|
||||
.@"mcp://page/markdown" => "text/markdown",
|
||||
};
|
||||
|
||||
const result: ResourceStreamingResult = .{
|
||||
.contents = &.{.{
|
||||
.uri = params.uri,
|
||||
.mimeType = mime_type,
|
||||
.text = .{ .page = page, .format = format },
|
||||
}},
|
||||
};
|
||||
server.sendResult(req_id, result) catch {
|
||||
return server.sendError(req_id, .InternalError, "Failed to serialize resource content");
|
||||
};
|
||||
switch (uri) {
|
||||
.@"mcp://page/html" => {
|
||||
const result: ResourceStreamingResult = .{
|
||||
.contents = &.{.{
|
||||
.uri = params.uri,
|
||||
.mimeType = "text/html",
|
||||
.text = .{ .page = page, .format = .html },
|
||||
}},
|
||||
};
|
||||
try server.sendResult(req_id, result);
|
||||
},
|
||||
.@"mcp://page/markdown" => {
|
||||
const result: ResourceStreamingResult = .{
|
||||
.contents = &.{.{
|
||||
.uri = params.uri,
|
||||
.mimeType = "text/markdown",
|
||||
.text = .{ .page = page, .format = .markdown },
|
||||
}},
|
||||
};
|
||||
try server.sendResult(req_id, result);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const testing = @import("../testing.zig");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const lp = @import("lightpanda");
|
||||
const protocol = @import("protocol.zig");
|
||||
const resources = @import("resources.zig");
|
||||
const Server = @import("Server.zig");
|
||||
@@ -15,7 +16,6 @@ pub fn processRequests(server: *Server, reader: *std.io.Reader) !void {
|
||||
const buffered_line = reader.takeDelimiter('\n') catch |err| switch (err) {
|
||||
error.StreamTooLong => {
|
||||
log.err(.mcp, "Message too long", .{});
|
||||
try server.sendError(.null, .InvalidRequest, "Message too long");
|
||||
continue;
|
||||
},
|
||||
else => return err,
|
||||
@@ -80,7 +80,6 @@ pub fn handleMessage(server: *Server, arena: std.mem.Allocator, msg: []const u8)
|
||||
}
|
||||
|
||||
fn handleInitialize(server: *Server, req: protocol.Request) !void {
|
||||
const id = req.id orelse return;
|
||||
const result = protocol.InitializeResult{
|
||||
.protocolVersion = "2025-11-25",
|
||||
.capabilities = .{
|
||||
@@ -93,7 +92,7 @@ fn handleInitialize(server: *Server, req: protocol.Request) !void {
|
||||
},
|
||||
};
|
||||
|
||||
try server.sendResult(id, result);
|
||||
try server.sendResult(req.id.?, result);
|
||||
}
|
||||
|
||||
fn handlePing(server: *Server, req: protocol.Request) !void {
|
||||
|
||||
@@ -4,7 +4,9 @@ const lp = @import("lightpanda");
|
||||
const log = lp.log;
|
||||
const js = lp.js;
|
||||
|
||||
const Element = @import("../browser/webapi/Element.zig");
|
||||
const DOMNode = @import("../browser/webapi/Node.zig");
|
||||
const Selector = @import("../browser/webapi/selector/Selector.zig");
|
||||
const protocol = @import("protocol.zig");
|
||||
const Server = @import("Server.zig");
|
||||
const CDPNode = @import("../cdp/Node.zig");
|
||||
@@ -170,18 +172,13 @@ pub const tool_list = [_]protocol.Tool{
|
||||
|
||||
pub fn handleList(server: *Server, arena: std.mem.Allocator, req: protocol.Request) !void {
|
||||
_ = arena;
|
||||
const id = req.id orelse return;
|
||||
try server.sendResult(id, .{ .tools = &tool_list });
|
||||
try server.sendResult(req.id.?, .{ .tools = &tool_list });
|
||||
}
|
||||
|
||||
const GotoParams = struct {
|
||||
url: [:0]const u8,
|
||||
};
|
||||
|
||||
const UrlParams = struct {
|
||||
url: ?[:0]const u8 = null,
|
||||
};
|
||||
|
||||
const EvaluateParams = struct {
|
||||
script: [:0]const u8,
|
||||
url: ?[:0]const u8 = null,
|
||||
@@ -204,18 +201,28 @@ const ToolStreamingText = struct {
|
||||
switch (self.action) {
|
||||
.markdown => lp.markdown.dump(self.page.document.asNode(), .{}, w, self.page) catch |err| {
|
||||
log.err(.mcp, "markdown dump failed", .{ .err = err });
|
||||
return error.WriteFailed;
|
||||
},
|
||||
.links => {
|
||||
const links = lp.links.collectLinks(self.page.call_arena, self.page.document.asNode(), self.page) catch |err| {
|
||||
if (Selector.querySelectorAll(self.page.document.asNode(), "a[href]", self.page)) |list| {
|
||||
defer list.deinit(self.page._session);
|
||||
|
||||
var first = true;
|
||||
for (list._nodes) |node| {
|
||||
if (node.is(Element.Html.Anchor)) |anchor| {
|
||||
const href = anchor.getHref(self.page) catch |err| {
|
||||
log.err(.mcp, "resolve href failed", .{ .err = err });
|
||||
continue;
|
||||
};
|
||||
|
||||
if (href.len > 0) {
|
||||
if (!first) try w.writeByte('\n');
|
||||
try w.writeAll(href);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else |err| {
|
||||
log.err(.mcp, "query links failed", .{ .err = err });
|
||||
return error.WriteFailed;
|
||||
};
|
||||
var first = true;
|
||||
for (links) |href| {
|
||||
if (!first) try w.writeByte('\n');
|
||||
try w.writeAll(href);
|
||||
first = false;
|
||||
}
|
||||
},
|
||||
.semantic_tree => {
|
||||
@@ -241,7 +248,6 @@ const ToolStreamingText = struct {
|
||||
|
||||
st.textStringify(w) catch |err| {
|
||||
log.err(.mcp, "semantic tree dump failed", .{ .err = err });
|
||||
return error.WriteFailed;
|
||||
};
|
||||
},
|
||||
}
|
||||
@@ -318,7 +324,7 @@ pub fn handleCall(server: *Server, arena: std.mem.Allocator, req: protocol.Reque
|
||||
}
|
||||
|
||||
fn handleGoto(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
const args = try parseArgs(GotoParams, arena, arguments, server, id, "goto");
|
||||
const args = try parseArguments(GotoParams, arena, arguments, server, id, "goto");
|
||||
try performGoto(server, args.url, id);
|
||||
|
||||
const content = [_]protocol.TextContent([]const u8){.{ .text = "Navigated successfully." }};
|
||||
@@ -326,27 +332,45 @@ fn handleGoto(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arg
|
||||
}
|
||||
|
||||
fn handleMarkdown(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
const args = try parseArgsOrDefault(UrlParams, arena, arguments, server, id);
|
||||
const page = try ensurePage(server, id, args.url);
|
||||
const MarkdownParams = struct {
|
||||
url: ?[:0]const u8 = null,
|
||||
};
|
||||
if (arguments) |args_raw| {
|
||||
if (std.json.parseFromValueLeaky(MarkdownParams, arena, args_raw, .{ .ignore_unknown_fields = true })) |args| {
|
||||
if (args.url) |u| {
|
||||
try performGoto(server, u, id);
|
||||
}
|
||||
} else |_| {}
|
||||
}
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
};
|
||||
|
||||
const content = [_]protocol.TextContent(ToolStreamingText){.{
|
||||
.text = .{ .page = page, .action = .markdown },
|
||||
}};
|
||||
server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content }) catch {
|
||||
return server.sendError(id, .InternalError, "Failed to serialize markdown content");
|
||||
};
|
||||
try server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content });
|
||||
}
|
||||
|
||||
fn handleLinks(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
const args = try parseArgsOrDefault(UrlParams, arena, arguments, server, id);
|
||||
const page = try ensurePage(server, id, args.url);
|
||||
const LinksParams = struct {
|
||||
url: ?[:0]const u8 = null,
|
||||
};
|
||||
if (arguments) |args_raw| {
|
||||
if (std.json.parseFromValueLeaky(LinksParams, arena, args_raw, .{ .ignore_unknown_fields = true })) |args| {
|
||||
if (args.url) |u| {
|
||||
try performGoto(server, u, id);
|
||||
}
|
||||
} else |_| {}
|
||||
}
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
};
|
||||
|
||||
const content = [_]protocol.TextContent(ToolStreamingText){.{
|
||||
.text = .{ .page = page, .action = .links },
|
||||
}};
|
||||
server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content }) catch {
|
||||
return server.sendError(id, .InternalError, "Failed to serialize links content");
|
||||
};
|
||||
try server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content });
|
||||
}
|
||||
|
||||
fn handleSemanticTree(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
@@ -355,38 +379,44 @@ fn handleSemanticTree(server: *Server, arena: std.mem.Allocator, id: std.json.Va
|
||||
backendNodeId: ?u32 = null,
|
||||
maxDepth: ?u32 = null,
|
||||
};
|
||||
const args = try parseArgsOrDefault(TreeParams, arena, arguments, server, id);
|
||||
const page = try ensurePage(server, id, args.url);
|
||||
var tree_args: TreeParams = .{};
|
||||
if (arguments) |args_raw| {
|
||||
if (std.json.parseFromValueLeaky(TreeParams, arena, args_raw, .{ .ignore_unknown_fields = true })) |args| {
|
||||
tree_args = args;
|
||||
if (args.url) |u| {
|
||||
try performGoto(server, u, id);
|
||||
}
|
||||
} else |_| {}
|
||||
}
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
};
|
||||
|
||||
const content = [_]protocol.TextContent(ToolStreamingText){.{
|
||||
.text = .{
|
||||
.page = page,
|
||||
.action = .semantic_tree,
|
||||
.registry = &server.node_registry,
|
||||
.arena = arena,
|
||||
.backendNodeId = args.backendNodeId,
|
||||
.maxDepth = args.maxDepth,
|
||||
},
|
||||
.text = .{ .page = page, .action = .semantic_tree, .registry = &server.node_registry, .arena = arena, .backendNodeId = tree_args.backendNodeId, .maxDepth = tree_args.maxDepth },
|
||||
}};
|
||||
server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content }) catch {
|
||||
return server.sendError(id, .InternalError, "Failed to serialize semantic tree content");
|
||||
};
|
||||
try server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content });
|
||||
}
|
||||
|
||||
fn handleInteractiveElements(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
const args = try parseArgsOrDefault(UrlParams, arena, arguments, server, id);
|
||||
const page = try ensurePage(server, id, args.url);
|
||||
const Params = struct {
|
||||
url: ?[:0]const u8 = null,
|
||||
};
|
||||
if (arguments) |args_raw| {
|
||||
if (std.json.parseFromValueLeaky(Params, arena, args_raw, .{ .ignore_unknown_fields = true })) |args| {
|
||||
if (args.url) |u| {
|
||||
try performGoto(server, u, id);
|
||||
}
|
||||
} else |_| {}
|
||||
}
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
};
|
||||
|
||||
const elements = lp.interactive.collectInteractiveElements(page.document.asNode(), arena, page) catch |err| {
|
||||
log.err(.mcp, "elements collection failed", .{ .err = err });
|
||||
return server.sendError(id, .InternalError, "Failed to collect interactive elements");
|
||||
};
|
||||
|
||||
lp.interactive.registerNodes(elements, &server.node_registry) catch |err| {
|
||||
log.err(.mcp, "node registration failed", .{ .err = err });
|
||||
return server.sendError(id, .InternalError, "Failed to register element nodes");
|
||||
};
|
||||
|
||||
var aw: std.Io.Writer.Allocating = .init(arena);
|
||||
try std.json.Stringify.value(elements, .{}, &aw.writer);
|
||||
|
||||
@@ -395,8 +425,19 @@ fn handleInteractiveElements(server: *Server, arena: std.mem.Allocator, id: std.
|
||||
}
|
||||
|
||||
fn handleStructuredData(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
const args = try parseArgsOrDefault(UrlParams, arena, arguments, server, id);
|
||||
const page = try ensurePage(server, id, args.url);
|
||||
const Params = struct {
|
||||
url: ?[:0]const u8 = null,
|
||||
};
|
||||
if (arguments) |args_raw| {
|
||||
if (std.json.parseFromValueLeaky(Params, arena, args_raw, .{ .ignore_unknown_fields = true })) |args| {
|
||||
if (args.url) |u| {
|
||||
try performGoto(server, u, id);
|
||||
}
|
||||
} else |_| {}
|
||||
}
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
};
|
||||
|
||||
const data = lp.structured_data.collectStructuredData(page.document.asNode(), arena, page) catch |err| {
|
||||
log.err(.mcp, "struct data collection failed", .{ .err = err });
|
||||
@@ -410,8 +451,20 @@ fn handleStructuredData(server: *Server, arena: std.mem.Allocator, id: std.json.
|
||||
}
|
||||
|
||||
fn handleDetectForms(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
const args = try parseArgsOrDefault(UrlParams, arena, arguments, server, id);
|
||||
const page = try ensurePage(server, id, args.url);
|
||||
const Params = struct {
|
||||
url: ?[:0]const u8 = null,
|
||||
};
|
||||
if (arguments) |args_raw| {
|
||||
const args = std.json.parseFromValueLeaky(Params, arena, args_raw, .{ .ignore_unknown_fields = true }) catch {
|
||||
return server.sendError(id, .InvalidParams, "Invalid arguments for detectForms");
|
||||
};
|
||||
if (args.url) |u| {
|
||||
try performGoto(server, u, id);
|
||||
}
|
||||
}
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
};
|
||||
|
||||
const forms_data = lp.forms.collectForms(arena, page.document.asNode(), page) catch |err| {
|
||||
log.err(.mcp, "form collection failed", .{ .err = err });
|
||||
@@ -431,8 +484,14 @@ fn handleDetectForms(server: *Server, arena: std.mem.Allocator, id: std.json.Val
|
||||
}
|
||||
|
||||
fn handleEvaluate(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
const args = try parseArgs(EvaluateParams, arena, arguments, server, id, "evaluate");
|
||||
const page = try ensurePage(server, id, args.url);
|
||||
const args = try parseArguments(EvaluateParams, arena, arguments, server, id, "evaluate");
|
||||
|
||||
if (args.url) |url| {
|
||||
try performGoto(server, url, id);
|
||||
}
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
};
|
||||
|
||||
var ls: js.Local.Scope = undefined;
|
||||
page.js.localScope(&ls);
|
||||
@@ -461,7 +520,7 @@ fn handleClick(server: *Server, arena: std.mem.Allocator, id: std.json.Value, ar
|
||||
const ClickParams = struct {
|
||||
backendNodeId: CDPNode.Id,
|
||||
};
|
||||
const args = try parseArgs(ClickParams, arena, arguments, server, id, "click");
|
||||
const args = try parseArguments(ClickParams, arena, arguments, server, id, "click");
|
||||
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
@@ -493,7 +552,7 @@ fn handleFill(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arg
|
||||
backendNodeId: CDPNode.Id,
|
||||
text: []const u8,
|
||||
};
|
||||
const args = try parseArgs(FillParams, arena, arguments, server, id, "fill");
|
||||
const args = try parseArguments(FillParams, arena, arguments, server, id, "fill");
|
||||
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
@@ -527,7 +586,7 @@ fn handleScroll(server: *Server, arena: std.mem.Allocator, id: std.json.Value, a
|
||||
x: ?i32 = null,
|
||||
y: ?i32 = null,
|
||||
};
|
||||
const args = try parseArgs(ScrollParams, arena, arguments, server, id, "scroll");
|
||||
const args = try parseArguments(ScrollParams, arena, arguments, server, id, "scroll");
|
||||
|
||||
const page = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
@@ -564,7 +623,7 @@ fn handleWaitForSelector(server: *Server, arena: std.mem.Allocator, id: std.json
|
||||
selector: [:0]const u8,
|
||||
timeout: ?u32 = null,
|
||||
};
|
||||
const args = try parseArgs(WaitParams, arena, arguments, server, id, "waitForSelector");
|
||||
const args = try parseArguments(WaitParams, arena, arguments, server, id, "waitForSelector");
|
||||
|
||||
_ = server.session.currentPage() orelse {
|
||||
return server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
@@ -588,38 +647,12 @@ fn handleWaitForSelector(server: *Server, arena: std.mem.Allocator, id: std.json
|
||||
return server.sendResult(id, protocol.CallToolResult([]const u8){ .content = &content });
|
||||
}
|
||||
|
||||
fn ensurePage(server: *Server, id: std.json.Value, url: ?[:0]const u8) !*lp.Page {
|
||||
if (url) |u| {
|
||||
try performGoto(server, u, id);
|
||||
}
|
||||
return server.session.currentPage() orelse {
|
||||
try server.sendError(id, .PageNotLoaded, "Page not loaded");
|
||||
return error.PageNotLoaded;
|
||||
};
|
||||
}
|
||||
|
||||
/// Parses JSON arguments into a given struct type `T`.
|
||||
/// If the arguments are missing, it returns a default-initialized `T` (e.g., `.{}`).
|
||||
/// If the arguments are present but invalid, it sends an MCP error response and returns `error.InvalidParams`.
|
||||
/// Use this for tools where all arguments are optional.
|
||||
fn parseArgsOrDefault(comptime T: type, arena: std.mem.Allocator, arguments: ?std.json.Value, server: *Server, id: std.json.Value) !T {
|
||||
const args_raw = arguments orelse return .{};
|
||||
return std.json.parseFromValueLeaky(T, arena, args_raw, .{ .ignore_unknown_fields = true }) catch {
|
||||
try server.sendError(id, .InvalidParams, "Invalid arguments");
|
||||
return error.InvalidParams;
|
||||
};
|
||||
}
|
||||
|
||||
/// Parses JSON arguments into a given struct type `T`.
|
||||
/// If the arguments are missing or invalid, it automatically sends an MCP error response to the client
|
||||
/// and returns an `error.InvalidParams`.
|
||||
/// Use this for tools that require strict validation or mandatory arguments.
|
||||
fn parseArgs(comptime T: type, arena: std.mem.Allocator, arguments: ?std.json.Value, server: *Server, id: std.json.Value, tool_name: []const u8) !T {
|
||||
const args_raw = arguments orelse {
|
||||
fn parseArguments(comptime T: type, arena: std.mem.Allocator, arguments: ?std.json.Value, server: *Server, id: std.json.Value, tool_name: []const u8) !T {
|
||||
if (arguments == null) {
|
||||
try server.sendError(id, .InvalidParams, "Missing arguments");
|
||||
return error.InvalidParams;
|
||||
};
|
||||
return std.json.parseFromValueLeaky(T, arena, args_raw, .{ .ignore_unknown_fields = true }) catch {
|
||||
}
|
||||
return std.json.parseFromValueLeaky(T, arena, arguments.?, .{ .ignore_unknown_fields = true }) catch {
|
||||
const msg = std.fmt.allocPrint(arena, "Invalid arguments for {s}", .{tool_name}) catch "Invalid arguments";
|
||||
try server.sendError(id, .InvalidParams, msg);
|
||||
return error.InvalidParams;
|
||||
@@ -631,10 +664,7 @@ fn performGoto(server: *Server, url: [:0]const u8, id: std.json.Value) !void {
|
||||
if (session.page != null) {
|
||||
session.removePage();
|
||||
}
|
||||
const page = session.createPage() catch {
|
||||
try server.sendError(id, .InternalError, "Failed to create page");
|
||||
return error.NavigationFailed;
|
||||
};
|
||||
const page = try session.createPage();
|
||||
page.navigate(url, .{
|
||||
.reason = .address_bar,
|
||||
.kind = .{ .push = null },
|
||||
@@ -643,14 +673,8 @@ fn performGoto(server: *Server, url: [:0]const u8, id: std.json.Value) !void {
|
||||
return error.NavigationFailed;
|
||||
};
|
||||
|
||||
var runner = session.runner(.{}) catch {
|
||||
try server.sendError(id, .InternalError, "Failed to start page runner");
|
||||
return error.NavigationFailed;
|
||||
};
|
||||
runner.wait(.{ .ms = 2000 }) catch {
|
||||
try server.sendError(id, .InternalError, "Timeout waiting for page load");
|
||||
return error.NavigationFailed;
|
||||
};
|
||||
var runner = try session.runner(.{});
|
||||
try runner.wait(.{ .ms = 2000 });
|
||||
}
|
||||
|
||||
const router = @import("router.zig");
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const posix = std.posix;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
|
||||
const Config = @import("../Config.zig");
|
||||
const libcurl = @import("../sys/libcurl.zig");
|
||||
@@ -25,12 +29,18 @@ const log = @import("lightpanda").log;
|
||||
const assert = @import("lightpanda").assert;
|
||||
|
||||
pub const ENABLE_DEBUG = false;
|
||||
const IS_DEBUG = builtin.mode == .Debug;
|
||||
|
||||
pub const Blob = libcurl.CurlBlob;
|
||||
pub const WaitFd = libcurl.CurlWaitFd;
|
||||
pub const writefunc_error = libcurl.curl_writefunc_error;
|
||||
|
||||
const Error = libcurl.Error;
|
||||
const ErrorMulti = libcurl.ErrorMulti;
|
||||
const errorFromCode = libcurl.errorFromCode;
|
||||
const errorMFromCode = libcurl.errorMFromCode;
|
||||
const errorCheck = libcurl.errorCheck;
|
||||
const errorMCheck = libcurl.errorMCheck;
|
||||
|
||||
pub fn curl_version() [*c]const u8 {
|
||||
return libcurl.curl_version();
|
||||
|
||||
@@ -9,6 +9,7 @@ const App = @import("../App.zig");
|
||||
const Config = @import("../Config.zig");
|
||||
const telemetry = @import("telemetry.zig");
|
||||
const Runtime = @import("../network/Runtime.zig");
|
||||
const Connection = @import("../network/http.zig").Connection;
|
||||
|
||||
const URL = "https://telemetry.lightpanda.io";
|
||||
const BUFFER_SIZE = 1024;
|
||||
|
||||
Reference in New Issue
Block a user