diff --git a/common.gypi b/common.gypi index 1b7eb92b89b34b..52636bb2fac590 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.19', + 'v8_embedder_string': '-node.20', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/execution/isolate.cc b/deps/v8/src/execution/isolate.cc index 1c63f0c56bf719..3c62ba5a5caef9 100644 --- a/deps/v8/src/execution/isolate.cc +++ b/deps/v8/src/execution/isolate.cc @@ -2451,6 +2451,7 @@ void Isolate::PrintCurrentStackTrace(std::ostream& out) { for (int i = 0; i < frames->length(); ++i) { Handle frame(CallSiteInfo::cast(frames->get(i)), this); SerializeCallSiteInfo(this, frame, &builder); + if (i != frames->length() - 1) builder.AppendCharacter('\n'); } Handle stack_trace = builder.Finish().ToHandleChecked(); diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index af7dfbf03ce2d8..6d83d9a4327598 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "test/cctest/cctest.h" @@ -4869,6 +4870,51 @@ TEST(MessageGetSourceLine) { }); } +void GetCurrentStackTrace(const v8::FunctionCallbackInfo& args) { + std::stringstream ss; + v8::Message::PrintCurrentStackTrace(args.GetIsolate(), ss); + std::string str = ss.str(); + args.GetReturnValue().Set(v8_str(str.c_str())); +} + +THREADED_TEST(MessagePrintCurrentStackTrace) { + v8::Isolate* isolate = CcTest::isolate(); + v8::HandleScope scope(isolate); + Local templ = ObjectTemplate::New(isolate); + templ->Set(isolate, "getCurrentStackTrace", + v8::FunctionTemplate::New(isolate, GetCurrentStackTrace)); + LocalContext context(nullptr, templ); + + v8::ScriptOrigin origin = v8::ScriptOrigin(isolate, v8_str("test"), 0, 0); + v8::Local script = v8_str( + "function c() {\n" + " return getCurrentStackTrace();\n" + "}\n" + "function b() {\n" + " return c();\n" + "}\n" + "function a() {\n" + " return b();\n" + "}\n" + "a();"); + v8::Local stack_trace = + v8::Script::Compile(context.local(), script, &origin) + .ToLocalChecked() + ->Run(context.local()) + .ToLocalChecked(); + + CHECK(stack_trace->IsString()); + v8::String::Utf8Value stack_trace_value(isolate, + stack_trace.As()); + std::string stack_trace_string(*stack_trace_value); + std::string expected( + "c (test:2:10)\n" + "b (test:5:10)\n" + "a (test:8:10)\n" + "test:10:1"); + CHECK_EQ(stack_trace_string, expected); +} + THREADED_TEST(GetSetProperty) { LocalContext context; v8::Isolate* isolate = context->GetIsolate();