Skip to content

fix: replace unreachable!/todo! with proper error handling and no-op#4940

Open
tkshsbcue wants to merge 2 commits intoboa-dev:mainfrom
tkshsbcue:fix/stability-unreachable-and-access-set-this
Open

fix: replace unreachable!/todo! with proper error handling and no-op#4940
tkshsbcue wants to merge 2 commits intoboa-dev:mainfrom
tkshsbcue:fix/stability-unreachable-and-access-set-this

Conversation

@tkshsbcue
Copy link
Contributor

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 proper Error::general so unexpected tokens produce parse errors instead of panics. (2) Implement access_set for Access::This in the bytecompiler—in sloppy mode, assignment to this is a no-op per ECMAScript; previously todo!() 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 this in 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 had todo!("access_set this"), so executing such code would panic. Implementing the no-op path removes this panic and aligns with the spec.

Changes

Category Description
Parser core/parser/src/parser/statement/declaration/hoistable/mod.rs: _ => unreachable!(...)Err(Error::general("expected 'function', 'async', or 'class' in declaration", tok.span().start()))
Parser core/parser/src/parser/statement/declaration/lexical.rs: _ => unreachable!(...)Err(Error::general("expected 'let' or 'const' in lexical declaration", tok.span().start()))
Bytecompiler core/engine/src/bytecompiler/mod.rs: Access::This => todo!(...) → evaluate RHS via expr_fn(self) for side effects, then no-op (no assignment)

Technical Details

  • Files modified: core/parser/.../hoistable/mod.rs, core/parser/.../lexical.rs, core/engine/src/bytecompiler/mod.rs
  • Behavioral impact: Parser: unexpected tokens in declaration context now yield parse errors. Bytecompiler: this = expr in sloppy mode now executes without panicking (RHS evaluated, assignment ignored).
  • Strict mode: Assignment to this in 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 pass
  • cargo test -p boa_engine --lib — all 921 tests pass
  • cargo clippy — no warnings

- 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
@tkshsbcue tkshsbcue requested a review from a team as a code owner March 8, 2026 01:55
@github-actions
Copy link

github-actions bot commented Mar 8, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 49,687 49,687 0
Ignored 2,262 2,262 0
Failed 1,014 1,014 0
Panics 0 0 0
Conformance 93.81% 93.81% 0.00%

Tested main commit: 28648a3207b482955f3f93935de1b181ab72c477
Tested PR commit: 9f3b70d6ea1b58550faadc2c215e0a2e2e0dd7e8
Compare commits: 28648a3...9f3b70d

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.93%. Comparing base (6ddc2b4) to head (9f3b70d).
⚠️ Report is 776 commits behind head on main.

Files with missing lines Patch % Lines
...parser/src/parser/statement/declaration/lexical.rs 0.00% 4 Missing ⚠️
.../src/parser/statement/declaration/hoistable/mod.rs 0.00% 3 Missing ⚠️
core/engine/src/bytecompiler/mod.rs 0.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tkshsbcue
Copy link
Contributor Author

@jedel1043 i hope you can review my PR
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant