Skip to content

Commit eb829f4

Browse files
Merge pull request #225 from lightpanda-io/netsurf-empty-event-type
dom: an event type can be null
2 parents 2a94e5a + d155421 commit eb829f4

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/dom/exceptions.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ pub const DOMException = struct {
9191
error.InvalidNodeType => "InvalidNodeTypeError",
9292
error.DataClone => "DataCloneError",
9393
error.NoError => unreachable,
94+
95+
// custom netsurf error
96+
error.UnspecifiedEventType => "UnspecifiedEventTypeError",
97+
error.DispatchRequest => "DispatchRequestError",
98+
error.NoMemory => "NoMemoryError",
99+
error.AttributeWrongType => "AttributeWrongTypeError",
94100
};
95101
}
96102

@@ -124,6 +130,12 @@ pub const DOMException = struct {
124130
error.InvalidNodeType => 24,
125131
error.DataClone => 25,
126132
error.NoError => unreachable,
133+
134+
// custom netsurf error
135+
error.UnspecifiedEventType => 128,
136+
error.DispatchRequest => 129,
137+
error.NoMemory => 130,
138+
error.AttributeWrongType => 131,
127139
};
128140
}
129141

src/netsurf.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ pub const DOMError = error{
339339
Timeout,
340340
InvalidNodeType,
341341
DataClone,
342+
343+
// custom netsurf error
344+
UnspecifiedEventType,
345+
DispatchRequest,
346+
NoMemory,
347+
AttributeWrongType,
342348
};
343349

344350
const DOMException = c.dom_exception;
@@ -363,6 +369,13 @@ fn DOMErr(except: DOMException) DOMError!void {
363369
c.DOM_INVALID_ACCESS_ERR => DOMError.InvalidAccess,
364370
c.DOM_VALIDATION_ERR => DOMError.Validation,
365371
c.DOM_TYPE_MISMATCH_ERR => DOMError.TypeMismatch,
372+
373+
// custom netsurf error
374+
c.DOM_UNSPECIFIED_EVENT_TYPE_ERR => DOMError.UnspecifiedEventType,
375+
c.DOM_DISPATCH_REQUEST_ERR => DOMError.DispatchRequest,
376+
c.DOM_NO_MEM_ERR => DOMError.NoMemory,
377+
c.DOM_ATTR_WRONG_TYPE_ERR => DOMError.AttributeWrongType,
378+
366379
else => unreachable,
367380
};
368381
}
@@ -397,6 +410,10 @@ pub fn eventType(evt: *Event) ![]const u8 {
397410
var s: ?*String = undefined;
398411
const err = c._dom_event_get_type(evt, &s);
399412
try DOMErr(err);
413+
414+
// if the event type is null, return a empty string.
415+
if (s == null) return "";
416+
400417
return strToData(s.?);
401418
}
402419

0 commit comments

Comments
 (0)