Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inputs:
zig-v8:
description: 'zig v8 version to install'
required: false
default: 'v0.1.17'
default: 'v0.1.18'
v8:
description: 'v8 version to install'
required: false
Expand Down
6 changes: 1 addition & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG ZIG=0.14.0
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
ARG ARCH=x86_64
ARG V8=11.1.134
ARG ZIG_V8=v0.1.16
ARG ZIG_V8=v0.1.18

RUN apt-get update -yq && \
apt-get install -yq xz-utils \
Expand Down Expand Up @@ -51,10 +51,6 @@ WORKDIR /browser
RUN git submodule init && \
git submodule update --recursive

RUN cd vendor/zig-js-runtime && \
git submodule init && \
git submodule update --recursive

RUN make install-libiconv && \
make install-netsurf && \
make install-mimalloc
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
.hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd",
},
.v8 = .{
.url = "https://github.com/karlseguin/zig-v8-fork/archive/e5f1c0c9f1ed147617427f22cdaf11df4ab60b79.tar.gz",
.hash = "v8-0.0.0-xddH61vYIACI2pT1t-dUbXm18cHAKy-KWT_Qft4sBwam",
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/5790c80fcd12dec64e596f6f66f09de567020e8a.tar.gz",
.hash = "v8-0.0.0-xddH66roIAAdXNJpBKN_NO8zBz2H8b9moUzshBCfns2p",
},
//.v8 = .{ .path = "../zig-v8-fork" },
//.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },
Expand Down
29 changes: 29 additions & 0 deletions src/cdp/domains/dom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn processMessage(cmd: anytype) !void {
getSearchResults,
discardSearchResults,
resolveNode,
describeNode,
}, cmd.input.action) orelse return error.UnknownMethod;

switch (action) {
Expand All @@ -39,6 +40,7 @@ pub fn processMessage(cmd: anytype) !void {
.getSearchResults => return getSearchResults(cmd),
.discardSearchResults => return discardSearchResults(cmd),
.resolveNode => return resolveNode(cmd),
.describeNode => return describeNode(cmd),
}
}

Expand Down Expand Up @@ -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");

test "cdp.dom: getSearchResults unknown search id" {
Expand Down
13 changes: 9 additions & 4 deletions src/cdp/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ const Browser = struct {
if (self.session != null) {
return error.MockBrowserSessionAlreadyExists;
}

const arena = self.arena.allocator();
const executor = arena.create(Executor) catch unreachable;
self.session = try arena.create(Session);
self.session.?.* = .{
.page = null,
.arena = arena,
.executor = .{},
.executor = executor,
.inspector = .{},
};
return self.session.?;
Expand All @@ -78,7 +78,7 @@ const Browser = struct {
const Session = struct {
page: ?Page = null,
arena: Allocator,
executor: Executor,
executor: *Executor,
inspector: Inspector,

pub fn currentPage(self: *Session) ?*Page {
Expand Down Expand Up @@ -112,7 +112,7 @@ const Executor = struct {};
const Inspector = struct {
pub fn getRemoteObject(
self: *const Inspector,
executor: Executor,
executor: *Executor,
group: []const u8,
value: anytype,
) !RemoteObject {
Expand All @@ -122,6 +122,11 @@ const Inspector = struct {
_ = value;
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 {
Expand Down
9 changes: 9 additions & 0 deletions src/runtime/js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,15 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
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;
Expand Down
Loading