Skip to content

Commit f72cbb7

Browse files
joyeecheungtargos
authored andcommitted
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 <[email protected]> Commit-Queue: Joyee Cheung <[email protected]> Cr-Commit-Position: refs/heads/main@{#90360} Refs: v8/v8@2590224 PR-URL: #50156 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]>
1 parent 35b160e commit f72cbb7

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.19',
39+
'v8_embedder_string': '-node.20',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/src/execution/isolate.cc

+1
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,7 @@ void Isolate::PrintCurrentStackTrace(std::ostream& out) {
24512451
for (int i = 0; i < frames->length(); ++i) {
24522452
Handle<CallSiteInfo> frame(CallSiteInfo::cast(frames->get(i)), this);
24532453
SerializeCallSiteInfo(this, frame, &builder);
2454+
if (i != frames->length() - 1) builder.AppendCharacter('\n');
24542455
}
24552456

24562457
Handle<String> stack_trace = builder.Finish().ToHandleChecked();

deps/v8/test/cctest/test-api.cc

+46
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <csignal>
3232
#include <map>
3333
#include <memory>
34+
#include <sstream>
3435
#include <string>
3536

3637
#include "test/cctest/cctest.h"
@@ -4869,6 +4870,51 @@ TEST(MessageGetSourceLine) {
48694870
});
48704871
}
48714872

4873+
void GetCurrentStackTrace(const v8::FunctionCallbackInfo<v8::Value>& args) {
4874+
std::stringstream ss;
4875+
v8::Message::PrintCurrentStackTrace(args.GetIsolate(), ss);
4876+
std::string str = ss.str();
4877+
args.GetReturnValue().Set(v8_str(str.c_str()));
4878+
}
4879+
4880+
THREADED_TEST(MessagePrintCurrentStackTrace) {
4881+
v8::Isolate* isolate = CcTest::isolate();
4882+
v8::HandleScope scope(isolate);
4883+
Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4884+
templ->Set(isolate, "getCurrentStackTrace",
4885+
v8::FunctionTemplate::New(isolate, GetCurrentStackTrace));
4886+
LocalContext context(nullptr, templ);
4887+
4888+
v8::ScriptOrigin origin = v8::ScriptOrigin(isolate, v8_str("test"), 0, 0);
4889+
v8::Local<v8::String> script = v8_str(
4890+
"function c() {\n"
4891+
" return getCurrentStackTrace();\n"
4892+
"}\n"
4893+
"function b() {\n"
4894+
" return c();\n"
4895+
"}\n"
4896+
"function a() {\n"
4897+
" return b();\n"
4898+
"}\n"
4899+
"a();");
4900+
v8::Local<v8::Value> stack_trace =
4901+
v8::Script::Compile(context.local(), script, &origin)
4902+
.ToLocalChecked()
4903+
->Run(context.local())
4904+
.ToLocalChecked();
4905+
4906+
CHECK(stack_trace->IsString());
4907+
v8::String::Utf8Value stack_trace_value(isolate,
4908+
stack_trace.As<v8::String>());
4909+
std::string stack_trace_string(*stack_trace_value);
4910+
std::string expected(
4911+
"c (test:2:10)\n"
4912+
"b (test:5:10)\n"
4913+
"a (test:8:10)\n"
4914+
"test:10:1");
4915+
CHECK_EQ(stack_trace_string, expected);
4916+
}
4917+
48724918
THREADED_TEST(GetSetProperty) {
48734919
LocalContext context;
48744920
v8::Isolate* isolate = context->GetIsolate();

0 commit comments

Comments
 (0)