| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a57c8ba commit b229083
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -458,6 +458,10 @@ inline double Environment::get_default_trigger_async_id() { | |||
| 458 | 458 | return default_trigger_async_id; | |
| 459 | 459 | } | |
| 460 | 460 | ||
| 461 | + inline int64_t Environment::stack_trace_limit() const { | ||
| 462 | + return isolate_data_->options()->stack_trace_limit; | ||
| 463 | + } | ||
| 464 | + | ||
| 461 | 465 | inline std::shared_ptr<EnvironmentOptions> Environment::options() { | |
| 462 | 466 | return options_; | |
| 463 | 467 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1252,9 +1252,11 @@ void Environment::PrintSyncTrace() const { | |||
| 1252 | 1252 | ||
| 1253 | 1253 | fprintf( | |
| 1254 | 1254 | stderr, "(node:%d) WARNING: Detected use of sync API\n", uv_os_getpid()); | |
| 1255 | - PrintStackTrace(isolate(), | ||
| 1256 | - StackTrace::CurrentStackTrace( | ||
| 1257 | - isolate(), stack_trace_limit(), StackTrace::kDetailed)); | ||
| 1255 | + PrintStackTrace( | ||
| 1256 | + isolate(), | ||
| 1257 | + StackTrace::CurrentStackTrace(isolate(), | ||
| 1258 | + static_cast<int>(stack_trace_limit()), | ||
| 1259 | + StackTrace::kDetailed)); | ||
| 1258 | 1260 | } | |
| 1259 | 1261 | ||
| 1260 | 1262 | MaybeLocal<Value> Environment::RunSnapshotSerializeCallback() const { | |
@@ -1856,9 +1858,11 @@ void Environment::Exit(ExitCode exit_code) { | |||
| 1856 | 1858 | fprintf(stderr, | |
| 1857 | 1859 | "WARNING: Exited the environment with code %d\n", | |
| 1858 | 1860 | static_cast<int>(exit_code)); | |
| 1859 | - PrintStackTrace(isolate(), | ||
| 1860 | - StackTrace::CurrentStackTrace( | ||
| 1861 | - isolate(), stack_trace_limit(), StackTrace::kDetailed)); | ||
| 1861 | + PrintStackTrace( | ||
| 1862 | + isolate(), | ||
| 1863 | + StackTrace::CurrentStackTrace(isolate(), | ||
| 1864 | + static_cast<int>(stack_trace_limit()), | ||
| 1865 | + StackTrace::kDetailed)); | ||
| 1862 | 1866 | } | |
| 1863 | 1867 | process_exit_handler_(this, exit_code); | |
| 1864 | 1868 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -981,7 +981,7 @@ class Environment final : public MemoryRetainer { | |||
| 981 | 981 | inline std::shared_ptr<EnvironmentOptions> options(); | |
| 982 | 982 | inline std::shared_ptr<ExclusiveAccess<HostPort>> inspector_host_port(); | |
| 983 | 983 | ||
| 984 | - inline int32_t stack_trace_limit() const { return 10; } | ||
| 984 | + inline int64_t stack_trace_limit() const; | ||
| 985 | 985 | ||
| 986 | 986 | #if HAVE_INSPECTOR | |
| 987 | 987 | void set_coverage_connection( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -447,9 +447,14 @@ void OptionsParser<Options>::Parse( | |||
| 447 | 447 | case kBoolean: | |
| 448 | 448 | *Lookup<bool>(info.field, options) = !is_negation; | |
| 449 | 449 | break; | |
| 450 | - case kInteger: | ||
| 450 | + case kInteger: { | ||
| 451 | + // Special case to pass --stack-trace-limit down to V8. | ||
| 452 | + if (name == "--stack-trace-limit") { | ||
| 453 | + v8_args->push_back(arg); | ||
| 454 | + } | ||
| 451 | 455 | *Lookup<int64_t>(info.field, options) = std::atoll(value.c_str()); | |
| 452 | 456 | break; | |
| 457 | + } | ||
| 453 | 458 | case kUInteger: | |
| 454 | 459 | *Lookup<uint64_t>(info.field, options) = | |
| 455 | 460 | std::strtoull(value.c_str(), nullptr, 10); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -921,7 +921,10 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( | |||
| 921 | 921 | "--perf-basic-prof-only-functions", "", V8Option{}, kAllowedInEnvvar); | |
| 922 | 922 | AddOption("--perf-prof", "", V8Option{}, kAllowedInEnvvar); | |
| 923 | 923 | AddOption("--perf-prof-unwinding-info", "", V8Option{}, kAllowedInEnvvar); | |
| 924 | - AddOption("--stack-trace-limit", "", V8Option{}, kAllowedInEnvvar); | ||
| 924 | + AddOption("--stack-trace-limit", | ||
| 925 | + "", | ||
| 926 | + &PerIsolateOptions::stack_trace_limit, | ||
| 927 | + kAllowedInEnvvar); | ||
| 925 | 928 | AddOption("--disallow-code-generation-from-strings", | |
| 926 | 929 | "disallow eval and friends", | |
| 927 | 930 | V8Option{}, | |
@@ -1313,6 +1316,11 @@ void GetCLIOptionsValues(const FunctionCallbackInfo<Value>& args) { | |||
| 1313 | 1316 | if (item.first == "--abort-on-uncaught-exception") { | |
| 1314 | 1317 | value = Boolean::New(isolate, | |
| 1315 | 1318 | s.original_per_env->abort_on_uncaught_exception); | |
| 1319 | + } else if (item.first == "--stack-trace-limit") { | ||
| 1320 | + value = | ||
| 1321 | + Number::New(isolate, | ||
| 1322 | + static_cast<double>( | ||
| 1323 | + *_ppop_instance.Lookup<int64_t>(field, opts))); | ||
| 1316 | 1324 | } else { | |
| 1317 | 1325 | value = undefined_value; | |
| 1318 | 1326 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -273,6 +273,7 @@ class PerIsolateOptions : public Options { | |||
| 273 | 273 | bool report_uncaught_exception = false; | |
| 274 | 274 | bool report_on_signal = false; | |
| 275 | 275 | bool experimental_shadow_realm = false; | |
| 276 | + int64_t stack_trace_limit = 10; | ||
| 276 | 277 | std::string report_signal = "SIGUSR2"; | |
| 277 | 278 | bool build_snapshot = false; | |
| 278 | 279 | std::string build_snapshot_config; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This is meant to be run with --trace-exit. | ||
| 4 | + | ||
| 5 | + const depth = parseInt(process.env.STACK_DEPTH) || 30; | ||
| 6 | + let counter = 1; | ||
| 7 | + function recurse() { | ||
| 8 | + if (counter++ < depth) { | ||
| 9 | + recurse(); | ||
| 10 | + } else { | ||
| 11 | + process.exit(0); | ||
| 12 | + } | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + recurse(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,42 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This tests that --stack-trace-limit can be used to tweak the stack trace size of --trace-exit. | ||
| 4 | + require('../common'); | ||
| 5 | + const fixture = require('../common/fixtures'); | ||
| 6 | + const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + | ||
| 9 | + // When the stack trace limit is bigger than the stack trace size, it should output them all. | ||
| 10 | + spawnSyncAndAssert( | ||
| 11 | + process.execPath, | ||
| 12 | + ['--trace-exit', '--stack-trace-limit=50', fixture.path('deep-exit.js')], | ||
| 13 | + { | ||
| 14 | + env: { | ||
| 15 | + ...process.env, | ||
| 16 | + STACK_DEPTH: 30 | ||
| 17 | + } | ||
| 18 | + }, | ||
| 19 | + { | ||
| 20 | + stderr(output) { | ||
| 21 | + const matches = [...output.matchAll(/at recurse/g)]; | ||
| 22 | + assert.strictEqual(matches.length, 30); | ||
| 23 | + } | ||
| 24 | + }); | ||
| 25 | + | ||
| 26 | + // When the stack trace limit is smaller than the stack trace size, it should truncate the stack size. | ||
| 27 | + spawnSyncAndAssert( | ||
| 28 | + process.execPath, | ||
| 29 | + ['--trace-exit', '--stack-trace-limit=30', fixture.path('deep-exit.js')], | ||
| 30 | + { | ||
| 31 | + env: { | ||
| 32 | + ...process.env, | ||
| 33 | + STACK_DEPTH: 30 | ||
| 34 | + } | ||
| 35 | + }, | ||
| 36 | + { | ||
| 37 | + stderr(output) { | ||
| 38 | + const matches = [...output.matchAll(/at recurse/g)]; | ||
| 39 | + // The top frame is process.exit(), so one frame from recurse() is truncated. | ||
| 40 | + assert.strictEqual(matches.length, 29); | ||
| 41 | + } | ||
| 42 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments