mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Adopt global Types changes in jsruntime
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -86,6 +86,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
const tests = b.addTest(.{ .root_source_file = .{ .path = "src/run_tests.zig" } });
|
||||
try common(tests, options);
|
||||
tests.single_threaded = true;
|
||||
tests.test_runner = "src/test_runner.zig";
|
||||
const run_tests = b.addRunArtifact(tests);
|
||||
|
||||
// step
|
||||
|
||||
@@ -55,8 +55,7 @@ pub const Attr = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var getters = [_]Case{
|
||||
.{ .src = "let a = document.createAttributeNS('foo', 'bar')", .ex = "undefined" },
|
||||
.{ .src = "a.namespaceURI", .ex = "foo" },
|
||||
|
||||
@@ -92,8 +92,7 @@ pub const CharacterData = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var get_data = [_]Case{
|
||||
.{ .src = "let link = document.getElementById('link')", .ex = "undefined" },
|
||||
.{ .src = "let cdata = link.firstChild", .ex = "undefined" },
|
||||
|
||||
@@ -251,8 +251,7 @@ pub const Document = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var constructor = [_]Case{
|
||||
.{ .src = "document.__proto__.__proto__.constructor.name", .ex = "Document" },
|
||||
.{ .src = "document.__proto__.__proto__.__proto__.constructor.name", .ex = "Node" },
|
||||
|
||||
@@ -290,8 +290,7 @@ pub const Element = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var getters = [_]Case{
|
||||
.{ .src = "let g = document.getElementById('content')", .ex = "undefined" },
|
||||
.{ .src = "g.namespaceURI", .ex = "http://www.w3.org/1999/xhtml" },
|
||||
|
||||
@@ -147,8 +147,7 @@ pub const DOMException = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
const err = "Failed to execute 'appendChild' on 'Node': The new child element contains the parent.";
|
||||
var cases = [_]Case{
|
||||
.{ .src = "let content = document.getElementById('content')", .ex = "undefined" },
|
||||
|
||||
@@ -338,8 +338,7 @@ pub const HTMLCollection = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var getElementsByTagName = [_]Case{
|
||||
.{ .src = "let getElementsByTagName = document.getElementsByTagName('p')", .ex = "undefined" },
|
||||
.{ .src = "getElementsByTagName.length", .ex = "2" },
|
||||
|
||||
@@ -74,8 +74,7 @@ pub const DOMImplementation = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var getImplementation = [_]Case{
|
||||
.{ .src = "let impl = document.implementation", .ex = "undefined" },
|
||||
.{ .src = "impl.createHTMLDocument();", .ex = "[object Document]" },
|
||||
|
||||
@@ -65,8 +65,7 @@ pub const NamedNodeMap = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var setItem = [_]Case{
|
||||
.{ .src = "let a = document.getElementById('content').attributes", .ex = "undefined" },
|
||||
.{ .src = "a.length", .ex = "1" },
|
||||
|
||||
@@ -264,8 +264,7 @@ pub const Node = struct {
|
||||
pub fn testExecFn(
|
||||
alloc: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
|
||||
// helper functions
|
||||
const trim_and_replace =
|
||||
|
||||
@@ -61,8 +61,7 @@ pub const NodeList = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var childnodes = [_]Case{
|
||||
.{ .src = "let list = document.getElementById('content').childNodes", .ex = "undefined" },
|
||||
.{ .src = "list.length", .ex = "9" },
|
||||
|
||||
@@ -43,8 +43,7 @@ pub const Text = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var get_whole_text = [_]Case{
|
||||
.{ .src = "let text = document.getElementById('link').firstChild", .ex = "undefined" },
|
||||
.{ .src = "text.wholeText === 'OK'", .ex = "true" },
|
||||
|
||||
@@ -98,8 +98,7 @@ pub const DOMTokenList = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var dynamiclist = [_]Case{
|
||||
.{ .src = "let gs = document.getElementById('para-empty')", .ex = "undefined" },
|
||||
.{ .src = "let cl = gs.classList", .ex = "undefined" },
|
||||
|
||||
@@ -29,8 +29,7 @@ pub const HTMLDocument = struct {
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
var constructor = [_]Case{
|
||||
.{ .src = "document.__proto__.constructor.name", .ex = "HTMLDocument" },
|
||||
.{ .src = "document.__proto__.__proto__.constructor.name", .ex = "Document" },
|
||||
|
||||
14
src/main.zig
14
src/main.zig
@@ -5,6 +5,8 @@ const jsruntime = @import("jsruntime");
|
||||
const parser = @import("netsurf.zig");
|
||||
const DOM = @import("dom.zig");
|
||||
|
||||
pub const Types = jsruntime.reflect(DOM.Interfaces);
|
||||
|
||||
const socket_path = "/tmp/browsercore-server.sock";
|
||||
|
||||
var doc: *parser.DocumentHTML = undefined;
|
||||
@@ -13,11 +15,10 @@ var server: std.net.StreamServer = undefined;
|
||||
fn execJS(
|
||||
alloc: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime apis: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
|
||||
// start JS env
|
||||
try js_env.start(alloc, apis);
|
||||
try js_env.start(alloc);
|
||||
defer js_env.stop();
|
||||
|
||||
// alias global as self and window
|
||||
@@ -25,7 +26,7 @@ fn execJS(
|
||||
try js_env.attachObject(try js_env.getGlobal(), "window", null);
|
||||
|
||||
// add document object
|
||||
try js_env.addObject(apis, doc, "document");
|
||||
try js_env.addObject(doc, "document");
|
||||
|
||||
while (true) {
|
||||
|
||||
@@ -49,9 +50,6 @@ fn execJS(
|
||||
|
||||
pub fn main() !void {
|
||||
|
||||
// generate APIs
|
||||
const apis = comptime jsruntime.compile(DOM.Interfaces);
|
||||
|
||||
// create v8 vm
|
||||
const vm = jsruntime.VM.init();
|
||||
defer vm.deinit();
|
||||
@@ -86,5 +84,5 @@ pub fn main() !void {
|
||||
try server.listen(addr);
|
||||
std.debug.print("Listening on: {s}...\n", .{socket_path});
|
||||
|
||||
try jsruntime.loadEnv(&arena, execJS, apis);
|
||||
try jsruntime.loadEnv(&arena, execJS);
|
||||
}
|
||||
|
||||
@@ -7,16 +7,17 @@ const DOM = @import("dom.zig");
|
||||
|
||||
const html_test = @import("html_test.zig").html;
|
||||
|
||||
pub const Types = jsruntime.reflect(DOM.Interfaces);
|
||||
|
||||
var doc: *parser.DocumentHTML = undefined;
|
||||
|
||||
fn execJS(
|
||||
alloc: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime apis: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
|
||||
// start JS env
|
||||
try js_env.start(alloc, apis);
|
||||
try js_env.start(alloc);
|
||||
defer js_env.stop();
|
||||
|
||||
// alias global as self and window
|
||||
@@ -24,17 +25,14 @@ fn execJS(
|
||||
try js_env.attachObject(try js_env.getGlobal(), "window", null);
|
||||
|
||||
// add document object
|
||||
try js_env.addObject(apis, doc, "document");
|
||||
try js_env.addObject(doc, "document");
|
||||
|
||||
// launch shellExec
|
||||
try jsruntime.shellExec(alloc, js_env, apis);
|
||||
try jsruntime.shellExec(alloc, js_env);
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
|
||||
// generate APIs
|
||||
const apis = comptime jsruntime.compile(DOM.Interfaces);
|
||||
|
||||
// allocator
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
@@ -55,5 +53,5 @@ pub fn main() !void {
|
||||
defer vm.deinit();
|
||||
|
||||
// launch shell
|
||||
try jsruntime.shell(&arena, apis, execJS, .{ .app_name = "browsercore" });
|
||||
try jsruntime.shell(&arena, execJS, .{ .app_name = "browsercore" });
|
||||
}
|
||||
|
||||
@@ -29,16 +29,14 @@ const Out = enum {
|
||||
text,
|
||||
};
|
||||
|
||||
pub const Types = jsruntime.reflect(DOM.Interfaces);
|
||||
|
||||
// TODO For now the WPT tests run is specific to WPT.
|
||||
// It manually load js framwork libs, and run the first script w/ js content in
|
||||
// the HTML page.
|
||||
// Once browsercore will have the html loader, it would be useful to refacto
|
||||
// this test to use it.
|
||||
pub fn main() !void {
|
||||
|
||||
// generate APIs
|
||||
const apis = comptime jsruntime.compile(DOM.Interfaces);
|
||||
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
const alloc = gpa.allocator();
|
||||
@@ -123,7 +121,7 @@ pub fn main() !void {
|
||||
var arena = std.heap.ArenaAllocator.init(alloc);
|
||||
defer arena.deinit();
|
||||
|
||||
const res = wpt.run(&arena, apis, wpt_dir, tc, &loader) catch |err| {
|
||||
const res = wpt.run(&arena, wpt_dir, tc, &loader) catch |err| {
|
||||
const suite = try Suite.init(alloc, tc, false, @errorName(err), null);
|
||||
try results.append(suite);
|
||||
|
||||
|
||||
@@ -20,17 +20,18 @@ const DOMTokenListExecFn = @import("dom/token_list.zig").testExecFn;
|
||||
const NodeListTestExecFn = @import("dom/nodelist.zig").testExecFn;
|
||||
const AttrTestExecFn = @import("dom/attribute.zig").testExecFn;
|
||||
|
||||
pub const Types = jsruntime.reflect(DOM.Interfaces);
|
||||
|
||||
var doc: *parser.DocumentHTML = undefined;
|
||||
|
||||
fn testExecFn(
|
||||
alloc: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime apis: []jsruntime.API,
|
||||
comptime execFn: jsruntime.ContextExecFn,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
|
||||
// start JS env
|
||||
try js_env.start(alloc, apis);
|
||||
try js_env.start(alloc);
|
||||
defer js_env.stop();
|
||||
|
||||
// alias global as self and window
|
||||
@@ -47,17 +48,16 @@ fn testExecFn(
|
||||
};
|
||||
|
||||
// add document object
|
||||
try js_env.addObject(apis, doc, "document");
|
||||
try js_env.addObject(doc, "document");
|
||||
|
||||
// run test
|
||||
try execFn(alloc, js_env, apis);
|
||||
try execFn(alloc, js_env);
|
||||
}
|
||||
|
||||
fn testsAllExecFn(
|
||||
alloc: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime apis: []jsruntime.API,
|
||||
) !void {
|
||||
) anyerror!void {
|
||||
const testFns = [_]jsruntime.ContextExecFn{
|
||||
documentTestExecFn,
|
||||
HTMLDocumentTestExecFn,
|
||||
@@ -75,19 +75,16 @@ fn testsAllExecFn(
|
||||
};
|
||||
|
||||
inline for (testFns) |testFn| {
|
||||
try testExecFn(alloc, js_env, apis, testFn);
|
||||
try testExecFn(alloc, js_env, testFn);
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
pub fn main() !void {
|
||||
std.debug.print("\n \n", .{});
|
||||
|
||||
// generate tests
|
||||
try generate.tests();
|
||||
|
||||
// generate APIs
|
||||
const apis = comptime jsruntime.compile(DOM.Interfaces);
|
||||
|
||||
// create JS vm
|
||||
const vm = jsruntime.VM.init();
|
||||
defer vm.deinit();
|
||||
@@ -96,7 +93,7 @@ test {
|
||||
var arena_alloc = std.heap.ArenaAllocator.init(bench_alloc.allocator());
|
||||
defer arena_alloc.deinit();
|
||||
|
||||
try jsruntime.loadEnv(&arena_alloc, testsAllExecFn, apis);
|
||||
try jsruntime.loadEnv(&arena_alloc, testsAllExecFn);
|
||||
}
|
||||
|
||||
test "DocumentHTMLParseFromStr" {
|
||||
|
||||
@@ -8,12 +8,13 @@ const parser = @import("../netsurf.zig");
|
||||
const jsruntime = @import("jsruntime");
|
||||
const Loop = jsruntime.Loop;
|
||||
const Env = jsruntime.Env;
|
||||
const TPL = jsruntime.TPL;
|
||||
|
||||
const Types = @import("../main_wpt.zig").Types;
|
||||
|
||||
// runWPT parses the given HTML file, starts a js env and run the first script
|
||||
// tags containing javascript sources.
|
||||
// It loads first the js libs files.
|
||||
pub fn run(arena: *std.heap.ArenaAllocator, comptime apis: []jsruntime.API, comptime dir: []const u8, f: []const u8, loader: *FileLoader) !jsruntime.JSResult {
|
||||
pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const u8, loader: *FileLoader) !jsruntime.JSResult {
|
||||
const alloc = arena.allocator();
|
||||
|
||||
// document
|
||||
@@ -31,16 +32,16 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime apis: []jsruntime.API, comp
|
||||
var js_env = try Env.init(alloc, &loop);
|
||||
defer js_env.deinit();
|
||||
|
||||
// load APIs in JS env
|
||||
var tpls: [apis.len]TPL = undefined;
|
||||
try js_env.load(apis, &tpls);
|
||||
// load user-defined types in JS env
|
||||
var js_types: [Types.len]usize = undefined;
|
||||
try js_env.load(&js_types);
|
||||
|
||||
// start JS env
|
||||
try js_env.start(alloc, apis);
|
||||
try js_env.start(alloc);
|
||||
defer js_env.stop();
|
||||
|
||||
// add document object
|
||||
try js_env.addObject(apis, html_doc, "document");
|
||||
try js_env.addObject(html_doc, "document");
|
||||
|
||||
// alias global as self and window
|
||||
try js_env.attachObject(try js_env.getGlobal(), "self", null);
|
||||
|
||||
2
vendor/jsruntime-lib
vendored
2
vendor/jsruntime-lib
vendored
Submodule vendor/jsruntime-lib updated: e03c46a39a...2ed82ec570
Reference in New Issue
Block a user