DOMException: implements reviewer comments

Co-authored-by: Pierre Tachoire <pierre@lightpanda.io>
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2023-11-24 18:26:03 +01:00
parent 57dcbe1ba9
commit 372c93d0f5
2 changed files with 5 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ const checkCases = jsruntime.test_utils.checkCases;
const parser = @import("../netsurf.zig");
// https://webidl.spec.whatwg.org/#idl-DOMException
pub const DOMException = struct {
err: parser.DOMError,
str: []const u8,

View File

@@ -299,8 +299,9 @@ pub const DOMError = error{
const DOMException = c.dom_exception;
fn DOMExceptionError(except: DOMException) DOMError {
fn DOMErr(except: DOMException) DOMError!void {
return switch (except) {
c.DOM_NO_ERR => return,
c.DOM_INDEX_SIZE_ERR => DOMError.IndexSize,
c.DOM_DOMSTRING_SIZE_ERR => DOMError.StringSize,
c.DOM_HIERARCHY_REQUEST_ERR => DOMError.HierarchyRequest,
@@ -318,7 +319,7 @@ fn DOMExceptionError(except: DOMException) DOMError {
c.DOM_INVALID_ACCESS_ERR => DOMError.InvalidAccess,
c.DOM_VALIDATION_ERR => DOMError.Validation,
c.DOM_TYPE_MISMATCH_ERR => DOMError.TypeMismatch,
else => DOMError.NoError,
else => unreachable,
};
}
@@ -502,7 +503,7 @@ pub fn nodeSetTextContent(node: *Node, value: []const u8) void {
pub fn nodeAppendChild(node: *Node, child: *Node) DOMError!*Node {
var res: ?*Node = undefined;
const err = nodeVtable(node).dom_node_append_child.?(node, child, &res);
if (err != 0) return DOMExceptionError(err);
try DOMErr(err);
return res.?;
}