Open
Conversation
This closes nginx#835 feature request on Github.
Unlike regular compound assignments (+=, -=), these operators short-circuit: the RHS is not evaluated and no assignment occurs if the logical condition is already satisfied.
e66d340 to
0ed7135
Compare
There was a problem hiding this comment.
Pull request overview
Adds runtime and parsing support for JavaScript optional chaining (?.) in njs, addressing the behavior reported in issue #835 (e.g. f?.() / obj?.prop short-circuiting on null/undefined).
Changes:
- Introduces a new VM opcode (
NJS_VMCODE_OPTIONAL_CHAIN) to implement optional-chain short-circuiting at runtime. - Updates the parser and bytecode generator to build/emit optional-chaining AST + vmcode (including
?.()call forms). - Adds a comprehensive set of unit tests covering property access, calls, delete semantics, and interactions with
??.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/test/njs_unit_test.c | Adds unit tests for optional chaining behavior across many forms/corner cases. |
| src/njs_vmcode.h | Adds NJS_VMCODE_OPTIONAL_CHAIN opcode to the VM opcode enum. |
| src/njs_vmcode.c | Implements interpreter handling for the optional-chain opcode and wires it into the dispatch table. |
| src/njs_parser.c | Extends parsing to recognize/construct optional-chaining AST nodes and delete behavior adjustments. |
| src/njs_lexer.h | Introduces AST token types for optional chaining nodes (OPTIONAL_CHAIN, OPTIONAL_CHAIN_REF). |
| src/njs_generator.c | Generates bytecode for optional chaining, including short-circuit jump patching and this handling in method-call cases. |
| src/njs_disassembler.c | Adds disassembly formatting for the new optional-chain opcode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This closes #835 feature request on Github.