Execute script.onload/onerror

Add object-support for URLSearchParams. Start to treat js.Value as a first
class object (instead of js.Object, where appropriate).
This commit is contained in:
Karl Seguin
2025-11-30 12:48:15 +08:00
parent 9f587ab24b
commit 613428c54c
10 changed files with 226 additions and 84 deletions

View File

@@ -34,6 +34,7 @@ const IS_DEBUG = @import("builtin").mode == .Debug;
const Fetch = @This();
_page: *Page,
_url: []const u8,
_buf: std.ArrayList(u8),
_response: *Response,
_resolver: js.PersistentPromiseResolver,
@@ -48,6 +49,7 @@ pub fn init(input: Input, page: *Page) !js.Promise {
fetch.* = .{
._page = page,
._buf = .empty,
._url = try page.arena.dupe(u8, request._url),
._resolver = try page.js.createPromiseResolver(.page),
._response = try Response.init(null, .{ .status = 0 }, page),
};
@@ -58,6 +60,7 @@ pub fn init(input: Input, page: *Page) !js.Promise {
if (comptime IS_DEBUG) {
log.debug(.http, "fetch", .{ .url = request._url });
}
std.debug.print("fetch: {s}\n", .{request._url});
try http_client.request(.{
.ctx = fetch,
@@ -97,6 +100,7 @@ fn httpDataCallback(transfer: *Http.Transfer, data: []const u8) !void {
fn httpDoneCallback(ctx: *anyopaque) !void {
const self: *Fetch = @ptrCast(@alignCast(ctx));
self._response._body = self._buf.items;
std.debug.print("fetch-resolve: {s}\n", .{self._url});
return self._resolver.resolve(self._response);
}