mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
xhr: move progress event in its own file
This commit is contained in:
@@ -13,12 +13,12 @@ const DOMException = @import("../dom/exceptions.zig").DOMException;
|
|||||||
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
||||||
const EventTargetUnion = @import("../dom/event_target.zig").Union;
|
const EventTargetUnion = @import("../dom/event_target.zig").Union;
|
||||||
|
|
||||||
const xhr = @import("../xhr/xhr.zig");
|
const ProgressEvent = @import("../xhr/progress_event.zig").ProgressEvent;
|
||||||
|
|
||||||
// Event interfaces
|
// Event interfaces
|
||||||
pub const Interfaces = generate.Tuple(.{
|
pub const Interfaces = generate.Tuple(.{
|
||||||
Event,
|
Event,
|
||||||
xhr.ProgressEvent,
|
ProgressEvent,
|
||||||
});
|
});
|
||||||
const Generated = generate.Union.compile(Interfaces);
|
const Generated = generate.Union.compile(Interfaces);
|
||||||
pub const Union = Generated._union;
|
pub const Union = Generated._union;
|
||||||
@@ -41,7 +41,7 @@ pub const Event = struct {
|
|||||||
pub fn toInterface(evt: *parser.Event) !Union {
|
pub fn toInterface(evt: *parser.Event) !Union {
|
||||||
return switch (try parser.eventGetInternalType(evt)) {
|
return switch (try parser.eventGetInternalType(evt)) {
|
||||||
.event => .{ .Event = evt },
|
.event => .{ .Event = evt },
|
||||||
.progress_event => .{ .ProgressEvent = @as(*xhr.ProgressEvent, @ptrCast(evt)).* },
|
.progress_event => .{ .ProgressEvent = @as(*ProgressEvent, @ptrCast(evt)).* },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const generate = @import("generate.zig");
|
|||||||
const parser = @import("netsurf.zig");
|
const parser = @import("netsurf.zig");
|
||||||
const apiweb = @import("apiweb.zig");
|
const apiweb = @import("apiweb.zig");
|
||||||
const Window = @import("html/window.zig").Window;
|
const Window = @import("html/window.zig").Window;
|
||||||
|
const xhr = @import("xhr/xhr.zig");
|
||||||
|
|
||||||
const documentTestExecFn = @import("dom/document.zig").testExecFn;
|
const documentTestExecFn = @import("dom/document.zig").testExecFn;
|
||||||
const HTMLDocumentTestExecFn = @import("html/document.zig").testExecFn;
|
const HTMLDocumentTestExecFn = @import("html/document.zig").testExecFn;
|
||||||
@@ -23,8 +24,8 @@ const NodeListTestExecFn = @import("dom/nodelist.zig").testExecFn;
|
|||||||
const AttrTestExecFn = @import("dom/attribute.zig").testExecFn;
|
const AttrTestExecFn = @import("dom/attribute.zig").testExecFn;
|
||||||
const EventTargetTestExecFn = @import("dom/event_target.zig").testExecFn;
|
const EventTargetTestExecFn = @import("dom/event_target.zig").testExecFn;
|
||||||
const EventTestExecFn = @import("events/event.zig").testExecFn;
|
const EventTestExecFn = @import("events/event.zig").testExecFn;
|
||||||
const xhr = @import("xhr/xhr.zig");
|
|
||||||
const XHRTestExecFn = xhr.testExecFn;
|
const XHRTestExecFn = xhr.testExecFn;
|
||||||
|
const ProgressEventTestExecFn = @import("xhr/progress_event.zig").testExecFn;
|
||||||
|
|
||||||
pub const Types = jsruntime.reflect(apiweb.Interfaces);
|
pub const Types = jsruntime.reflect(apiweb.Interfaces);
|
||||||
|
|
||||||
@@ -81,6 +82,7 @@ fn testsAllExecFn(
|
|||||||
EventTargetTestExecFn,
|
EventTargetTestExecFn,
|
||||||
EventTestExecFn,
|
EventTestExecFn,
|
||||||
XHRTestExecFn,
|
XHRTestExecFn,
|
||||||
|
ProgressEventTestExecFn,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline for (testFns) |testFn| {
|
inline for (testFns) |testFn| {
|
||||||
|
|||||||
72
src/xhr/progress_event.zig
Normal file
72
src/xhr/progress_event.zig
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const jsruntime = @import("jsruntime");
|
||||||
|
const Case = jsruntime.test_utils.Case;
|
||||||
|
const checkCases = jsruntime.test_utils.checkCases;
|
||||||
|
|
||||||
|
const parser = @import("../netsurf.zig");
|
||||||
|
const Event = @import("../events/event.zig").Event;
|
||||||
|
|
||||||
|
const DOMException = @import("../dom/exceptions.zig").DOMException;
|
||||||
|
|
||||||
|
pub const ProgressEvent = struct {
|
||||||
|
pub const prototype = *Event;
|
||||||
|
pub const Exception = DOMException;
|
||||||
|
pub const mem_guarantied = true;
|
||||||
|
|
||||||
|
pub const EventInit = struct {
|
||||||
|
lengthComputable: bool = false,
|
||||||
|
loaded: u64 = 0,
|
||||||
|
total: u64 = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
proto: parser.Event,
|
||||||
|
lengthComputable: bool,
|
||||||
|
loaded: u64 = 0,
|
||||||
|
total: u64 = 0,
|
||||||
|
|
||||||
|
pub fn constructor(eventType: []const u8, opts: ?EventInit) !ProgressEvent {
|
||||||
|
const event = try parser.eventCreate();
|
||||||
|
defer parser.eventDestroy(event);
|
||||||
|
try parser.eventInit(event, eventType, .{});
|
||||||
|
try parser.eventSetInternalType(event, .progress_event);
|
||||||
|
|
||||||
|
const o = opts orelse EventInit{};
|
||||||
|
|
||||||
|
return .{
|
||||||
|
.proto = event.*,
|
||||||
|
.lengthComputable = o.lengthComputable,
|
||||||
|
.loaded = o.loaded,
|
||||||
|
.total = o.total,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_lengthComputable(self: ProgressEvent) bool {
|
||||||
|
return self.lengthComputable;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_loaded(self: ProgressEvent) u64 {
|
||||||
|
return self.loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_total(self: ProgressEvent) u64 {
|
||||||
|
return self.total;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn testExecFn(
|
||||||
|
_: std.mem.Allocator,
|
||||||
|
js_env: *jsruntime.Env,
|
||||||
|
) anyerror!void {
|
||||||
|
var progress_event = [_]Case{
|
||||||
|
.{ .src = "let pevt = new ProgressEvent('foo');", .ex = "undefined" },
|
||||||
|
.{ .src = "pevt.loaded", .ex = "0" },
|
||||||
|
.{ .src = "pevt instanceof ProgressEvent", .ex = "true" },
|
||||||
|
.{ .src = "var nnb = 0; var eevt = null; function ccbk(event) { nnb ++; eevt = event; }", .ex = "undefined" },
|
||||||
|
.{ .src = "document.addEventListener('foo', ccbk)", .ex = "undefined" },
|
||||||
|
.{ .src = "document.dispatchEvent(pevt)", .ex = "true" },
|
||||||
|
.{ .src = "eevt.type", .ex = "foo" },
|
||||||
|
.{ .src = "eevt instanceof ProgressEvent", .ex = "true" },
|
||||||
|
};
|
||||||
|
try checkCases(js_env, &progress_event);
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ const generate = @import("../generate.zig");
|
|||||||
|
|
||||||
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
||||||
const Event = @import("../events/event.zig").Event;
|
const Event = @import("../events/event.zig").Event;
|
||||||
|
const ProgressEvent = @import("progress_event.zig").ProgressEvent;
|
||||||
const Callback = jsruntime.Callback;
|
const Callback = jsruntime.Callback;
|
||||||
const DOMError = @import("../netsurf.zig").DOMError;
|
const DOMError = @import("../netsurf.zig").DOMError;
|
||||||
const DOMException = @import("../dom/exceptions.zig").DOMException;
|
const DOMException = @import("../dom/exceptions.zig").DOMException;
|
||||||
@@ -123,51 +124,6 @@ pub const XMLHttpRequestUpload = struct {
|
|||||||
proto: XMLHttpRequestEventTarget = XMLHttpRequestEventTarget{},
|
proto: XMLHttpRequestEventTarget = XMLHttpRequestEventTarget{},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ProgressEvent = struct {
|
|
||||||
pub const prototype = *Event;
|
|
||||||
pub const Exception = DOMException;
|
|
||||||
pub const mem_guarantied = true;
|
|
||||||
|
|
||||||
pub const EventInit = struct {
|
|
||||||
lengthComputable: bool = false,
|
|
||||||
loaded: u64 = 0,
|
|
||||||
total: u64 = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
proto: parser.Event,
|
|
||||||
lengthComputable: bool,
|
|
||||||
loaded: u64 = 0,
|
|
||||||
total: u64 = 0,
|
|
||||||
|
|
||||||
pub fn constructor(eventType: []const u8, opts: ?EventInit) !ProgressEvent {
|
|
||||||
const event = try parser.eventCreate();
|
|
||||||
defer parser.eventDestroy(event);
|
|
||||||
try parser.eventInit(event, eventType, .{});
|
|
||||||
try parser.eventSetInternalType(event, .progress_event);
|
|
||||||
|
|
||||||
const o = opts orelse EventInit{};
|
|
||||||
|
|
||||||
return .{
|
|
||||||
.proto = event.*,
|
|
||||||
.lengthComputable = o.lengthComputable,
|
|
||||||
.loaded = o.loaded,
|
|
||||||
.total = o.total,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_lengthComputable(self: ProgressEvent) bool {
|
|
||||||
return self.lengthComputable;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_loaded(self: ProgressEvent) u64 {
|
|
||||||
return self.loaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_total(self: ProgressEvent) u64 {
|
|
||||||
return self.total;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const XMLHttpRequest = struct {
|
pub const XMLHttpRequest = struct {
|
||||||
pub const prototype = *XMLHttpRequestEventTarget;
|
pub const prototype = *XMLHttpRequestEventTarget;
|
||||||
pub const mem_guarantied = true;
|
pub const mem_guarantied = true;
|
||||||
@@ -595,16 +551,4 @@ pub fn testExecFn(
|
|||||||
.{ .src = "req.responseText.length > 1024", .ex = "true" },
|
.{ .src = "req.responseText.length > 1024", .ex = "true" },
|
||||||
};
|
};
|
||||||
try checkCases(js_env, &send);
|
try checkCases(js_env, &send);
|
||||||
|
|
||||||
var progress_event = [_]Case{
|
|
||||||
.{ .src = "let pevt = new ProgressEvent('foo');", .ex = "undefined" },
|
|
||||||
.{ .src = "pevt.loaded", .ex = "0" },
|
|
||||||
.{ .src = "pevt instanceof ProgressEvent", .ex = "true" },
|
|
||||||
.{ .src = "var nnb = 0; var eevt = null; function ccbk(event) { nnb ++; eevt = event; }", .ex = "undefined" },
|
|
||||||
.{ .src = "document.addEventListener('foo', ccbk)", .ex = "undefined" },
|
|
||||||
.{ .src = "document.dispatchEvent(pevt)", .ex = "true" },
|
|
||||||
.{ .src = "eevt.type", .ex = "foo" },
|
|
||||||
.{ .src = "eevt instanceof ProgressEvent", .ex = "true" },
|
|
||||||
};
|
|
||||||
try checkCases(js_env, &progress_event);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user