Skip to content

Commit 1734cb8

Browse files
committed
set defaults and unblock unittests
1 parent f13c1d8 commit 1734cb8

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/cdp/domains/dom.zig

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ fn describeNode(cmd: anytype) !void {
155155
nodeId: ?Node.Id = null,
156156
backendNodeId: ?Node.Id = null,
157157
objectId: ?[]const u8 = null,
158-
depth: ?u32 = null,
159-
pierce: ?bool = null,
158+
depth: u32 = 1,
159+
pierce: bool = false,
160160
})) orelse return error.InvalidParams;
161-
if (params.backendNodeId != null or params.depth != null or params.pierce != null) {
161+
if (params.backendNodeId != null or params.depth != 1 or params.pierce) {
162162
return error.NotYetImplementedParams;
163163
}
164164

@@ -169,12 +169,11 @@ fn describeNode(cmd: anytype) !void {
169169
return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{});
170170
} else if (params.objectId != null) {
171171
const jsValue = try bc.session.inspector.getValueByObjectId(cmd.arena, params.objectId.?);
172-
const entry = jsValue.externalEntry().?;
173-
const sub_type = entry.sub_type.?;
174172

175-
if (!std.mem.eql(u8, sub_type[0..std.mem.len(sub_type)], "node")) {
176-
return error.ObjectIdIsNotANode;
177-
}
173+
const entry = jsValue.externalEntry() orelse return error.ObjectIdIsNotANode;
174+
const sub_type = entry.sub_type orelse return error.ObjectIdIsNotANode;
175+
if (!std.mem.eql(u8, sub_type[0..std.mem.len(sub_type)], "node")) return error.ObjectIdIsNotANode;
176+
178177
const node = try bc.node_registry.register(@ptrCast(entry.ptr));
179178
return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{});
180179
}

src/cdp/testing.zig

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,22 @@ const Session = struct {
107107
}
108108
};
109109

110+
const Value = struct {
111+
pub fn externalEntry(self: Value) ?*ExternalEntry {
112+
_ = self;
113+
return allocator.create(ExternalEntry) catch unreachable;
114+
}
115+
};
116+
const ExternalEntry = struct {
117+
ptr: *anyopaque,
118+
sub_type: [*c]const u8 = null,
119+
};
120+
110121
const Env = struct {
111-
pub fn findOrAddValue(self: *Env, value: anytype) !@TypeOf(value) { // ?
122+
pub fn findOrAddValue(self: *Env, value: anytype) !Value {
112123
_ = self;
113-
return value;
124+
_ = value;
125+
return .{};
114126
}
115127
};
116128

@@ -122,6 +134,12 @@ const Inspector = struct {
122134
_ = groupName;
123135
return RemoteObject{};
124136
}
137+
pub fn getValueByObjectId(self: Inspector, alloc: std.mem.Allocator, object_id: []const u8) !Value {
138+
_ = self;
139+
_ = alloc;
140+
_ = object_id;
141+
return .{};
142+
}
125143
};
126144

127145
const RemoteObject = struct {

0 commit comments

Comments
 (0)