Skip to content

Commit 1b74289

Browse files
Merge pull request #543 from lightpanda-io/describeNode2
descibeNode for new js runtime
2 parents f3d8ec0 + a698ff8 commit 1b74289

File tree

6 files changed

+51
-12
lines changed

6 files changed

+51
-12
lines changed

.github/actions/install/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ inputs:
1717
zig-v8:
1818
description: 'zig v8 version to install'
1919
required: false
20-
default: 'v0.1.17'
20+
default: 'v0.1.18'
2121
v8:
2222
description: 'v8 version to install'
2323
required: false

Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG ZIG=0.14.0
55
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
66
ARG ARCH=x86_64
77
ARG V8=11.1.134
8-
ARG ZIG_V8=v0.1.16
8+
ARG ZIG_V8=v0.1.18
99

1010
RUN apt-get update -yq && \
1111
apt-get install -yq xz-utils \
@@ -51,10 +51,6 @@ WORKDIR /browser
5151
RUN git submodule init && \
5252
git submodule update --recursive
5353

54-
RUN cd vendor/zig-js-runtime && \
55-
git submodule init && \
56-
git submodule update --recursive
57-
5854
RUN make install-libiconv && \
5955
make install-netsurf && \
6056
make install-mimalloc

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
.hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd",
1414
},
1515
.v8 = .{
16-
.url = "https://github.com/karlseguin/zig-v8-fork/archive/e5f1c0c9f1ed147617427f22cdaf11df4ab60b79.tar.gz",
17-
.hash = "v8-0.0.0-xddH61vYIACI2pT1t-dUbXm18cHAKy-KWT_Qft4sBwam",
16+
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/5790c80fcd12dec64e596f6f66f09de567020e8a.tar.gz",
17+
.hash = "v8-0.0.0-xddH66roIAAdXNJpBKN_NO8zBz2H8b9moUzshBCfns2p",
1818
},
1919
//.v8 = .{ .path = "../zig-v8-fork" },
2020
//.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },

src/cdp/domains/dom.zig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn processMessage(cmd: anytype) !void {
3030
getSearchResults,
3131
discardSearchResults,
3232
resolveNode,
33+
describeNode,
3334
}, cmd.input.action) orelse return error.UnknownMethod;
3435

3536
switch (action) {
@@ -39,6 +40,7 @@ pub fn processMessage(cmd: anytype) !void {
3940
.getSearchResults => return getSearchResults(cmd),
4041
.discardSearchResults => return discardSearchResults(cmd),
4142
.resolveNode => return resolveNode(cmd),
43+
.describeNode => return describeNode(cmd),
4244
}
4345
}
4446

@@ -151,6 +153,33 @@ fn resolveNode(cmd: anytype) !void {
151153
} }, .{});
152154
}
153155

156+
fn describeNode(cmd: anytype) !void {
157+
const params = (try cmd.params(struct {
158+
nodeId: ?Node.Id = null,
159+
backendNodeId: ?Node.Id = null,
160+
objectId: ?[]const u8 = null,
161+
depth: u32 = 1,
162+
pierce: bool = false,
163+
})) orelse return error.InvalidParams;
164+
if (params.backendNodeId != null or params.depth != 1 or params.pierce) {
165+
return error.NotYetImplementedParams;
166+
}
167+
168+
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
169+
170+
if (params.nodeId != null) {
171+
const node = bc.node_registry.lookup_by_id.get(params.nodeId.?) orelse return error.NodeNotFound;
172+
return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{});
173+
}
174+
if (params.objectId != null) {
175+
// Retrieve the object from which ever context it is in.
176+
const parser_node = try bc.session.inspector.getNodePtr(cmd.arena, params.objectId.?);
177+
const node = try bc.node_registry.register(@ptrCast(parser_node));
178+
return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{});
179+
}
180+
return error.MissingParams;
181+
}
182+
154183
const testing = @import("../testing.zig");
155184

156185
test "cdp.dom: getSearchResults unknown search id" {

src/cdp/testing.zig

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ const Browser = struct {
5555
if (self.session != null) {
5656
return error.MockBrowserSessionAlreadyExists;
5757
}
58-
5958
const arena = self.arena.allocator();
59+
const executor = arena.create(Executor) catch unreachable;
6060
self.session = try arena.create(Session);
6161
self.session.?.* = .{
6262
.page = null,
6363
.arena = arena,
64-
.executor = .{},
64+
.executor = executor,
6565
.inspector = .{},
6666
};
6767
return self.session.?;
@@ -78,7 +78,7 @@ const Browser = struct {
7878
const Session = struct {
7979
page: ?Page = null,
8080
arena: Allocator,
81-
executor: Executor,
81+
executor: *Executor,
8282
inspector: Inspector,
8383

8484
pub fn currentPage(self: *Session) ?*Page {
@@ -112,7 +112,7 @@ const Executor = struct {};
112112
const Inspector = struct {
113113
pub fn getRemoteObject(
114114
self: *const Inspector,
115-
executor: Executor,
115+
executor: *Executor,
116116
group: []const u8,
117117
value: anytype,
118118
) !RemoteObject {
@@ -122,6 +122,11 @@ const Inspector = struct {
122122
_ = value;
123123
return RemoteObject{};
124124
}
125+
pub fn getNodePtr(self: Inspector, alloc: std.mem.Allocator, object_id: []const u8) !?*anyopaque {
126+
_ = self;
127+
_ = object_id;
128+
return try alloc.create(i32);
129+
}
125130
};
126131

127132
const RemoteObject = struct {

src/runtime/js.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,15 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
13691369
generate_preview,
13701370
);
13711371
}
1372+
1373+
// Gets a value by object ID regardless of which context it is in.
1374+
pub fn getNodePtr(self: *const Inspector, allocator: Allocator, object_id: []const u8) !?*anyopaque {
1375+
const unwrapped = try self.session.unwrapObject(allocator, object_id);
1376+
// The values context and groupId are not used here
1377+
const toa = getTaggedAnyOpaque(unwrapped.value) orelse return null;
1378+
if (toa.subtype == null or toa.subtype != .node) return error.ObjectIdIsNotANode;
1379+
return toa.ptr;
1380+
}
13721381
};
13731382

13741383
pub const RemoteObject = v8.RemoteObject;

0 commit comments

Comments
 (0)