Commit 46e11e8
authored
Add --max-stack / -s flag to limit stack depth (#637)
## Summary
- Adds a `--max-stack` / `-s` CLI flag (default 500) to limit the
evaluation stack depth, matching go-jsonnet's `-s` / `--max-stack`
option.
- Introduces a stack frame counter in the Evaluator,
incremented/decremented at function calls (`Apply*`, `ApplyBuiltin*`),
object field evaluation (`invoke`), imports, and default parameter
evaluation.
- When the counter exceeds `maxStack`, a clear `sjsonnet.Error: Max
stack frames exceeded.` is thrown instead of a raw JVM
`StackOverflowError`.
## Test plan
- [x] JVM tests pass (140/140)
- [x] WASM tests pass (333/333)
- [x] New unit tests for recursive functions, mutual recursion, depth
within limits, and builtin calls
- [x] Golden files updated for `error.recursive_function_nonterm`,
`error.recursive_import`, `error.recursive_object_non_term`, and
`error.function_infinite_default`
- [x] CLI flag verified with `--max-stack` and `-s` short form1 parent ad4edb1 commit 46e11e8
12 files changed
Lines changed: 241 additions & 4225 deletions
File tree
- sjsonnet
- src-jvm-native/sjsonnet
- src/sjsonnet
- test
- resources/test_suite
- src/sjsonnet
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
| 81 | + | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
164 | 170 | | |
165 | 171 | | |
166 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
| 158 | + | |
| 159 | + | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| |||
0 commit comments