mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
window: use window as global object
This commit is contained in:
@@ -8,6 +8,7 @@ const parser = @import("../netsurf.zig");
|
||||
const jsruntime = @import("jsruntime");
|
||||
const Loop = jsruntime.Loop;
|
||||
const Env = jsruntime.Env;
|
||||
const Window = @import("../html/window.zig").Window;
|
||||
|
||||
const Types = @import("../main_wpt.zig").Types;
|
||||
|
||||
@@ -50,31 +51,14 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
|
||||
}
|
||||
|
||||
// setup global env vars.
|
||||
try js_env.attachObject(try js_env.getGlobal(), "self", null);
|
||||
try js_env.attachObject(try js_env.getGlobal(), "window", null);
|
||||
try js_env.addObject(html_doc, "document");
|
||||
var window = Window.create(null);
|
||||
window.replaceDocument(doc);
|
||||
try js_env.bindGlobal(window);
|
||||
|
||||
// thanks to the arena, we don't need to deinit res.
|
||||
var res: jsruntime.JSResult = undefined;
|
||||
|
||||
const init =
|
||||
\\window.listeners = [];
|
||||
\\window.document = document;
|
||||
\\window.parent = window;
|
||||
\\window.addEventListener = function (type, listener, options) {
|
||||
\\ window.listeners.push({type: type, listener: listener, options: options});
|
||||
\\};
|
||||
\\window.dispatchEvent = function (event) {
|
||||
\\ len = window.listeners.length;
|
||||
\\ for (var i = 0; i < len; i++) {
|
||||
\\ if (window.listeners[i].type == event.target) {
|
||||
\\ window.listeners[i].listener(event);
|
||||
\\ }
|
||||
\\ }
|
||||
\\ return true;
|
||||
\\};
|
||||
\\window.removeEventListener = function () {};
|
||||
\\
|
||||
\\console = [];
|
||||
\\console.log = function () {
|
||||
\\ console.push(...arguments);
|
||||
@@ -116,7 +100,7 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
|
||||
}
|
||||
|
||||
// Mark tests as ready to run.
|
||||
res = try evalJS(js_env, alloc, "window.dispatchEvent({target: 'load'});", "ready");
|
||||
res = try evalJS(js_env, alloc, "window.dispatchEvent(new Event('load'));", "ready");
|
||||
if (!res.success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user