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
14 changes: 13 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ pub fn build(b: *std.Build) !void {
b.option([]const u8, "git_commit", "Current git commit") orelse "dev",
);

opts.addOption(
std.log.Level,
"log_level",
b.option(std.log.Level, "log_level", "The log level") orelse std.log.Level.info,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about defaulting to .debug if build.mode == debug?

Copy link
Collaborator Author

@karlseguin karlseguin May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the noise to signal ratio is too low right now. The point of the flag is to let everyone set it to whatever they want, without having to touch the source. So the default can be anything.

);

opts.addOption(
bool,
"log_unknown_properties",
b.option(bool, "log_unknown_properties", "Log access to unknown properties") orelse false,
);

const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

Expand Down Expand Up @@ -175,7 +187,7 @@ fn common(b: *std.Build, opts: *std.Build.Step.Options, step: *std.Build.Step.Co
else => {},
}

mod.addImport("build_info", opts.createModule());
mod.addImport("build_config", opts.createModule());
mod.addObjectFile(mod.owner.path(lib_path));
}

Expand Down
6 changes: 1 addition & 5 deletions src/browser/page.zig
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,7 @@ pub const Page = struct {
}
return error.JsErr;
};

if (builtin.mode == .Debug) {
const msg = try res.toString(page.arena);
log.debug("eval script {s}: {s}", .{ src, msg });
}
_ = res;

if (self.onload) |onload| {
_ = page.scope.exec(onload, "script_on_load") catch {
Expand Down
6 changes: 3 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const App = @import("app.zig").App;
const Platform = @import("runtime/js.zig").Platform;
const Browser = @import("browser/browser.zig").Browser;

const build_config = @import("build_config");
const parser = @import("browser/netsurf.zig");
const version = @import("build_info").git_commit;

const log = std.log.scoped(.cli);

pub const std_options = std.Options{
// Set the log level to info
.log_level = .info,
.log_level = @enumFromInt(@intFromEnum(build_config.log_level)),

// Define logFn to override the std implementation
.logFn = logFn,
Expand All @@ -59,7 +59,7 @@ pub fn main() !void {
return std.process.cleanExit();
},
.version => {
std.debug.print("{s}\n", .{version});
std.debug.print("{s}\n", .{build_config.git_commit});
return std.process.cleanExit();
},
else => {},
Expand Down
28 changes: 28 additions & 0 deletions src/runtime/js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {

fn generateNamedIndexer(comptime Struct: type, template_proto: v8.ObjectTemplate) void {
if (@hasDecl(Struct, "named_get") == false) {
if (comptime @import("build_config").log_unknown_properties) {
generateDebugNamedIndexer(Struct, template_proto);
}
return;
}
const configuration = v8.NamedPropertyHandlerConfiguration{
Expand Down Expand Up @@ -1441,6 +1444,31 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
template_proto.setNamedProperty(configuration, null);
}

fn generateDebugNamedIndexer(comptime Struct: type, template_proto: v8.ObjectTemplate) void {
const configuration = v8.NamedPropertyHandlerConfiguration{
.getter = struct {
fn callback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 {
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
const isolate = info.getIsolate();
const context = isolate.getCurrentContext();

const scope: *Scope = @ptrFromInt(context.getEmbedderData(1).castTo(v8.BigInt).getUint64());

const property = valueToString(scope.call_arena, .{ .handle = c_name.? }, isolate, context) catch "???";
log.debug("unknwon named property {s}.{s}", .{ @typeName(Struct), property });
return v8.Intercepted.No;
}
}.callback,

// This is really cool. Without this, we'd intercept _all_ properties
// even those explicitly set. So, node.length for example would get routed
// to our `named_get`, rather than a `get_length`. This might be
// useful if we run into a type that we can't model properly in Zig.
.flags = v8.PropertyHandlerFlags.OnlyInterceptStrings | v8.PropertyHandlerFlags.NonMasking,
};
template_proto.setNamedProperty(configuration, null);
}

fn generateUndetectable(comptime Struct: type, template: v8.ObjectTemplate) void {
const has_js_call_as_function = @hasDecl(Struct, "jsCallAsFunction");

Expand Down
4 changes: 2 additions & 2 deletions src/telemetry/lightpanda.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const build_info = @import("build_info");
const build_config = @import("build_config");

const Thread = std.Thread;
const Allocator = std.mem.Allocator;
Expand Down Expand Up @@ -151,7 +151,7 @@ const LightPandaEvent = struct {
try writer.write(builtin.cpu.arch);

try writer.objectField("version");
try writer.write(build_info.git_commit);
try writer.write(build_config.git_commit);

try writer.objectField("event");
try writer.write(@tagName(std.meta.activeTag(self.event)));
Expand Down