Skip to content

Commit 087a7b5

Browse files
committed
browser: use *const Page with fetchModule
1 parent 229844d commit 087a7b5

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/browser/browser.zig

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,17 @@ pub const Session = struct {
184184
_ = referrer;
185185

186186
const self: *Session = @ptrCast(@alignCast(ctx));
187-
188-
if (self.page == null) {
189-
return error.NoPage;
190-
}
187+
const page = &(self.page orelse return error.NoPage);
191188

192189
log.debug("fetch module: specifier: {s}", .{specifier});
193190
// fetchModule is called within the context of processing a page.
194191
// Use the page_arena for this, which has a more appropriate lifetime
195192
// and which has more retained memory between sessions and pages.
196193
const arena = self.browser.page_arena.allocator();
197-
const body = try self.page.?.fetchData(
194+
const body = try page.fetchData(
198195
arena,
199196
specifier,
200-
if (self.page.?.current_script) |s| s.src else null,
197+
if (page.current_script) |s| s.src else null,
201198
);
202199
return self.env.compileModule(body, specifier);
203200
}
@@ -605,7 +602,7 @@ pub const Page = struct {
605602
// It resolves src using the page's uri.
606603
// If a base path is given, src is resolved according to the base first.
607604
// the caller owns the returned string
608-
fn fetchData(self: *Page, arena: Allocator, src: []const u8, base: ?[]const u8) ![]const u8 {
605+
fn fetchData(self: *const Page, arena: Allocator, src: []const u8, base: ?[]const u8) ![]const u8 {
609606
log.debug("starting fetch {s}", .{src});
610607

611608
var buffer: [1024]u8 = undefined;
@@ -647,7 +644,7 @@ pub const Page = struct {
647644

648645
// fetchScript senf a GET request to the src and execute the script
649646
// received.
650-
fn fetchScript(self: *Page, s: *const Script) !void {
647+
fn fetchScript(self: *const Page, s: *const Script) !void {
651648
const arena = self.arena;
652649

653650
const body = try self.fetchData(arena, s.src, null);

0 commit comments

Comments
 (0)