mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
xhr: fix unit tests for 0.12.1
This commit is contained in:
@@ -25,7 +25,7 @@ const Case = jsruntime.test_utils.Case;
|
|||||||
const checkCases = jsruntime.test_utils.checkCases;
|
const checkCases = jsruntime.test_utils.checkCases;
|
||||||
|
|
||||||
const parser = @import("netsurf");
|
const parser = @import("netsurf");
|
||||||
const event_handler = @import("../events/event.zig").event_handler;
|
const EventHandler = @import("../events/event.zig").EventHandler;
|
||||||
|
|
||||||
const DOMException = @import("exceptions.zig").DOMException;
|
const DOMException = @import("exceptions.zig").DOMException;
|
||||||
const Nod = @import("node.zig");
|
const Nod = @import("node.zig");
|
||||||
@@ -75,7 +75,7 @@ pub const EventTarget = struct {
|
|||||||
eventType,
|
eventType,
|
||||||
cbk,
|
cbk,
|
||||||
capture orelse false,
|
capture orelse false,
|
||||||
event_handler,
|
EventHandler,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ pub fn testExecFn(
|
|||||||
try checkCases(js_env, &remove);
|
try checkCases(js_env, &remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const event_handler = struct {
|
pub const EventHandler = struct {
|
||||||
fn handle(event: ?*parser.Event, data: ?*anyopaque) callconv(.C) void {
|
fn handle(event: ?*parser.Event, data: ?*anyopaque) callconv(.C) void {
|
||||||
if (data) |d| {
|
if (data) |d| {
|
||||||
const func = parser.event_handler_cbk(d);
|
const func = parser.event_handler_cbk(d);
|
||||||
@@ -252,9 +252,9 @@ pub const event_handler = struct {
|
|||||||
if (event) |evt| {
|
if (event) |evt| {
|
||||||
func.trycall(.{
|
func.trycall(.{
|
||||||
Event.toInterface(evt) catch unreachable,
|
Event.toInterface(evt) catch unreachable,
|
||||||
}, &res) catch {};
|
}, &res) catch |e| log.err("event handler error: {any}", .{e});
|
||||||
} else {
|
} else {
|
||||||
func.trycall(.{event}, &res) catch {};
|
func.trycall(.{event}, &res) catch |e| log.err("event handler error: {any}", .{e});
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case of function error, we log the result and the trace.
|
// in case of function error, we log the result and the trace.
|
||||||
|
|||||||
@@ -608,13 +608,15 @@ pub fn eventTargetHasListener(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EventHandler = fn (event: ?*Event, data: ?*anyopaque) callconv(.C) void;
|
||||||
|
|
||||||
pub fn eventTargetAddEventListener(
|
pub fn eventTargetAddEventListener(
|
||||||
et: *EventTarget,
|
et: *EventTarget,
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
typ: []const u8,
|
typ: []const u8,
|
||||||
cbk: Callback,
|
cbk: Callback,
|
||||||
capture: bool,
|
capture: bool,
|
||||||
handler: anytype,
|
handler: EventHandler,
|
||||||
) !void {
|
) !void {
|
||||||
// this allocation will be removed either on
|
// this allocation will be removed either on
|
||||||
// eventTargetRemoveEventListener or eventTargetRemoveAllEventListeners
|
// eventTargetRemoveEventListener or eventTargetRemoveAllEventListeners
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ pub const URL = struct {
|
|||||||
var q = std.ArrayList(u8).init(alloc);
|
var q = std.ArrayList(u8).init(alloc);
|
||||||
defer q.deinit();
|
defer q.deinit();
|
||||||
try self.search_params.values.encode(q.writer());
|
try self.search_params.values.encode(q.writer());
|
||||||
self.uri.query = .{ .raw = q.items };
|
self.uri.query = .{ .percent_encoded = q.items };
|
||||||
|
|
||||||
return try self.format(alloc);
|
return try self.format(alloc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const jsruntime = @import("jsruntime");
|
|||||||
const Callback = jsruntime.Callback;
|
const Callback = jsruntime.Callback;
|
||||||
|
|
||||||
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
||||||
const event_handler = @import("../events/event.zig").event_handler;
|
const EventHandler = @import("../events/event.zig").EventHandler;
|
||||||
|
|
||||||
const parser = @import("netsurf");
|
const parser = @import("netsurf");
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ pub const XMLHttpRequestEventTarget = struct {
|
|||||||
typ,
|
typ,
|
||||||
cbk,
|
cbk,
|
||||||
false,
|
false,
|
||||||
event_handler,
|
EventHandler,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
fn unregister(self: *XMLHttpRequestEventTarget, alloc: std.mem.Allocator, typ: []const u8, cbk: Callback) !void {
|
fn unregister(self: *XMLHttpRequestEventTarget, alloc: std.mem.Allocator, typ: []const u8, cbk: Callback) !void {
|
||||||
|
|||||||
@@ -118,7 +118,12 @@ pub const XMLHttpRequest = struct {
|
|||||||
// https://lightpanda.slack.com/archives/C05TRU6RBM1/p1707819010681019
|
// https://lightpanda.slack.com/archives/C05TRU6RBM1/p1707819010681019
|
||||||
// upload: ?XMLHttpRequestUpload = null,
|
// upload: ?XMLHttpRequestUpload = null,
|
||||||
|
|
||||||
timeout: u32 = 0,
|
// TODO uncomment this field causes casting issue with
|
||||||
|
// XMLHttpRequestEventTarget. I think it's dueto an alignement issue, but
|
||||||
|
// not sure. see
|
||||||
|
// https://lightpanda.slack.com/archives/C05TRU6RBM1/p1707819010681019
|
||||||
|
// timeout: u32 = 0,
|
||||||
|
|
||||||
withCredentials: bool = false,
|
withCredentials: bool = false,
|
||||||
// TODO: response readonly attribute any response;
|
// TODO: response readonly attribute any response;
|
||||||
response_bytes: ?[]const u8 = null,
|
response_bytes: ?[]const u8 = null,
|
||||||
@@ -195,7 +200,7 @@ pub const XMLHttpRequest = struct {
|
|||||||
|
|
||||||
fn has(self: Headers, k: []const u8) bool {
|
fn has(self: Headers, k: []const u8) bool {
|
||||||
for (self.list.items) |h| {
|
for (self.list.items) |h| {
|
||||||
if (std.ascii.eqlIgnoreCase(k, h.value)) {
|
if (std.ascii.eqlIgnoreCase(k, h.name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +210,7 @@ pub const XMLHttpRequest = struct {
|
|||||||
|
|
||||||
fn getFirstValue(self: Headers, k: []const u8) ?[]const u8 {
|
fn getFirstValue(self: Headers, k: []const u8) ?[]const u8 {
|
||||||
for (self.list.items) |h| {
|
for (self.list.items) |h| {
|
||||||
if (std.ascii.eqlIgnoreCase(k, h.value)) {
|
if (std.ascii.eqlIgnoreCase(k, h.name)) {
|
||||||
return h.value;
|
return h.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,7 +221,7 @@ pub const XMLHttpRequest = struct {
|
|||||||
// replace any existing header with the same key
|
// replace any existing header with the same key
|
||||||
fn set(self: *Headers, k: []const u8, v: []const u8) !void {
|
fn set(self: *Headers, k: []const u8, v: []const u8) !void {
|
||||||
for (self.list.items, 0..) |h, i| {
|
for (self.list.items, 0..) |h, i| {
|
||||||
if (std.ascii.eqlIgnoreCase(k, h.value)) {
|
if (std.ascii.eqlIgnoreCase(k, h.name)) {
|
||||||
const hh = self.list.swapRemove(i);
|
const hh = self.list.swapRemove(i);
|
||||||
self.alloc.free(hh.name);
|
self.alloc.free(hh.name);
|
||||||
self.alloc.free(hh.value);
|
self.alloc.free(hh.value);
|
||||||
@@ -330,16 +335,16 @@ pub const XMLHttpRequest = struct {
|
|||||||
return self.state;
|
return self.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_timeout(self: *XMLHttpRequest) u32 {
|
pub fn get_timeout(_: *XMLHttpRequest) u32 {
|
||||||
return self.timeout;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_timeout(self: *XMLHttpRequest, timeout: u32) !void {
|
// TODO, the value is ignored for now.
|
||||||
|
pub fn set_timeout(_: *XMLHttpRequest, _: u32) !void {
|
||||||
// TODO If the current global object is a Window object and this’s
|
// TODO If the current global object is a Window object and this’s
|
||||||
// synchronous flag is set, then throw an "InvalidAccessError"
|
// synchronous flag is set, then throw an "InvalidAccessError"
|
||||||
// DOMException.
|
// DOMException.
|
||||||
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-timeout
|
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-timeout
|
||||||
self.timeout = timeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_withCredentials(self: *XMLHttpRequest) bool {
|
pub fn get_withCredentials(self: *XMLHttpRequest) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user