File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1919const parser = @import ("../netsurf.zig" );
2020const Event = @import ("event.zig" ).Event ;
2121const JsObject = @import ("../env.zig" ).JsObject ;
22+ const netsurf = @import ("../netsurf.zig" );
2223
2324// https://dom.spec.whatwg.org/#interface-customevent
2425pub const CustomEvent = struct {
@@ -55,6 +56,25 @@ pub const CustomEvent = struct {
5556 pub fn get_detail (self : * CustomEvent ) ? JsObject {
5657 return self .detail ;
5758 }
59+
60+ // Initializes an already created `CustomEvent`.
61+ // https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/initCustomEvent
62+ pub fn _initCustomEvent (
63+ self : * CustomEvent ,
64+ event_type : []const u8 ,
65+ can_bubble : bool ,
66+ cancelable : bool ,
67+ detail : ? JsObject ,
68+ ) ! void {
69+ // This function can only be called after the constructor has called.
70+ // So we assume proto is initialized already by constructor.
71+ self .proto .type = try netsurf .strFromData (event_type );
72+ self .proto .bubble = can_bubble ;
73+ self .proto .cancelable = cancelable ;
74+ self .proto .is_initialised = true ;
75+ // Detail is stored separately.
76+ self .detail = detail ;
77+ }
5878};
5979
6080const testing = @import ("../../testing.zig" );
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ inline fn strToData(s: *String) []const u8 {
106106 return data [0.. c .dom_string_byte_length (s )];
107107}
108108
109- inline fn strFromData (data : []const u8 ) ! * String {
109+ pub inline fn strFromData (data : []const u8 ) ! * String {
110110 var s : ? * String = null ;
111111 const err = c .dom_string_create (data .ptr , data .len , & s );
112112 try DOMErr (err );
You can’t perform that action at this time.
0 commit comments