From ebb21cb07542f86c95490ec4078f7bdabfd29651 Mon Sep 17 00:00:00 2001 From: pollyzhang Date: Fri, 13 Jan 2023 10:53:12 +0800 Subject: [PATCH] fix(core): add handle_scope for v8 exception --- core/src/napi/v8/js_native_api_v8.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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;