"InternalError: too much recursion" on deep ternary chains
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
People
(Reporter: skyschub, Unassigned)
References
(Blocks 1 open bug, )
Details
As part of investigations into the backgrounds of bug 2033215, Microsoft let us know about a difference in browser behavior on deep-nested ternary operator chains. It appears that Firefox throws a
InternalError: too much recursion
at ~5k nested operations, while V8 has no issues with 100k. A very helpful MS engineer (thank you!!) provided a repo with instructions and more details at https://github.com/guru-irl/firefox-ternary-parse-recursion
While no human would ever hand-write code like that, the code in question was created by oxc, which is increasing in popularity, and the problematic code in question was part of a chunk-id-to-filename map function as per the repo, so I can totally imagine other web apps eventually running into the same limit.
We should figure out if we can get closer to V8's behavior here in order to avoid future surprises.
Updated•1 month ago
|
Comment 1•1 month ago
|
||
This needs modification in the following parts:
- The recursion between
GeneralParser::condExprandGeneralParser::assignExpr - The recursion in
ParseNodeVisitor, its subclasses, andTernaryNode::visit - The recursion between
BytecodeEmitter::emitConditionalExpressionandBytecodeEmitter::emitTree
We could use similar structure as if-else-if.
Comment 3•1 month ago
|
||
I filed an issue against oxc to avoid introducing these problems: https://github.com/oxc-project/oxc/issues/21901
Comment 4•1 month ago
|
||
and guru-irl had previously put a PR up: https://github.com/oxc-project/oxc/pull/21841
Updated•1 day ago
|
Description
•