mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-17 08:48:58 +00:00
Initial commit
Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
51
src/main_shell.zig
Normal file
51
src/main_shell.zig
Normal file
@@ -0,0 +1,51 @@
|
||||
const std = @import("std");
|
||||
|
||||
const jsruntime = @import("jsruntime");
|
||||
const Console = @import("jsruntime").Console;
|
||||
|
||||
const DOM = @import("dom.zig");
|
||||
|
||||
const html = @import("html.zig").html;
|
||||
|
||||
var doc: DOM.HTMLDocument = undefined;
|
||||
|
||||
fn execJS(
|
||||
alloc: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime apis: []jsruntime.API,
|
||||
) !void {
|
||||
|
||||
// start JS env
|
||||
js_env.start();
|
||||
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
|
||||
var base_doc = DOM.Document.init();
|
||||
defer base_doc.deinit();
|
||||
try base_doc.parse(html);
|
||||
doc = DOM.HTMLDocument{ .proto = base_doc };
|
||||
|
||||
// create JS vm
|
||||
const vm = jsruntime.VM.init();
|
||||
defer vm.deinit();
|
||||
|
||||
// alloc
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
const alloc = gpa.allocator();
|
||||
|
||||
// launch shell
|
||||
try jsruntime.shell(alloc, false, apis, execJS, .{ .app_name = "browsercore" });
|
||||
}
|
||||
Reference in New Issue
Block a user