From 3a9713bb5aa6fb90d16884be7e0c325a540329d8 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 2 Nov 2023 02:06:00 +0100 Subject: [PATCH] src: use v8::Isolate::TryGetCurrent() in DumpJavaScriptBacktrace() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was using Isolate::GetCurrent() which DCHECK on nullptr, even though what we wanted was to return early if it is nullptr. PR-URL: https://github.com/nodejs/node/pull/50518 Refs: https://github.com/nodejs/node/pull/50242 Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Juan José Arboleda Reviewed-By: Chengzhong Wu --- src/debug_utils.cc | 2 +- test/cctest/test_util.cc | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/debug_utils.cc b/src/debug_utils.cc index 26f2a96831c137..d3436c62079e6a 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc @@ -319,7 +319,7 @@ void DumpNativeBacktrace(FILE* fp) { } void DumpJavaScriptBacktrace(FILE* fp) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::TryGetCurrent(); if (isolate == nullptr) { return; } diff --git a/test/cctest/test_util.cc b/test/cctest/test_util.cc index 5b83e07db3b7c2..c48803cff0337e 100644 --- a/test/cctest/test_util.cc +++ b/test/cctest/test_util.cc @@ -299,3 +299,7 @@ TEST(UtilTest, SPrintF) { const std::string with_zero = std::string("a") + '\0' + 'b'; EXPECT_EQ(SPrintF("%s", with_zero), with_zero); } + +TEST(UtilTest, DumpJavaScriptStackWithNoIsolate) { + node::DumpJavaScriptBacktrace(stderr); +}