xhr: use nested object for ProgressEventInit

This commit is contained in:
Pierre Tachoire
2024-02-08 14:31:15 +01:00
parent 5aafc93a03
commit d24df5725c

View File

@@ -29,7 +29,6 @@ pub const Interfaces = generate.Tuple(.{
XMLHttpRequestUpload, XMLHttpRequestUpload,
XMLHttpRequest, XMLHttpRequest,
ProgressEvent, ProgressEvent,
ProgressEventInit,
}); });
pub const XMLHttpRequestEventTarget = struct { pub const XMLHttpRequestEventTarget = struct {
@@ -125,30 +124,28 @@ pub const XMLHttpRequestUpload = struct {
proto: XMLHttpRequestEventTarget = XMLHttpRequestEventTarget{}, proto: XMLHttpRequestEventTarget = XMLHttpRequestEventTarget{},
}; };
pub const ProgressEventInit = struct {
pub const mem_guarantied = true;
lengthComputable: bool = false,
loaded: u64 = 0,
total: u64 = 0,
};
pub const ProgressEvent = struct { pub const ProgressEvent = struct {
pub const prototype = *Event; pub const prototype = *Event;
pub const Exception = DOMException; pub const Exception = DOMException;
pub const mem_guarantied = true; pub const mem_guarantied = true;
pub const EventInit = struct {
lengthComputable: bool = false,
loaded: u64 = 0,
total: u64 = 0,
};
proto: parser.Event, proto: parser.Event,
lengthComputable: bool, lengthComputable: bool,
loaded: u64 = 0, loaded: u64 = 0,
total: u64 = 0, total: u64 = 0,
pub fn constructor(eventType: []const u8, opts: ?ProgressEventInit) !ProgressEvent { pub fn constructor(eventType: []const u8, opts: ?EventInit) !ProgressEvent {
const event = try parser.eventCreate(); const event = try parser.eventCreate();
defer parser.eventDestroy(event); defer parser.eventDestroy(event);
try parser.eventInit(event, eventType, .{}); try parser.eventInit(event, eventType, .{});
const o = opts orelse ProgressEventInit{}; const o = opts orelse EventInit{};
return .{ return .{
.proto = event.*, .proto = event.*,
@@ -332,7 +329,7 @@ pub const XMLHttpRequest = struct {
fn dispatchProgressEvent( fn dispatchProgressEvent(
self: *XMLHttpRequest, self: *XMLHttpRequest,
typ: []const u8, typ: []const u8,
opts: ProgressEventInit, opts: ProgressEvent.EventInit,
) void { ) void {
// TODO destroy struct // TODO destroy struct
const evt = self.alloc.create(ProgressEvent) catch |e| { const evt = self.alloc.create(ProgressEvent) catch |e| {