]> git.kaiwu.me - njs.git/commit
Parser: fix "for" initializer parsing after a failed speculative parse
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 1 Sep 2026 01:29:41 +0000 (18:29 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 4 Sep 2026 20:56:37 +0000 (13:56 -0700)
commit55f72dc3defe3eba610d9e0304ab544d17652545
tree4460de46bc6379e64dcea7c9d70c6cf328d186bb
parent5614d8ef0bd8d6ef7e6f2c2a9798cc2b1954af89
Parser: fix "for" initializer parsing after a failed speculative parse

Previously, the "for" initializer was parsed speculatively as a
LeftHandSideExpression, and njs_parser_for_expression_map_reparse() resumed
parsing whenever that parse produced no node.  njs_parser_reject() rewinds
the state stack only, so the resume continued from a later token with an
abandoned function scope still on parser->scope, and generated bytecode with
a scope that is never instantiated at run time.

The fix is to remove that landing state together with its frame, so a
rejected speculative parse reports a SyntaxError, and to dispatch the
initializer starts that cannot begin a LeftHandSideExpression to <Expression>
directly.  Routing "await" through that dispatch also applies [~In] to it, so
a bare "in" in an await initializer is now a SyntaxError.

Found by OSS-Fuzz.
src/njs_parser.c
src/test/njs_unit_test.c