From 00de2faf784718c5218100c9897401804f6502fc Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 16 Oct 2023 00:30:13 +0800 Subject: [PATCH] deps: V8: cherry-pick 25902244ad1a Original commit message: [api] add line breaks to the output of Message::PrintCurrentStackTrace Previously this prints the stack trace without line breaks and it can be difficult to read. This also affects --abort-on-uncaught-exception. This patch adds line breaks to the output to improve readability. Change-Id: I4c44b529f8c829329f784b0859b1d13c9ec56838 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4925009 Reviewed-by: Leszek Swirski Commit-Queue: Joyee Cheung Cr-Commit-Position: refs/heads/main@{#90360} Refs: https://github.com/v8/v8/commit/25902244ad1aa5ad7c7e5c85d6b0afae4e878536 PR-URL: https://github.com/nodejs/node/pull/50156 Reviewed-By: Jiawen Geng Reviewed-By: Debadree Chatterjee --- common.gypi | 2 +- deps/v8/src/execution/isolate.cc | 1 + deps/v8/test/cctest/test-api.cc | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 071a27afc2fd59..4c62386f4e8fce 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.12', + 'v8_embedder_string': '-node.13', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/execution/isolate.cc b/deps/v8/src/execution/isolate.cc index e7232e5c1fd50d..cbe353e95f5584 100644 --- a/deps/v8/src/execution/isolate.cc +++ b/deps/v8/src/execution/isolate.cc @@ -2503,6 +2503,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 6c80599b571793..fa6901159a2bd5 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" @@ -4926,6 +4927,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();