fix: replace unreachable!/todo! with proper error handling and no-op#4940
Open
tkshsbcue wants to merge 2 commits intoboa-dev:mainfrom
Open
fix: replace unreachable!/todo! with proper error handling and no-op#4940tkshsbcue wants to merge 2 commits intoboa-dev:mainfrom
tkshsbcue wants to merge 2 commits intoboa-dev:mainfrom
Conversation
- Parser: replace unreachable! with Error::general in hoistable and lexical declaration parsers for unexpected tokens (defensive, prevents panics) - Bytecompiler: implement access_set for Access::This as no-op (sloppy mode this assignment per spec); previously todo! would panic Made-with: Cursor
Test262 conformance changes
Tested main commit: |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4940 +/- ##
===========================================
+ Coverage 47.24% 57.93% +10.69%
===========================================
Files 476 557 +81
Lines 46892 60944 +14052
===========================================
+ Hits 22154 35309 +13155
- Misses 24738 25635 +897 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
@jedel1043 i hope you can review my PR |
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.
fix: replace unreachable!/todo! with proper error handling and no-op
Summary
Two stability improvements: (1) Replace
unreachable!()in the hoistable and lexical declaration parsers with properError::generalso unexpected tokens produce parse errors instead of panics. (2) Implementaccess_setforAccess::Thisin the bytecompiler—in sloppy mode, assignment tothisis a no-op per ECMAScript; previouslytodo!()would panic.Motivation
Parser unreachable! — The hoistable and lexical declaration parsers used
unreachable!("unknown token found: {:?}", tok)in their catch-all arms. In theory the caller ensures only valid tokens reach these parsers, but if a bug or edge case produces an unexpected token, the parser would panic. For embedded use and tooling, panics are unacceptable. Returning a parse error lets the host handle the failure gracefully.Bytecompiler todo! — Assigning to
thisin sloppy mode (e.g.this = 5) is valid JavaScript; the assignment is a no-op (the RHS is evaluated for side effects only). The bytecompiler hadtodo!("access_setthis"), so executing such code would panic. Implementing the no-op path removes this panic and aligns with the spec.Changes
core/parser/src/parser/statement/declaration/hoistable/mod.rs:_ => unreachable!(...)→Err(Error::general("expected 'function', 'async', or 'class' in declaration", tok.span().start()))core/parser/src/parser/statement/declaration/lexical.rs:_ => unreachable!(...)→Err(Error::general("expected 'let' or 'const' in lexical declaration", tok.span().start()))core/engine/src/bytecompiler/mod.rs:Access::This => todo!(...)→ evaluate RHS viaexpr_fn(self)for side effects, then no-op (no assignment)Technical Details
core/parser/.../hoistable/mod.rs,core/parser/.../lexical.rs,core/engine/src/bytecompiler/mod.rsthis = exprin sloppy mode now executes without panicking (RHS evaluated, assignment ignored).thisin strict mode is a SyntaxError and is rejected by the parser, so the bytecompiler path is only reached in sloppy mode.Testing
cargo test -p boa_parser— all 296 tests passcargo test -p boa_engine --lib— all 921 tests passcargo clippy— no warnings