Skip to content

Commit ade128f

Browse files
Merge pull request #244 from lightpanda-io/trycatch-env-not-started
try_catch: check if the env is started before get it
2 parents a486251 + 31d4b8c commit ade128f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/engines/v8/v8.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ pub const TryCatch = struct {
453453

454454
// the caller needs to deinit the string returned
455455
pub fn exception(self: TryCatch, alloc: std.mem.Allocator, env: Env) anyerror!?[]const u8 {
456+
if (env.js_ctx == null) return error.EnvNotStarted;
457+
456458
if (self.inner.getException()) |msg| {
457459
return try valueToUtf8(alloc, msg, env.isolate, env.js_ctx.?);
458460
}
@@ -461,6 +463,8 @@ pub const TryCatch = struct {
461463

462464
// the caller needs to deinit the string returned
463465
pub fn stack(self: TryCatch, alloc: std.mem.Allocator, env: Env) anyerror!?[]const u8 {
466+
if (env.js_ctx == null) return error.EnvNotStarted;
467+
464468
const stck = self.inner.getStackTrace(env.js_ctx.?);
465469
if (stck) |s| return try valueToUtf8(alloc, s, env.isolate, env.js_ctx.?);
466470
return null;

0 commit comments

Comments
 (0)