mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-09 18:17:28 -04:00
I forgot to update main and main_shell in previous commit. Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
52 lines
1.2 KiB
Zig
52 lines
1.2 KiB
Zig
const std = @import("std");
|
|
|
|
const jsruntime = @import("jsruntime");
|
|
|
|
const parser = @import("parser.zig");
|
|
const DOM = @import("dom.zig");
|
|
|
|
const html_test = @import("html_test.zig").html;
|
|
|
|
var doc: *parser.DocumentHTML = undefined;
|
|
|
|
fn execJS(
|
|
alloc: std.mem.Allocator,
|
|
js_env: *jsruntime.Env,
|
|
comptime apis: []jsruntime.API,
|
|
) !void {
|
|
|
|
// start JS env
|
|
js_env.start(apis);
|
|
defer js_env.stop();
|
|
|
|
// add document object
|
|
try js_env.addObject(apis, doc, "document");
|
|
|
|
// launch shellExec
|
|
try jsruntime.shellExec(alloc, js_env, apis);
|
|
}
|
|
|
|
pub fn main() !void {
|
|
|
|
// generate APIs
|
|
const apis = jsruntime.compile(DOM.Interfaces);
|
|
|
|
// document
|
|
doc = parser.documentHTMLInit();
|
|
defer parser.documentHTMLDeinit(doc);
|
|
try parser.documentHTMLParse(doc, html_test);
|
|
|
|
// create JS vm
|
|
const vm = jsruntime.VM.init();
|
|
defer vm.deinit();
|
|
|
|
// alloc
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
defer _ = gpa.deinit();
|
|
var arena = std.heap.ArenaAllocator.init(gpa.allocator());
|
|
defer arena.deinit();
|
|
|
|
// launch shell
|
|
try jsruntime.shell(&arena, apis, execJS, .{ .app_name = "browsercore" });
|
|
}
|