Merge pull request #543 from lightpanda-io/describeNode2

descibeNode for new js runtime
This commit is contained in:
Pierre Tachoire
2025-04-22 13:57:18 +02:00
committed by GitHub
6 changed files with 51 additions and 12 deletions

View File

@@ -17,7 +17,7 @@ inputs:
zig-v8: zig-v8:
description: 'zig v8 version to install' description: 'zig v8 version to install'
required: false required: false
default: 'v0.1.17' default: 'v0.1.18'
v8: v8:
description: 'v8 version to install' description: 'v8 version to install'
required: false required: false

View File

@@ -5,7 +5,7 @@ ARG ZIG=0.14.0
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
ARG ARCH=x86_64 ARG ARCH=x86_64
ARG V8=11.1.134 ARG V8=11.1.134
ARG ZIG_V8=v0.1.16 ARG ZIG_V8=v0.1.18
RUN apt-get update -yq && \ RUN apt-get update -yq && \
apt-get install -yq xz-utils \ apt-get install -yq xz-utils \
@@ -51,10 +51,6 @@ WORKDIR /browser
RUN git submodule init && \ RUN git submodule init && \
git submodule update --recursive git submodule update --recursive
RUN cd vendor/zig-js-runtime && \
git submodule init && \
git submodule update --recursive
RUN make install-libiconv && \ RUN make install-libiconv && \
make install-netsurf && \ make install-netsurf && \
make install-mimalloc make install-mimalloc

View File

@@ -13,8 +13,8 @@
.hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd", .hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd",
}, },
.v8 = .{ .v8 = .{
.url = "https://github.com/karlseguin/zig-v8-fork/archive/e5f1c0c9f1ed147617427f22cdaf11df4ab60b79.tar.gz", .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/5790c80fcd12dec64e596f6f66f09de567020e8a.tar.gz",
.hash = "v8-0.0.0-xddH61vYIACI2pT1t-dUbXm18cHAKy-KWT_Qft4sBwam", .hash = "v8-0.0.0-xddH66roIAAdXNJpBKN_NO8zBz2H8b9moUzshBCfns2p",
}, },
//.v8 = .{ .path = "../zig-v8-fork" }, //.v8 = .{ .path = "../zig-v8-fork" },
//.tigerbeetle_io = .{ .path = "../tigerbeetle-io" }, //.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },

View File

@@ -30,6 +30,7 @@ pub fn processMessage(cmd: anytype) !void {
getSearchResults, getSearchResults,
discardSearchResults, discardSearchResults,
resolveNode, resolveNode,
describeNode,
}, cmd.input.action) orelse return error.UnknownMethod; }, cmd.input.action) orelse return error.UnknownMethod;
switch (action) { switch (action) {
@@ -39,6 +40,7 @@ pub fn processMessage(cmd: anytype) !void {
.getSearchResults => return getSearchResults(cmd), .getSearchResults => return getSearchResults(cmd),
.discardSearchResults => return discardSearchResults(cmd), .discardSearchResults => return discardSearchResults(cmd),
.resolveNode => return resolveNode(cmd), .resolveNode => return resolveNode(cmd),
.describeNode => return describeNode(cmd),
} }
} }
@@ -151,6 +153,33 @@ fn resolveNode(cmd: anytype) !void {
} }, .{}); } }, .{});
} }
fn describeNode(cmd: anytype) !void {
const params = (try cmd.params(struct {
nodeId: ?Node.Id = null,
backendNodeId: ?Node.Id = null,
objectId: ?[]const u8 = null,
depth: u32 = 1,
pierce: bool = false,
})) orelse return error.InvalidParams;
if (params.backendNodeId != null or params.depth != 1 or params.pierce) {
return error.NotYetImplementedParams;
}
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
if (params.nodeId != null) {
const node = bc.node_registry.lookup_by_id.get(params.nodeId.?) orelse return error.NodeNotFound;
return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{});
}
if (params.objectId != null) {
// Retrieve the object from which ever context it is in.
const parser_node = try bc.session.inspector.getNodePtr(cmd.arena, params.objectId.?);
const node = try bc.node_registry.register(@ptrCast(parser_node));
return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{});
}
return error.MissingParams;
}
const testing = @import("../testing.zig"); const testing = @import("../testing.zig");
test "cdp.dom: getSearchResults unknown search id" { test "cdp.dom: getSearchResults unknown search id" {

View File

@@ -55,13 +55,13 @@ const Browser = struct {
if (self.session != null) { if (self.session != null) {
return error.MockBrowserSessionAlreadyExists; return error.MockBrowserSessionAlreadyExists;
} }
const arena = self.arena.allocator(); const arena = self.arena.allocator();
const executor = arena.create(Executor) catch unreachable;
self.session = try arena.create(Session); self.session = try arena.create(Session);
self.session.?.* = .{ self.session.?.* = .{
.page = null, .page = null,
.arena = arena, .arena = arena,
.executor = .{}, .executor = executor,
.inspector = .{}, .inspector = .{},
}; };
return self.session.?; return self.session.?;
@@ -78,7 +78,7 @@ const Browser = struct {
const Session = struct { const Session = struct {
page: ?Page = null, page: ?Page = null,
arena: Allocator, arena: Allocator,
executor: Executor, executor: *Executor,
inspector: Inspector, inspector: Inspector,
pub fn currentPage(self: *Session) ?*Page { pub fn currentPage(self: *Session) ?*Page {
@@ -112,7 +112,7 @@ const Executor = struct {};
const Inspector = struct { const Inspector = struct {
pub fn getRemoteObject( pub fn getRemoteObject(
self: *const Inspector, self: *const Inspector,
executor: Executor, executor: *Executor,
group: []const u8, group: []const u8,
value: anytype, value: anytype,
) !RemoteObject { ) !RemoteObject {
@@ -122,6 +122,11 @@ const Inspector = struct {
_ = value; _ = value;
return RemoteObject{}; return RemoteObject{};
} }
pub fn getNodePtr(self: Inspector, alloc: std.mem.Allocator, object_id: []const u8) !?*anyopaque {
_ = self;
_ = object_id;
return try alloc.create(i32);
}
}; };
const RemoteObject = struct { const RemoteObject = struct {

View File

@@ -1369,6 +1369,15 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
generate_preview, generate_preview,
); );
} }
// Gets a value by object ID regardless of which context it is in.
pub fn getNodePtr(self: *const Inspector, allocator: Allocator, object_id: []const u8) !?*anyopaque {
const unwrapped = try self.session.unwrapObject(allocator, object_id);
// The values context and groupId are not used here
const toa = getTaggedAnyOpaque(unwrapped.value) orelse return null;
if (toa.subtype == null or toa.subtype != .node) return error.ObjectIdIsNotANode;
return toa.ptr;
}
}; };
pub const RemoteObject = v8.RemoteObject; pub const RemoteObject = v8.RemoteObject;