]> git.kaiwu.me - njs.git/commit
Fixed call argument evaluation.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 4 Mar 2026 07:22:54 +0000 (23:22 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 12 Mar 2026 22:26:01 +0000 (15:26 -0700)
commitfd5e523fc01036638c6ec0aa75519e2f42a0bfab
tree00a69d321c3d6af5f4f33dee72858254778dd480
parent5f2fc915eed0701464c8711723fec9dc4bc2dc35
Fixed call argument evaluation.

Previously, call lowering created FUNCTION_FRAME and METHOD_FRAME before
argument evaluation.  This made call ordering observably wrong: for
non-callable callees, the error was thrown before arguments with side
effects were evaluated, violating the ECMAScript specification.  It also
prevented await expressions in call arguments, which were rejected at
parse time because suspending inside a half-created frame was not
supported.

The fix evaluates arguments first, then emits the frame, PUT_ARG, and
FUNCTION_CALL.  Callee and receiver values are captured into temporaries
before argument evaluation to guard against argument side effects.
Method properties are resolved via PROPERTY_GET before arguments.

METHOD_FRAME is redefined from a composite opcode (property lookup +
callability check + frame creation) to a pure frame-creation opcode
that takes an already-resolved function and explicit "this" value.
The parser always wraps call expressions in a NJS_TOKEN_FUNCTION_CALL
node, removing the NJS_TOKEN_NAME special case.
src/njs_disassembler.c
src/njs_generator.c
src/njs_parser.c
src/njs_vmcode.c
src/njs_vmcode.h
src/test/njs_unit_test.c
test/shell_test_njs.exp