Skip to content
Permalink
Browse files

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 <anna@addaleax.net>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
legendecas authored and BridgeAR committed Dec 1, 2019
1 parent 4292f64 commit 60dd1838e9e19f5dbc69d1b947e21ecc5d3aa5e9
@@ -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() {
@@ -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();
@@ -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);
@@ -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());
@@ -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:*:*
@@ -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:*:*
@@ -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.
You can’t perform that action at this time.