Skip to content

Commit ab77cb8

Browse files
committed
log module specifier on dynamic import stages
1 parent 4c3673f commit ab77cb8

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/runtime/js.zig

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,8 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
776776
pub fn module(self: *JsContext, src: []const u8, url: []const u8, cacheable: bool) !?v8.Promise {
777777
const arena = self.context_arena;
778778

779-
if (cacheable) {
780-
const value = self.module_cache.get(url);
781-
if (value != null) return null;
779+
if (cacheable and self.module_cache.contains(url)) {
780+
return null;
782781
}
783782
errdefer _ = self.module_cache.remove(url);
784783

@@ -789,7 +788,11 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
789788
errdefer _ = self.module_identifier.remove(m.getIdentityHash());
790789

791790
if (cacheable) {
792-
try self.module_cache.put(arena, owned_url, PersistentModule.init(self.isolate, m));
791+
try self.module_cache.putNoClobber(
792+
arena,
793+
owned_url,
794+
PersistentModule.init(self.isolate, m),
795+
);
793796
}
794797

795798
// resolveModuleCallback loads module's dependencies.
@@ -1561,14 +1564,14 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
15611564
}
15621565

15631566
fn _dynamicModuleCallback(
1564-
context: *JsContext,
1567+
self: *JsContext,
15651568
specifier: []const u8,
15661569
resolver: *const v8.PromiseResolver,
15671570
) !void {
1568-
const iso = context.isolate;
1569-
const ctx = context.v8_context;
1571+
const iso = self.isolate;
1572+
const ctx = self.v8_context;
15701573

1571-
const module_loader = context.module_loader;
1574+
const module_loader = self.module_loader;
15721575
const source = module_loader.func(module_loader.ptr, specifier) catch {
15731576
const error_msg = v8.String.initUtf8(iso, "Failed to load module");
15741577
_ = resolver.reject(ctx, error_msg.toValue());
@@ -1580,34 +1583,36 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
15801583
};
15811584

15821585
var try_catch: TryCatch = undefined;
1583-
try_catch.init(context);
1586+
try_catch.init(self);
15841587
defer try_catch.deinit();
15851588

1586-
const maybe_promise = context.module(source, specifier, true) catch {
1589+
const maybe_promise = self.module(source, specifier, true) catch {
15871590
log.err(.js, "module compilation failed", .{
15881591
.specifier = specifier,
1589-
.exception = try_catch.exception(context.call_arena) catch "unknown error",
1590-
.stack = try_catch.stack(context.call_arena) catch null,
1592+
.exception = try_catch.exception(self.call_arena) catch "unknown error",
1593+
.stack = try_catch.stack(self.call_arena) catch null,
15911594
.line = try_catch.sourceLineNumber() orelse 0,
15921595
});
15931596
const error_msg = if (try_catch.hasCaught()) blk: {
1594-
const exception_str = try_catch.exception(context.call_arena) catch "Evaluation error";
1597+
const exception_str = try_catch.exception(self.call_arena) catch "Evaluation error";
15951598
break :blk v8.String.initUtf8(iso, exception_str orelse "Evaluation error");
15961599
} else v8.String.initUtf8(iso, "Module evaluation failed");
15971600
_ = resolver.reject(ctx, error_msg.toValue());
15981601
return;
15991602
};
1600-
const new_module = context.module_cache.get(specifier).?.castToModule();
1603+
const new_module = self.module_cache.get(specifier).?.castToModule();
16011604

16021605
if (maybe_promise) |promise| {
16031606
// This means we must wait for the evaluation.
16041607
const EvaluationData = struct {
1608+
specifier: []const u8,
16051609
module: v8.Persistent(v8.Module),
16061610
resolver: v8.Persistent(v8.PromiseResolver),
16071611
};
16081612

1609-
const ev_data = try context.context_arena.create(EvaluationData);
1613+
const ev_data = try self.context_arena.create(EvaluationData);
16101614
ev_data.* = .{
1615+
.specifier = specifier,
16111616
.module = v8.Persistent(v8.Module).init(iso, new_module),
16121617
.resolver = v8.Persistent(v8.PromiseResolver).init(iso, resolver.*),
16131618
};
@@ -1623,10 +1628,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
16231628
const cb_resolver = data.resolver.castToPromiseResolver();
16241629

16251630
const namespace = cb_module.getModuleNamespace();
1626-
log.info(.js, "dynamic import complete", .{
1627-
.module = cb_module,
1628-
.namespace = namespace,
1629-
});
1631+
log.info(.js, "dynamic import complete", .{ .specifier = data.specifier });
16301632
_ = cb_resolver.resolve(cb_context, namespace);
16311633
}
16321634
}.callback, external);
@@ -1636,12 +1638,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
16361638
const cb_info = v8.FunctionCallbackInfo{ .handle = info.? };
16371639
const cb_context = cb_info.getIsolate().getCurrentContext();
16381640
const data: *EvaluationData = @ptrCast(@alignCast(cb_info.getExternalValue()));
1639-
const cb_module = data.module.castToModule();
16401641
const cb_resolver = data.resolver.castToPromiseResolver();
16411642

1642-
log.err(.js, "dynamic import failed", .{
1643-
.module = cb_module,
1644-
});
1643+
log.err(.js, "dynamic import failed", .{ .specifier = data.specifier });
16451644
_ = cb_resolver.reject(cb_context, cb_info.getData());
16461645
}
16471646
}.callback, external);

0 commit comments

Comments
 (0)