diff --git a/core/src/napi/v8/js_native_api_v8.cc b/core/src/napi/v8/js_native_api_v8.cc index 9fffe919a34..5004741c480 100644 --- a/core/src/napi/v8/js_native_api_v8.cc +++ b/core/src/napi/v8/js_native_api_v8.cc @@ -340,8 +340,12 @@ void V8TryCatch::SetVerbose(bool verbose) { std::shared_ptr V8TryCatch::Exception() { if (try_catch_) { - v8::Local exception = try_catch_->Exception(); - std::shared_ptr v8_ctx = std::static_pointer_cast(ctx_); + TDF_BASE_CHECK(ctx_); + auto v8_ctx = std::static_pointer_cast(ctx_); + v8::HandleScope handle_scope(v8_ctx->isolate_); + auto context = v8_ctx->context_persistent_.Get(v8_ctx->isolate_); + v8::Context::Scope context_scope(context); + auto exception = try_catch_->Exception(); return std::make_shared(v8_ctx->isolate_, exception); } return nullptr;