window: use window as global object

This commit is contained in:
Pierre Tachoire
2024-02-26 10:57:51 +01:00
parent b8bf09c8e5
commit fec212ab94
9 changed files with 22 additions and 43 deletions

View File

@@ -4,6 +4,7 @@ const jsruntime = @import("jsruntime");
const parser = @import("netsurf.zig");
const apiweb = @import("apiweb.zig");
const Window = @import("html/window.zig").Window;
pub const Types = jsruntime.reflect(apiweb.Interfaces);
@@ -16,17 +17,14 @@ fn execJS(
alloc: std.mem.Allocator,
js_env: *jsruntime.Env,
) anyerror!void {
// start JS env
try js_env.start(alloc);
defer js_env.stop();
// alias global as self and window
try js_env.attachObject(try js_env.getGlobal(), "self", null);
try js_env.attachObject(try js_env.getGlobal(), "window", null);
// add document object
try js_env.addObject(doc, "document");
var window = Window.create(null);
window.replaceDocument(parser.documentHTMLToDocument(doc));
try js_env.bindGlobal(window);
while (true) {