Skip to content

Commit 943047e

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 <leszeks@chromium.org> Commit-Queue: Joyee Cheung <joyee@igalia.com> Cr-Commit-Position: refs/heads/main@{#90360} Refs: v8/v8@2590224 PR-URL: #50156 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
1 parent bf7b94f commit 943047e

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.12',
39+
'v8_embedder_string': '-node.13',
4040

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

deps/v8/src/execution/isolate.cc

+1
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,7 @@ void Isolate::PrintCurrentStackTrace(std::ostream& out) {
25032503
for (int i = 0; i < frames->length(); ++i) {
25042504
Handle<CallSiteInfo> frame(CallSiteInfo::cast(frames->get(i)), this);
25052505
SerializeCallSiteInfo(this, frame, &builder);
2506+
if (i != frames->length() - 1) builder.AppendCharacter('\n');
25062507
}
25072508

25082509
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"
@@ -4926,6 +4927,51 @@ TEST(MessageGetSourceLine) {
49264927
});
49274928
}
49284929

4930+
void GetCurrentStackTrace(const v8::FunctionCallbackInfo<v8::Value>& args) {
4931+
std::stringstream ss;
4932+
v8::Message::PrintCurrentStackTrace(args.GetIsolate(), ss);
4933+
std::string str = ss.str();
4934+
args.GetReturnValue().Set(v8_str(str.c_str()));
4935+
}
4936+
4937+
THREADED_TEST(MessagePrintCurrentStackTrace) {
4938+
v8::Isolate* isolate = CcTest::isolate();
4939+
v8::HandleScope scope(isolate);
4940+
Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4941+
templ->Set(isolate, "getCurrentStackTrace",
4942+
v8::FunctionTemplate::New(isolate, GetCurrentStackTrace));
4943+
LocalContext context(nullptr, templ);
4944+
4945+
v8::ScriptOrigin origin = v8::ScriptOrigin(isolate, v8_str("test"), 0, 0);
4946+
v8::Local<v8::String> script = v8_str(
4947+
"function c() {\n"
4948+
" return getCurrentStackTrace();\n"
4949+
"}\n"
4950+
"function b() {\n"
4951+
" return c();\n"
4952+
"}\n"
4953+
"function a() {\n"
4954+
" return b();\n"
4955+
"}\n"
4956+
"a();");
4957+
v8::Local<v8::Value> stack_trace =
4958+
v8::Script::Compile(context.local(), script, &origin)
4959+
.ToLocalChecked()
4960+
->Run(context.local())
4961+
.ToLocalChecked();
4962+
4963+
CHECK(stack_trace->IsString());
4964+
v8::String::Utf8Value stack_trace_value(isolate,
4965+
stack_trace.As<v8::String>());
4966+
std::string stack_trace_string(*stack_trace_value);
4967+
std::string expected(
4968+
"c (test:2:10)\n"
4969+
"b (test:5:10)\n"
4970+
"a (test:8:10)\n"
4971+
"test:10:1");
4972+
CHECK_EQ(stack_trace_string, expected);
4973+
}
4974+
49294975
THREADED_TEST(GetSetProperty) {
49304976
LocalContext context;
49314977
v8::Isolate* isolate = context->GetIsolate();

0 commit comments

Comments
 (0)