Skip to content
Merged
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
8 changes: 8 additions & 0 deletions src/runtime/js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,11 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
specifier: []const u8,
module: v8.Persistent(v8.Module),
resolver: v8.Persistent(v8.PromiseResolver),

pub fn deinit(ev: *@This()) void {
ev.module.deinit();
ev.resolver.deinit();
}
};

const ev_data = try self.context_arena.create(EvaluationData);
Expand All @@ -1684,6 +1689,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
const cb_isolate = cb_info.getIsolate();
const cb_context = cb_isolate.getCurrentContext();
const data: *EvaluationData = @ptrCast(@alignCast(cb_info.getExternalValue()));
defer data.deinit();
const cb_module = data.module.castToModule();
const cb_resolver = data.resolver.castToPromiseResolver();

Expand All @@ -1698,6 +1704,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
const cb_info = v8.FunctionCallbackInfo{ .handle = info.? };
const cb_context = cb_info.getIsolate().getCurrentContext();
const data: *EvaluationData = @ptrCast(@alignCast(cb_info.getExternalValue()));
defer data.deinit();
const cb_resolver = data.resolver.castToPromiseResolver();

log.err(.js, "dynamic import failed", .{ .specifier = data.specifier });
Expand All @@ -1710,6 +1717,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
.specifier = specifier,
.line = try_catch.sourceLineNumber() orelse 0,
});
defer ev_data.deinit();
const error_msg = v8.String.initUtf8(iso, "Evaluation is a promise");
_ = resolver.reject(ctx, error_msg.toValue());
return;
Expand Down