Skip to content

Commit 60dd183

Browse files
legendecasBridgeAR
authored andcommitted
src: prevent hard coding stack trace limit
Refer to Environment::stack_trace_limit() while printing fresh stacktraces in c++ land. PR-URL: #30752 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 4292f64 commit 60dd183

6 files changed

+12
-7
lines changed

src/env.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,9 @@ void Environment::PrintSyncTrace() const {
595595

596596
fprintf(
597597
stderr, "(node:%d) WARNING: Detected use of sync API\n", uv_os_getpid());
598-
PrintStackTrace(
599-
isolate(),
600-
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed));
598+
PrintStackTrace(isolate(),
599+
StackTrace::CurrentStackTrace(
600+
isolate(), stack_trace_limit(), StackTrace::kDetailed));
601601
}
602602

603603
void Environment::RunCleanup() {
@@ -952,9 +952,9 @@ void Environment::Exit(int exit_code) {
952952

953953
fprintf(
954954
stderr, "WARNING: Exited the environment with code %d\n", exit_code);
955-
PrintStackTrace(
956-
isolate(),
957-
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed));
955+
PrintStackTrace(isolate(),
956+
StackTrace::CurrentStackTrace(
957+
isolate(), stack_trace_limit(), StackTrace::kDetailed));
958958
}
959959
if (is_main_thread()) {
960960
stop_sub_worker_contexts();

src/env.h

+2
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,8 @@ class Environment : public MemoryRetainer {
12311231
inline void modify_base_object_count(int64_t delta);
12321232
inline int64_t base_object_count() const;
12331233

1234+
inline int32_t stack_trace_limit() const { return 10; }
1235+
12341236
#if HAVE_INSPECTOR
12351237
void set_coverage_connection(
12361238
std::unique_ptr<profiler::V8CoverageConnection> connection);

src/node_errors.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static std::string GetErrorSource(Isolate* isolate,
145145
}
146146

147147
void PrintStackTrace(Isolate* isolate, Local<StackTrace> stack) {
148-
for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
148+
for (int i = 0; i < stack->GetFrameCount(); i++) {
149149
Local<StackFrame> stack_frame = stack->GetFrame(isolate, i);
150150
node::Utf8Value fn_name_s(isolate, stack_frame->GetFunctionName());
151151
node::Utf8Value script_name(isolate, stack_frame->GetScriptName());

test/message/throw_error_with_getter_throw_traced.out

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Thrown at:
1010
at Module.load (internal/modules/cjs/loader.js:*:*)
1111
at Module._load (internal/modules/cjs/loader.js:*:*)
1212
at executeUserEntryPoint (internal/modules/run_main.js:*:*)
13+
at internal/main/run_main_module.js:*:*

test/message/throw_null_traced.out

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Thrown at:
1010
at Module.load (internal/modules/cjs/loader.js:*:*)
1111
at Module._load (internal/modules/cjs/loader.js:*:*)
1212
at executeUserEntryPoint (internal/modules/run_main.js:*:*)
13+
at internal/main/run_main_module.js:*:*

test/message/throw_undefined_traced.out

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Thrown at:
1010
at Module.load (internal/modules/cjs/loader.js:*:*)
1111
at Module._load (internal/modules/cjs/loader.js:*:*)
1212
at executeUserEntryPoint (internal/modules/run_main.js:*:*)
13+
at internal/main/run_main_module.js:*:*

0 commit comments

Comments
 (0)