Skip to content

Commit 766f979

Browse files
committed
browser: load module
1 parent 680d634 commit 766f979

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/browser/browser.zig

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ pub const Page = struct {
407407
// ignore non-js script.
408408
const script = try Script.init(e) orelse continue;
409409
if (script.kind == .unknown) continue;
410-
if (script.kind == .module) continue;
411410

412411
// Ignore the defer attribute b/c we analyze all script
413412
// after the document has been parsed.
@@ -596,23 +595,21 @@ pub const Page = struct {
596595
fn kind(stype: ?[]const u8) Kind {
597596
if (stype == null or stype.?.len == 0) return .javascript;
598597
if (std.mem.eql(u8, stype.?, "application/javascript")) return .javascript;
599-
if (!std.mem.eql(u8, stype.?, "module")) return .module;
598+
if (std.mem.eql(u8, stype.?, "module")) return .module;
600599

601600
return .unknown;
602601
}
603602

604603
fn eval(self: Script, alloc: std.mem.Allocator, env: Env, body: []const u8) !void {
605-
switch (self.kind) {
606-
.unknown => return error.UnknownScript,
607-
.javascript => {},
608-
.module => {},
609-
}
610-
611604
var try_catch: jsruntime.TryCatch = undefined;
612605
try_catch.init(env);
613606
defer try_catch.deinit();
614607

615-
const res = env.exec(body, self.src) catch {
608+
const res = switch (self.kind) {
609+
.unknown => return error.UnknownScript,
610+
.javascript => env.exec(body, self.src),
611+
.module => env.module(body, self.src),
612+
} catch {
616613
if (try try_catch.err(alloc, env)) |msg| {
617614
defer alloc.free(msg);
618615
log.info("eval script {s}: {s}", .{ self.src, msg });

0 commit comments

Comments
 (0)