@@ -36,6 +36,8 @@ const CSSStyleSheet = @import("../cssom/CSSStyleSheet.zig");
3636const NodeIterator = @import ("node_iterator.zig" ).NodeIterator ;
3737const Range = @import ("range.zig" ).Range ;
3838
39+ const CustomEvent = @import ("../events/custom_event.zig" ).CustomEvent ;
40+
3941const Env = @import ("../env.zig" ).Env ;
4042
4143const DOMImplementation = @import ("implementation.zig" ).DOMImplementation ;
@@ -110,13 +112,21 @@ pub const Document = struct {
110112 return try parser .documentGetDoctype (self );
111113 }
112114
113- pub fn _createEvent (_ : * parser.Document , eventCstr : []const u8 ) ! * parser.Event {
114- // TODO: for now only "Event" constructor is supported
115- // see table on https://dom.spec.whatwg.org/#dom-document-createevent $2
115+ pub fn _createEvent (_ : * parser.Document , eventCstr : []const u8 ) ! union (enum ) {
116+ base : * parser.Event ,
117+ custom : CustomEvent ,
118+ } {
116119 if (std .ascii .eqlIgnoreCase (eventCstr , "Event" ) or std .ascii .eqlIgnoreCase (eventCstr , "Events" )) {
117- return try parser .eventCreate ();
120+ return .{ .base = try parser .eventCreate () };
121+ }
122+
123+ // Not documented in MDN but supported in Chrome.
124+ // This is actually both instance of `Event` and `CustomEvent`.
125+ if (std .ascii .eqlIgnoreCase (eventCstr , "CustomEvent" )) {
126+ return .{ .custom = try CustomEvent .constructor (eventCstr , null ) };
118127 }
119- return parser .DOMError .NotSupported ;
128+
129+ return error .NotSupported ;
120130 }
121131
122132 pub fn _getElementById (self : * parser.Document , id : []const u8 ) ! ? ElementUnion {
0 commit comments