Skip to content

Commit a698ff8

Browse files
committed
describeNode feedback
1 parent 5026c48 commit a698ff8

File tree

3 files changed

+11
-35
lines changed

3 files changed

+11
-35
lines changed

src/cdp/domains/dom.zig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,11 @@ fn describeNode(cmd: anytype) !void {
170170
if (params.nodeId != null) {
171171
const node = bc.node_registry.lookup_by_id.get(params.nodeId.?) orelse return error.NodeNotFound;
172172
return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{});
173-
} else if (params.objectId != null) {
174-
173+
}
174+
if (params.objectId != null) {
175175
// Retrieve the object from which ever context it is in.
176-
const js_value = try bc.session.inspector.getValueByObjectId(cmd.arena, bc.session.executor, params.objectId.?);
177-
const entry = js_value.taggedAnyOpaque() orelse return error.ObjectIdIsNotANode;
178-
const subtype = entry.subtype orelse return error.ObjectIdIsNotANode;
179-
if (subtype != .node) return error.ObjectIdIsNotANode;
180-
181-
const node = try bc.node_registry.register(@ptrCast(entry.ptr));
176+
const parser_node = try bc.session.inspector.getNodePtr(cmd.arena, params.objectId.?);
177+
const node = try bc.node_registry.register(@ptrCast(parser_node));
182178
return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{});
183179
}
184180
return error.MissingParams;

src/cdp/testing.zig

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,12 @@ const Inspector = struct {
122122
_ = value;
123123
return RemoteObject{};
124124
}
125-
pub fn getValueByObjectId(self: Inspector, alloc: std.mem.Allocator, executor: *const Executor, object_id: []const u8) !Value {
125+
pub fn getNodePtr(self: Inspector, alloc: std.mem.Allocator, object_id: []const u8) !?*anyopaque {
126126
_ = self;
127-
_ = alloc;
128-
_ = executor;
129127
_ = object_id;
130-
return .{};
131-
}
132-
};
133-
const Value = struct {
134-
pub fn taggedAnyOpaque(self: Value) ?*TaggedAnyOpaque {
135-
_ = self;
136-
return null;
128+
return try alloc.create(i32);
137129
}
138130
};
139-
const TaggedAnyOpaque = struct {
140-
ptr: *anyopaque,
141-
subtype: ?SubType = .node,
142-
};
143-
144-
const SubType = enum {
145-
node,
146-
};
147131

148132
const RemoteObject = struct {
149133
pub fn deinit(self: RemoteObject) void {

src/runtime/js.zig

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,12 +1371,12 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
13711371
}
13721372

13731373
// Gets a value by object ID regardless of which context it is in.
1374-
// unwrapping the object also tells us the context, for now we assume it is always the default one.
1375-
// The executor argument is likely to change to somthing to allow us to find the right Executer with the given context
1376-
pub fn getValueByObjectId(self: Inspector, allocator: std.mem.Allocator, executor: *const Executor, object_id: []const u8) !Value {
1374+
pub fn getNodePtr(self: *const Inspector, allocator: Allocator, object_id: []const u8) !?*anyopaque {
13771375
const unwrapped = try self.session.unwrapObject(allocator, object_id);
1378-
// std.debug.assert(executor.context.handle == unwrapped.context.handle);
1379-
return .{ .value = unwrapped.value, .executor = executor }; // The values context and groupId are not used here
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;
13801380
}
13811381
};
13821382

@@ -1391,10 +1391,6 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
13911391
const executor = self.executor;
13921392
return valueToString(allocator, self.value, executor.isolate, executor.context);
13931393
}
1394-
1395-
pub fn taggedAnyOpaque(self: Value) ?*TaggedAnyOpaque {
1396-
return getTaggedAnyOpaque(self.value);
1397-
}
13981394
};
13991395

14001396
// Reverses the mapZigInstanceToJs, making sure that our TaggedAnyOpaque

0 commit comments

Comments
 (0)