usrctx: use ctx http client with xhr

This commit is contained in:
Pierre Tachoire
2024-04-23 12:09:41 +02:00
parent c2e64c131a
commit 00d75584db
6 changed files with 40 additions and 13 deletions

View File

@@ -30,6 +30,7 @@ const xhr = @import("xhr/xhr.zig");
const storage = @import("storage/storage.zig");
const url = @import("url/url.zig");
const urlquery = @import("url/query.zig");
const Client = @import("async/Client.zig");
const documentTestExecFn = @import("dom/document.zig").testExecFn;
const HTMLDocumentTestExecFn = @import("html/document.zig").testExecFn;
@@ -84,7 +85,13 @@ fn testExecFn(
std.debug.print("documentHTMLClose error: {s}\n", .{@errorName(err)});
};
js_env.getUserContext().?.document = doc;
var cli = Client{ .allocator = alloc, .loop = js_env.nat_ctx.loop };
defer cli.deinit();
try js_env.setUserContext(.{
.document = doc,
.httpClient = &cli,
});
// alias global as self and window
var window = Window.create(null);
@@ -322,11 +329,7 @@ fn testJSRuntime(alloc: std.mem.Allocator) !void {
var arena_alloc = std.heap.ArenaAllocator.init(alloc);
defer arena_alloc.deinit();
const userctx = UserContext{
.document = null,
};
try jsruntime.loadEnv(&arena_alloc, userctx, testsAllExecFn);
try jsruntime.loadEnv(&arena_alloc, null, testsAllExecFn);
}
test "DocumentHTMLParseFromStr" {