userctx: inject user context

This commit is contained in:
Pierre Tachoire
2024-04-16 12:06:29 +02:00
parent c1b73dfdc2
commit e18d04a799
10 changed files with 31 additions and 4 deletions

View File

@@ -54,6 +54,7 @@ const URLTestExecFn = url.testExecFn;
const HTMLElementTestExecFn = @import("html/elements.zig").testExecFn;
pub const Types = jsruntime.reflect(apiweb.Interfaces);
pub const UserContext = @import("user_context.zig").UserContext;
var doc: *parser.DocumentHTML = undefined;
@@ -81,6 +82,8 @@ fn testExecFn(
std.debug.print("documentHTMLClose error: {s}\n", .{@errorName(err)});
};
js_env.getUserContext().?.document = doc;
// alias global as self and window
var window = Window.create(null);
@@ -315,7 +318,11 @@ fn testJSRuntime(alloc: std.mem.Allocator) !void {
var arena_alloc = std.heap.ArenaAllocator.init(alloc);
defer arena_alloc.deinit();
try jsruntime.loadEnv(&arena_alloc, testsAllExecFn);
const userctx = UserContext{
.document = null,
};
try jsruntime.loadEnv(&arena_alloc, userctx, testsAllExecFn);
}
test "DocumentHTMLParseFromStr" {