replace zig-js-runtime

This commit is contained in:
Karl Seguin
2025-04-02 10:30:59 +08:00
parent 25dcae7648
commit b8d7744563
88 changed files with 5933 additions and 4124 deletions

View File

@@ -17,9 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const parser = @import("netsurf");
const Allocator = std.mem.Allocator;
const parser = @import("../browser/netsurf.zig");
pub const Id = u32;
const log = std.log.scoped(.cdp_node);

View File

@@ -72,13 +72,16 @@ pub fn CDPT(comptime TypeProvider: type) type {
pub const Browser = TypeProvider.Browser;
pub const Session = TypeProvider.Session;
pub fn init(app: *App, client: TypeProvider.Client) Self {
pub fn init(app: *App, client: TypeProvider.Client) !Self {
const allocator = app.allocator;
const browser = try Browser.init(app);
errdefer browser.deinit();
return .{
.client = client,
.browser = browser,
.allocator = allocator,
.browser_context = null,
.browser = Browser.init(app),
.message_arena = std.heap.ArenaAllocator.init(allocator),
.browser_context_pool = std.heap.MemoryPool(BrowserContext(Self)).init(allocator),
};

View File

@@ -17,10 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const parser = @import("netsurf");
const Node = @import("../Node.zig");
const css = @import("../../dom/css.zig");
const dom_node = @import("../../dom/node.zig");
const css = @import("../../browser/dom/css.zig");
const parser = @import("../../browser/netsurf.zig");
const dom_node = @import("../../browser/dom/node.zig");
pub fn processMessage(cmd: anytype) !void {
const action = std.meta.stringToEnum(enum {
@@ -134,17 +134,20 @@ fn resolveNode(cmd: anytype) !void {
// node._node is a *parser.Node we need this to be able to find its most derived type e.g. Node -> Element -> HTMLElement
// So we use the Node.Union when retrieve the value from the environment
const jsValue = try bc.session.env.findOrAddValue(try dom_node.Node.toInterface(node._node));
const remoteObject = try bc.session.inspector.getRemoteObject(&bc.session.env, jsValue, params.objectGroup orelse "");
defer remoteObject.deinit();
const remote_object = try bc.session.inspector.getRemoteObject(
bc.session.executor,
params.objectGroup orelse "",
try dom_node.Node.toInterface(node._node),
);
defer remote_object.deinit();
const arena = cmd.arena;
return cmd.sendResult(.{ .object = .{
.type = try remoteObject.getType(arena),
.subtype = try remoteObject.getSubtype(arena),
.className = try remoteObject.getClassName(arena),
.description = try remoteObject.getDescription(arena),
.objectId = try remoteObject.getObjectId(arena),
.type = try remote_object.getType(arena),
.subtype = try remote_object.getSubtype(arena),
.className = try remote_object.getClassName(arena),
.description = try remote_object.getDescription(arena),
.objectId = try remote_object.getObjectId(arena),
} }, .{});
}

View File

@@ -23,9 +23,9 @@ const Allocator = std.mem.Allocator;
const Testing = @This();
const main = @import("cdp.zig");
const parser = @import("netsurf");
const URL = @import("../url.zig").URL;
const App = @import("../app.zig").App;
const parser = @import("../browser/netsurf.zig");
const base = @import("../testing.zig");
pub const allocator = base.allocator;
@@ -40,7 +40,7 @@ const Browser = struct {
session: ?*Session = null,
arena: std.heap.ArenaAllocator,
pub fn init(app: *App) Browser {
pub fn init(app: *App) !Browser {
return .{
.arena = std.heap.ArenaAllocator.init(app.allocator),
};
@@ -61,8 +61,8 @@ const Browser = struct {
self.session.?.* = .{
.page = null,
.arena = arena,
.env = Env{},
.inspector = Inspector{},
.executor = .{},
.inspector = .{},
};
return self.session.?;
}
@@ -78,7 +78,7 @@ const Browser = struct {
const Session = struct {
page: ?Page = null,
arena: Allocator,
env: Env,
executor: Executor,
inspector: Inspector,
pub fn currentPage(self: *Session) ?*Page {
@@ -107,19 +107,19 @@ const Session = struct {
}
};
const Env = struct {
pub fn findOrAddValue(self: *Env, value: anytype) !@TypeOf(value) { // ?
_ = self;
return value;
}
};
const Executor = struct {};
const Inspector = struct {
pub fn getRemoteObject(self: Inspector, env: *Env, jsValue: anytype, groupName: []const u8) !RemoteObject {
pub fn getRemoteObject(
self: *const Inspector,
executor: Executor,
group: []const u8,
value: anytype,
) !RemoteObject {
_ = self;
_ = env;
_ = jsValue;
_ = groupName;
_ = executor;
_ = group;
_ = value;
return RemoteObject{};
}
};
@@ -217,7 +217,7 @@ const TestContext = struct {
self.client = Client.init(self.arena.allocator());
// Don't use the arena here. We want to detect leaks in CDP.
// The arena is only for test-specific stuff
self.cdp_ = TestCDP.init(self.app, &self.client.?);
self.cdp_ = try TestCDP.init(self.app, &self.client.?);
}
return &self.cdp_.?;
}