Convert more DOM_NO_ERR cases to assertions

There is some risk to this change. The first is that I made a mistake. The
other is that one of the APIs that doesn't currently return an error changes
in the future.
This commit is contained in:
Karl Seguin
2025-09-17 13:37:24 +08:00
parent b7d26cf0d5
commit 58acb2b821
57 changed files with 380 additions and 446 deletions

View File

@@ -115,7 +115,7 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
for (nodes) |_n| {
var n = _n;
while (true) {
const p = try parser.nodeParentNode(n) orelse break;
const p = parser.nodeParentNode(n) orelse break;
// Register the node.
const node = try bc.node_registry.register(p);
@@ -144,7 +144,7 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
// If the node has no parent, it's the root node.
// We don't dispatch event for it because we assume the root node is
// dispatched via the DOM.getDocument command.
const p = try parser.nodeParentNode(node._node) orelse {
const p = parser.nodeParentNode(node._node) orelse {
continue;
};
@@ -353,7 +353,7 @@ fn scrollIntoViewIfNeeded(cmd: anytype) !void {
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
const node_type = parser.nodeType(node._node) catch return error.InvalidNode;
const node_type = parser.nodeType(node._node);
switch (node_type) {
.element => {},
.document => {},
@@ -395,7 +395,7 @@ fn getContentQuads(cmd: anytype) !void {
// visibility: hidden
// display: none
if (try parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
if (parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
// TODO implement for document or text
// Most likely document would require some hierachgy in the renderer. It is left unimplemented till we have a good example.
// Text may be tricky, multiple quads in case of multiple lines? empty quads of text = ""?
@@ -421,7 +421,7 @@ fn getBoxModel(cmd: anytype) !void {
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
// TODO implement for document or text
if (try parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
if (parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
const element = parser.nodeToElement(node._node);
const rect = try Element._getBoundingClientRect(element, page);