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 BridgeAR committed Jan 3, 2020
1 parent 4292f64 commit 60dd183
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 @@ -595,9 +595,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 @@ -952,9 +952,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++) {
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 60dd183

Please sign in to comment.