Skip to content

Commit

Permalink
deps: V8: cherry-pick 25902244ad1a
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joyeecheung authored and targos committed Oct 23, 2023
1 parent bf7b94f commit 943047e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####

Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/execution/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,7 @@ void Isolate::PrintCurrentStackTrace(std::ostream& out) {
for (int i = 0; i < frames->length(); ++i) {
Handle<CallSiteInfo> frame(CallSiteInfo::cast(frames->get(i)), this);
SerializeCallSiteInfo(this, frame, &builder);
if (i != frames->length() - 1) builder.AppendCharacter('\n');
}

Handle<String> stack_trace = builder.Finish().ToHandleChecked();
Expand Down
46 changes: 46 additions & 0 deletions deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <csignal>
#include <map>
#include <memory>
#include <sstream>
#include <string>

#include "test/cctest/cctest.h"
Expand Down Expand Up @@ -4926,6 +4927,51 @@ TEST(MessageGetSourceLine) {
});
}

void GetCurrentStackTrace(const v8::FunctionCallbackInfo<v8::Value>& 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<ObjectTemplate> 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<v8::String> 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<v8::Value> 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<v8::String>());
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();
Expand Down

0 comments on commit 943047e

Please sign in to comment.