Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: prevent hard coding stack trace limit #30752

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ void Environment::PrintSyncTrace() const {

fprintf(
stderr, "(node:%d) WARNING: Detected use of sync API\n", uv_os_getpid());
PrintStackTrace(
isolate(),
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed));
PrintStackTrace(isolate(),
StackTrace::CurrentStackTrace(
isolate(), stack_trace_limit(), StackTrace::kDetailed));
}

void Environment::RunCleanup() {
Expand Down Expand Up @@ -949,9 +949,9 @@ void Environment::Exit(int exit_code) {

fprintf(
stderr, "WARNING: Exited the environment with code %d\n", exit_code);
PrintStackTrace(
isolate(),
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed));
PrintStackTrace(isolate(),
StackTrace::CurrentStackTrace(
isolate(), stack_trace_limit(), StackTrace::kDetailed));
}
if (is_main_thread()) {
stop_sub_worker_contexts();
Expand Down
2 changes: 2 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,8 @@ class Environment : public MemoryRetainer {
inline void modify_base_object_count(int64_t delta);
inline int64_t base_object_count() const;

inline int32_t stack_trace_limit() const { return 10; }

#if HAVE_INSPECTOR
void set_coverage_connection(
std::unique_ptr<profiler::V8CoverageConnection> connection);
Expand Down
2 changes: 1 addition & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static std::string GetErrorSource(Isolate* isolate,
}

void PrintStackTrace(Isolate* isolate, Local<StackTrace> stack) {
for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
for (int i = 0; i < stack->GetFrameCount(); i++) {
lundibundi marked this conversation as resolved.
Show resolved Hide resolved
Local<StackFrame> stack_frame = stack->GetFrame(isolate, i);
node::Utf8Value fn_name_s(isolate, stack_frame->GetFunctionName());
node::Utf8Value script_name(isolate, stack_frame->GetScriptName());
Expand Down
1 change: 1 addition & 0 deletions test/message/throw_error_with_getter_throw_traced.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Thrown at:
at Module.load (internal/modules/cjs/loader.js:*:*)
at Module._load (internal/modules/cjs/loader.js:*:*)
at executeUserEntryPoint (internal/modules/run_main.js:*:*)
at internal/main/run_main_module.js:*:*
1 change: 1 addition & 0 deletions test/message/throw_null_traced.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Thrown at:
at Module.load (internal/modules/cjs/loader.js:*:*)
at Module._load (internal/modules/cjs/loader.js:*:*)
at executeUserEntryPoint (internal/modules/run_main.js:*:*)
at internal/main/run_main_module.js:*:*
1 change: 1 addition & 0 deletions test/message/throw_undefined_traced.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Thrown at:
at Module.load (internal/modules/cjs/loader.js:*:*)
at Module._load (internal/modules/cjs/loader.js:*:*)
at executeUserEntryPoint (internal/modules/run_main.js:*:*)
at internal/main/run_main_module.js:*:*