Skip to content

Commit 66e24ed

Browse files
committed
xhr: fix unit tests for 0.12.1
1 parent ecac824 commit 66e24ed

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

src/dom/event_target.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const Case = jsruntime.test_utils.Case;
2525
const checkCases = jsruntime.test_utils.checkCases;
2626

2727
const parser = @import("netsurf");
28-
const event_handler = @import("../events/event.zig").event_handler;
28+
const EventHandler = @import("../events/event.zig").EventHandler;
2929

3030
const DOMException = @import("exceptions.zig").DOMException;
3131
const Nod = @import("node.zig");
@@ -75,7 +75,7 @@ pub const EventTarget = struct {
7575
eventType,
7676
cbk,
7777
capture orelse false,
78-
event_handler,
78+
EventHandler,
7979
);
8080
}
8181

src/events/event.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub fn testExecFn(
240240
try checkCases(js_env, &remove);
241241
}
242242

243-
pub const event_handler = struct {
243+
pub const EventHandler = struct {
244244
fn handle(event: ?*parser.Event, data: ?*anyopaque) callconv(.C) void {
245245
if (data) |d| {
246246
const func = parser.event_handler_cbk(d);
@@ -252,9 +252,9 @@ pub const event_handler = struct {
252252
if (event) |evt| {
253253
func.trycall(.{
254254
Event.toInterface(evt) catch unreachable,
255-
}, &res) catch {};
255+
}, &res) catch |e| log.err("event handler error: {any}", .{e});
256256
} else {
257-
func.trycall(.{event}, &res) catch {};
257+
func.trycall(.{event}, &res) catch |e| log.err("event handler error: {any}", .{e});
258258
}
259259

260260
// in case of function error, we log the result and the trace.

src/netsurf/netsurf.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,15 @@ pub fn eventTargetHasListener(
608608
return null;
609609
}
610610

611+
const EventHandler = fn (event: ?*Event, data: ?*anyopaque) callconv(.C) void;
612+
611613
pub fn eventTargetAddEventListener(
612614
et: *EventTarget,
613615
alloc: std.mem.Allocator,
614616
typ: []const u8,
615617
cbk: Callback,
616618
capture: bool,
617-
handler: anytype,
619+
handler: EventHandler,
618620
) !void {
619621
// this allocation will be removed either on
620622
// eventTargetRemoveEventListener or eventTargetRemoveAllEventListeners

src/url/url.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub const URL = struct {
105105
var q = std.ArrayList(u8).init(alloc);
106106
defer q.deinit();
107107
try self.search_params.values.encode(q.writer());
108-
self.uri.query = .{ .raw = q.items };
108+
self.uri.query = .{ .percent_encoded = q.items };
109109

110110
return try self.format(alloc);
111111
}

src/xhr/event_target.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const jsruntime = @import("jsruntime");
2222
const Callback = jsruntime.Callback;
2323

2424
const EventTarget = @import("../dom/event_target.zig").EventTarget;
25-
const event_handler = @import("../events/event.zig").event_handler;
25+
const EventHandler = @import("../events/event.zig").EventHandler;
2626

2727
const parser = @import("netsurf");
2828

@@ -54,7 +54,7 @@ pub const XMLHttpRequestEventTarget = struct {
5454
typ,
5555
cbk,
5656
false,
57-
event_handler,
57+
EventHandler,
5858
);
5959
}
6060
fn unregister(self: *XMLHttpRequestEventTarget, alloc: std.mem.Allocator, typ: []const u8, cbk: Callback) !void {

src/xhr/xhr.zig

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ pub const XMLHttpRequest = struct {
118118
// https://lightpanda.slack.com/archives/C05TRU6RBM1/p1707819010681019
119119
// upload: ?XMLHttpRequestUpload = null,
120120

121-
timeout: u32 = 0,
121+
// TODO uncomment this field causes casting issue with
122+
// XMLHttpRequestEventTarget. I think it's dueto an alignement issue, but
123+
// not sure. see
124+
// https://lightpanda.slack.com/archives/C05TRU6RBM1/p1707819010681019
125+
// timeout: u32 = 0,
126+
122127
withCredentials: bool = false,
123128
// TODO: response readonly attribute any response;
124129
response_bytes: ?[]const u8 = null,
@@ -195,7 +200,7 @@ pub const XMLHttpRequest = struct {
195200

196201
fn has(self: Headers, k: []const u8) bool {
197202
for (self.list.items) |h| {
198-
if (std.ascii.eqlIgnoreCase(k, h.value)) {
203+
if (std.ascii.eqlIgnoreCase(k, h.name)) {
199204
return true;
200205
}
201206
}
@@ -205,7 +210,7 @@ pub const XMLHttpRequest = struct {
205210

206211
fn getFirstValue(self: Headers, k: []const u8) ?[]const u8 {
207212
for (self.list.items) |h| {
208-
if (std.ascii.eqlIgnoreCase(k, h.value)) {
213+
if (std.ascii.eqlIgnoreCase(k, h.name)) {
209214
return h.value;
210215
}
211216
}
@@ -216,7 +221,7 @@ pub const XMLHttpRequest = struct {
216221
// replace any existing header with the same key
217222
fn set(self: *Headers, k: []const u8, v: []const u8) !void {
218223
for (self.list.items, 0..) |h, i| {
219-
if (std.ascii.eqlIgnoreCase(k, h.value)) {
224+
if (std.ascii.eqlIgnoreCase(k, h.name)) {
220225
const hh = self.list.swapRemove(i);
221226
self.alloc.free(hh.name);
222227
self.alloc.free(hh.value);
@@ -330,16 +335,16 @@ pub const XMLHttpRequest = struct {
330335
return self.state;
331336
}
332337

333-
pub fn get_timeout(self: *XMLHttpRequest) u32 {
334-
return self.timeout;
338+
pub fn get_timeout(_: *XMLHttpRequest) u32 {
339+
return 0;
335340
}
336341

337-
pub fn set_timeout(self: *XMLHttpRequest, timeout: u32) !void {
342+
// TODO, the value is ignored for now.
343+
pub fn set_timeout(_: *XMLHttpRequest, _: u32) !void {
338344
// TODO If the current global object is a Window object and this’s
339345
// synchronous flag is set, then throw an "InvalidAccessError"
340346
// DOMException.
341347
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-timeout
342-
self.timeout = timeout;
343348
}
344349

345350
pub fn get_withCredentials(self: *XMLHttpRequest) bool {

0 commit comments

Comments
 (0)