Skip to content

Commit

Permalink
try_catch: check if the env is started before get it
Browse files Browse the repository at this point in the history
  • Loading branch information
krichprollsch committed Jul 19, 2024
1 parent e7fd4b1 commit 31d4b8c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/engines/v8/v8.zig
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ pub const TryCatch = struct {

// the caller needs to deinit the string returned
pub fn exception(self: TryCatch, alloc: std.mem.Allocator, env: Env) anyerror!?[]const u8 {
if (env.js_ctx == null) return error.EnvNotStarted;

if (self.inner.getException()) |msg| {
return try valueToUtf8(alloc, msg, env.isolate, env.js_ctx.?);
}
Expand All @@ -461,6 +463,8 @@ pub const TryCatch = struct {

// the caller needs to deinit the string returned
pub fn stack(self: TryCatch, alloc: std.mem.Allocator, env: Env) anyerror!?[]const u8 {
if (env.js_ctx == null) return error.EnvNotStarted;

const stck = self.inner.getStackTrace(env.js_ctx.?);
if (stck) |s| return try valueToUtf8(alloc, s, env.isolate, env.js_ctx.?);
return null;
Expand Down

0 comments on commit 31d4b8c

Please sign in to comment.