src: use v8::Isolate::TryGetCurrent() in DumpJavaScriptBacktrace()

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 <contact@viniciusl.com.br>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
Joyee Cheung authored and Michaël Zasso committed 2023-11-14 09:17:55 +01:00
1 parent aa8feea5f1
commit b740324f7c
2 files changed
+5 -1

No files matched your search

+1 -1
View File
@@ -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;
}
+4
View File
@@ -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);
}