Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
zig:
description: 'Zig version to install'
required: false
default: '0.13.0'
default: '0.14.0'
arch:
description: 'CPU arch used to select the v8 lib'
required: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zig-fmt.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: zig-fmt

env:
ZIG_VERSION: 0.13.0
ZIG_VERSION: 0.14.0

on:
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[submodule "vendor/zig-js-runtime"]
path = vendor/zig-js-runtime
url = https://github.com/lightpanda-io/zig-js-runtime.git/
branch = zig-0.14
[submodule "vendor/netsurf/libwapcaplet"]
path = vendor/netsurf/libwapcaplet
url = https://github.com/lightpanda-io/libwapcaplet.git/
Expand Down Expand Up @@ -28,3 +29,4 @@
[submodule "vendor/zig-async-io"]
path = vendor/zig-async-io
url = https://github.com/lightpanda-io/zig-async-io.git/
branch = zig-0.14
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:24.04

ARG MINISIG=0.12
ARG ZIG=0.13.0
ARG ZIG=0.14.0
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
ARG ARCH=x86_64
ARG V8=11.1.134
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ You can also follow the progress of our Javascript support in our dedicated [zig

### Prerequisites

Lightpanda is written with [Zig](https://ziglang.org/) `0.13.0`. You have to
Lightpanda is written with [Zig](https://ziglang.org/) `0.14.0`. You have to
install it with the right version in order to build the project.

Lightpanda also depends on
Expand Down
6 changes: 3 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn build(b: *std.Build) !void {
// compile
const tests = b.addTest(.{
.root_source_file = b.path("src/main_tests.zig"),
.test_runner = b.path("src/main_tests.zig"),
.test_runner = .{ .path = b.path("src/main_tests.zig"), .mode = .simple },
.target = target,
.optimize = mode,
});
Expand All @@ -134,7 +134,7 @@ pub fn build(b: *std.Build) !void {
// compile
const unit_tests = b.addTest(.{
.root_source_file = b.path("src/unit_tests.zig"),
.test_runner = b.path("src/unit_tests.zig"),
.test_runner = .{ .path = b.path("src/unit_tests.zig"), .mode = .simple },
.target = target,
.optimize = mode,
});
Expand Down Expand Up @@ -195,7 +195,7 @@ fn common(
step.root_module.addImport("asyncio", asyncio);

const tlsmod = b.addModule("tls", .{
.root_source_file = b.path("vendor/tls.zig/src/main.zig"),
.root_source_file = b.path("vendor/tls.zig/src/root.zig"),
});
step.root_module.addImport("tls", tlsmod);
}
Expand Down
32 changes: 13 additions & 19 deletions src/browser/browser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ pub const Session = struct {

const ContextT = @TypeOf(ctx);
const InspectorContainer = switch (@typeInfo(ContextT)) {
.Struct => ContextT,
.Pointer => |ptr| ptr.child,
.Void => NoopInspector,
.@"struct" => ContextT,
.pointer => |ptr| ptr.child,
.void => NoopInspector,
else => @compileError("invalid context type"),
};

// const ctx_opaque = @as(*anyopaque, @ptrCast(ctx));
self.inspector = try jsruntime.Inspector.init(
arena,
self.env, // TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
&self.env,
if (@TypeOf(ctx) == void) @constCast(@ptrCast(&{})) else ctx,
InspectorContainer.onInspectorResponse,
InspectorContainer.onInspectorEvent,
Expand Down Expand Up @@ -231,7 +231,7 @@ pub const Session = struct {

// load polyfills
// TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
try polyfill.load(self.arena.allocator(), self.env);
try polyfill.load(self.arena.allocator(), &self.env);

// inspector
self.contextCreated(page, aux_data);
Expand Down Expand Up @@ -264,7 +264,7 @@ pub const Session = struct {

fn contextCreated(self: *Session, page: *Page, aux_data: ?[]const u8) void {
log.debug("inspector context created", .{});
self.inspector.contextCreated(self.env, "", page.origin orelse "://", aux_data);
self.inspector.contextCreated(&self.env, "", page.origin orelse "://", aux_data);
}
};

Expand Down Expand Up @@ -316,15 +316,15 @@ pub const Page = struct {
pub fn wait(self: *Page) !void {
// try catch
var try_catch: jsruntime.TryCatch = undefined;
try_catch.init(self.session.env);
try_catch.init(&self.session.env);
defer try_catch.deinit();

self.session.env.wait() catch |err| {
// the js env could not be started if the document wasn't an HTML.
if (err == error.EnvNotStarted) return;

const arena = self.arena;
if (try try_catch.err(arena, self.session.env)) |msg| {
if (try try_catch.err(arena, &self.session.env)) |msg| {
defer arena.free(msg);
log.info("wait error: {s}", .{msg});
return;
Expand Down Expand Up @@ -591,9 +591,7 @@ pub const Page = struct {
// TODO handle charset attribute
const opt_text = try parser.nodeTextContent(parser.elementToNode(s.element));
if (opt_text) |text| {
// TODO: change to &self.session.env when
// https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
try s.eval(self.arena, self.session.env, text);
try s.eval(self.arena, &self.session.env, text);
return;
}

Expand Down Expand Up @@ -656,11 +654,8 @@ pub const Page = struct {
// received.
fn fetchScript(self: *const Page, s: *const Script) !void {
const arena = self.arena;

const body = try self.fetchData(arena, s.src, null);
// TODO: change to &self.session.env when
// https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
try s.eval(arena, self.session.env, body);
try s.eval(arena, &self.session.env, body);
}

const Script = struct {
Expand All @@ -683,9 +678,8 @@ pub const Page = struct {

return .{
.element = e,
.kind = kind(try parser.elementGetAttribute(e, "type")),
.kind = parseKind(try parser.elementGetAttribute(e, "type")),
.is_async = try parser.elementGetAttribute(e, "async") != null,

.src = try parser.elementGetAttribute(e, "src") orelse "inline",
};
}
Expand All @@ -695,15 +689,15 @@ pub const Page = struct {
// > type indicates that the script is a "classic script", containing
// > JavaScript code.
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type
fn kind(stype: ?[]const u8) Kind {
fn parseKind(stype: ?[]const u8) Kind {
if (stype == null or stype.?.len == 0) return .javascript;
if (std.mem.eql(u8, stype.?, "application/javascript")) return .javascript;
if (std.mem.eql(u8, stype.?, "module")) return .module;

return .unknown;
}

fn eval(self: Script, arena: Allocator, env: Env, body: []const u8) !void {
fn eval(self: Script, arena: Allocator, env: *const Env, body: []const u8) !void {
var try_catch: jsruntime.TryCatch = undefined;
try_catch.init(env);
defer try_catch.deinit();
Expand Down
2 changes: 1 addition & 1 deletion src/browser/mime.zig
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub const Mime = struct {
const bit_len = @bitSizeOf(@TypeOf(target.*)) - 8;
const byte_len = bit_len / 8;

const T = @Type(.{ .Int = .{
const T = @Type(.{ .int = .{
.bits = bit_len,
.signedness = .unsigned,
} });
Expand Down
4 changes: 2 additions & 2 deletions src/cdp/cdp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
pub fn sendResult(self: *Self, result: anytype, opts: SendResultOpts) !void {
return self.sender.sendJSON(.{
.id = self.input.id,
.result = if (comptime @typeInfo(@TypeOf(result)) == .Null) struct {}{} else result,
.result = if (comptime @typeInfo(@TypeOf(result)) == .null) struct {}{} else result,
.sessionId = if (opts.include_session_id) self.input.session_id else null,
});
}
Expand All @@ -466,7 +466,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
// Events ALWAYS go to the client. self.sender should not be used
return self.cdp.sendJSON(.{
.method = method,
.params = if (comptime @typeInfo(@TypeOf(p)) == .Null) struct {}{} else p,
.params = if (comptime @typeInfo(@TypeOf(p)) == .null) struct {}{} else p,
.sessionId = opts.session_id,
});
}
Expand Down
101 changes: 4 additions & 97 deletions src/cdp/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ const TestContext = struct {

pub fn processMessage(self: *TestContext, msg: anytype) !void {
var json_message: []const u8 = undefined;
if (@typeInfo(@TypeOf(msg)) != .Pointer) {
json_message = try json.stringifyAlloc(self.arena.allocator(), msg, .{});
if (@typeInfo(@TypeOf(msg)) != .pointer) {
json_message = try std.json.stringifyAlloc(self.arena.allocator(), msg, .{});
} else {
// assume this is a string we want to send as-is, if it isn't, we'll
// get a compile error, so no big deal.
Expand All @@ -196,7 +196,7 @@ const TestContext = struct {
pub fn expectSentResult(self: *TestContext, expected: anytype, opts: ExpectResultOpts) !void {
const expected_result = .{
.id = opts.id,
.result = if (comptime @typeInfo(@TypeOf(expected)) == .Null) struct {}{} else expected,
.result = if (comptime @typeInfo(@TypeOf(expected)) == .null) struct {}{} else expected,
.sessionId = opts.session_id,
};

Expand All @@ -210,7 +210,7 @@ const TestContext = struct {
pub fn expectSentEvent(self: *TestContext, method: []const u8, params: anytype, opts: ExpectEventOpts) !void {
const expected_event = .{
.method = method,
.params = if (comptime @typeInfo(@TypeOf(params)) == .Null) struct {}{} else params,
.params = if (comptime @typeInfo(@TypeOf(params)) == .null) struct {}{} else params,
.sessionId = opts.session_id,
};

Expand Down Expand Up @@ -323,96 +323,3 @@ fn compareJsonValues(a: std.json.Value, b: std.json.Value) bool {
},
}
}

// fn compareAnyToJsonValue(expected: anytype, actual: json.Value) bool {
// switch (@typeInfo(@TypeOf(expected))) {
// .Optional => {
// if (expected) |e| {
// return compareAnyToJsonValue(e, actual);
// }
// return actual == .null;
// },
// .Int, .ComptimeInt => {
// if (actual != .integer) {
// return false;
// }
// return expected == actual.integer;
// },
// .Float, .ComptimeFloat => {
// if (actual != .float) {
// return false;
// }
// return expected == actual.float;
// },
// .Bool => {
// if (actual != .bool) {
// return false;
// }
// return expected == actual.bool;
// },
// .Pointer => |ptr| switch (ptr.size) {
// .One => switch (@typeInfo(ptr.child)) {
// .Struct => return compareAnyToJsonValue(expected.*, actual),
// .Array => |arr| if (arr.child == u8) {
// if (actual != .string) {
// return false;
// }
// return std.mem.eql(u8, expected, actual.string);
// },
// else => {},
// },
// .Slice => switch (ptr.child) {
// u8 => {
// if (actual != .string) {
// return false;
// }
// return std.mem.eql(u8, expected, actual.string);
// },
// else => {},
// },
// else => {},
// },
// .Struct => |s| {
// if (s.is_tuple) {
// // how an array might look in an anytype
// if (actual != .array) {
// return false;
// }
// if (s.fields.len != actual.array.items.len) {
// return false;
// }

// inline for (s.fields, 0..) |f, i| {
// const e = @field(expected, f.name);
// if (compareAnyToJsonValue(e, actual.array.items[i]) == false) {
// return false;
// }
// }
// return true;
// }

// if (s.fields.len == 0) {
// return (actual == .array and actual.array.items.len == 0);
// }

// if (actual != .object) {
// return false;
// }
// inline for (s.fields) |f| {
// const e = @field(expected, f.name);
// if (actual.object.get(f.name)) |a| {
// if (compareAnyToJsonValue(e, a) == false) {
// return false;
// }
// } else if (@typeInfo(f.type) != .Optional or e != null) {
// // We don't JSON serialize nulls. So if we're expecting
// // a null, that should show up as a missing field.
// return false;
// }
// }
// return true;
// },
// else => {},
// }
// @compileError("Can't compare " ++ @typeName(@TypeOf(expected)));
// }
Loading