mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
xhr: fix ProgressEvent implementation
This commit is contained in:
@@ -13,6 +13,16 @@ const DOMException = @import("../dom/exceptions.zig").DOMException;
|
||||
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
||||
const EventTargetUnion = @import("../dom/event_target.zig").Union;
|
||||
|
||||
const xhr = @import("../xhr/xhr.zig");
|
||||
|
||||
// Event interfaces
|
||||
pub const Interfaces = generate.Tuple(.{
|
||||
Event,
|
||||
xhr.ProgressEvent,
|
||||
});
|
||||
const Generated = generate.Union.compile(Interfaces);
|
||||
pub const Union = Generated._union;
|
||||
|
||||
// https://dom.spec.whatwg.org/#event
|
||||
pub const Event = struct {
|
||||
pub const Self = parser.Event;
|
||||
@@ -28,6 +38,13 @@ pub const Event = struct {
|
||||
pub const _AT_TARGET = 2;
|
||||
pub const _BUBBLING_PHASE = 3;
|
||||
|
||||
pub fn toInterface(evt: *parser.Event) !Union {
|
||||
return switch (try parser.eventGetInternalType(evt)) {
|
||||
.event => .{ .Event = evt },
|
||||
.progress_event => .{ .ProgressEvent = @as(*xhr.ProgressEvent, @ptrCast(evt)).* },
|
||||
};
|
||||
}
|
||||
|
||||
pub fn constructor(eventType: []const u8, opts: ?EventInit) !*parser.Event {
|
||||
const event = try parser.eventCreate();
|
||||
try parser.eventInit(event, eventType, opts orelse EventInit{});
|
||||
@@ -104,13 +121,6 @@ pub const Event = struct {
|
||||
}
|
||||
};
|
||||
|
||||
// Event interfaces
|
||||
pub const Interfaces = generate.Tuple(.{
|
||||
Event,
|
||||
});
|
||||
const Generated = generate.Union.compile(Interfaces);
|
||||
pub const Union = Generated._union;
|
||||
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
@@ -200,7 +210,7 @@ pub fn testExecFn(
|
||||
try checkCases(js_env, &legacy);
|
||||
|
||||
var remove = [_]Case{
|
||||
.{ .src = "var nb = 0; function cbk(event) { nb ++; }", .ex = "undefined" },
|
||||
.{ .src = "var nb = 0; var evt = null; function cbk(event) { nb ++; evt=event; }", .ex = "undefined" },
|
||||
.{ .src = "document.addEventListener('count', cbk)", .ex = "undefined" },
|
||||
.{ .src = "document.removeEventListener('count', cbk)", .ex = "undefined" },
|
||||
.{ .src = "document.dispatchEvent(new Event('count'))", .ex = "true" },
|
||||
|
||||
Reference in New Issue
Block a user