Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/dom/exceptions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ pub const DOMException = struct {
error.InvalidNodeType => "InvalidNodeTypeError",
error.DataClone => "DataCloneError",
error.NoError => unreachable,

// custom netsurf error
error.UnspecifiedEventType => "UnspecifiedEventTypeError",
error.DispatchRequest => "DispatchRequestError",
error.NoMemory => "NoMemoryError",
error.AttributeWrongType => "AttributeWrongTypeError",
};
}

Expand Down Expand Up @@ -124,6 +130,12 @@ pub const DOMException = struct {
error.InvalidNodeType => 24,
error.DataClone => 25,
error.NoError => unreachable,

// custom netsurf error
error.UnspecifiedEventType => 128,
error.DispatchRequest => 129,
error.NoMemory => 130,
error.AttributeWrongType => 131,
};
}

Expand Down
17 changes: 17 additions & 0 deletions src/netsurf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ pub const DOMError = error{
Timeout,
InvalidNodeType,
DataClone,

// custom netsurf error
UnspecifiedEventType,
DispatchRequest,
NoMemory,
AttributeWrongType,
};

const DOMException = c.dom_exception;
Expand All @@ -363,6 +369,13 @@ fn DOMErr(except: DOMException) DOMError!void {
c.DOM_INVALID_ACCESS_ERR => DOMError.InvalidAccess,
c.DOM_VALIDATION_ERR => DOMError.Validation,
c.DOM_TYPE_MISMATCH_ERR => DOMError.TypeMismatch,

// custom netsurf error
c.DOM_UNSPECIFIED_EVENT_TYPE_ERR => DOMError.UnspecifiedEventType,
c.DOM_DISPATCH_REQUEST_ERR => DOMError.DispatchRequest,
c.DOM_NO_MEM_ERR => DOMError.NoMemory,
c.DOM_ATTR_WRONG_TYPE_ERR => DOMError.AttributeWrongType,

else => unreachable,
};
}
Expand Down Expand Up @@ -397,6 +410,10 @@ pub fn eventType(evt: *Event) ![]const u8 {
var s: ?*String = undefined;
const err = c._dom_event_get_type(evt, &s);
try DOMErr(err);

// if the event type is null, return a empty string.
if (s == null) return "";

return strToData(s.?);
}

Expand Down