Skip to content

Commit

Permalink
src: prevent hard coding stack trace limit
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
legendecas authored and BethGriggs committed Feb 6, 2020
1 parent f86862a commit a4c7eba
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,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 @@ -943,9 +943,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 @@ -1230,6 +1230,8 @@ class Environment : public MemoryRetainer {

inline AsyncRequest* thread_stopper() { return &thread_stopper_; }

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++) {
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:*:*

0 comments on commit a4c7eba

Please sign in to comment.