Skip to content

Fix var initialization when it redeclares a parameter with an initializer - #5647

Queued
Basharkhan7776 wants to merge 1 commit into
boa-dev:mainfrom
Basharkhan7776:issue-#5634
Queued

Basharkhan7776 wants to merge 1 commit into
boa-dev:mainfrom
Basharkhan7776:issue-#5634

Conversation

@Basharkhan7776

Copy link
Copy Markdown

Fixes #5634.

When a function has parameter expressions, FunctionDeclarationInstantiation step 28 gives the body's var names a separate varEnv. A var whose name is also a parameter must be initialized from the parameter environment (env.GetBindingValue), not from varEnv.

The bytecompiler read varEnv instead. That binding has no register yet, so compilation emitted ThrowNewReferenceError("access of uninitialized binding") before the body ran. A later emit_store_undefined also discarded the copied value, so a bare var b would have become undefined instead of the parameter's value.

GetBindingValue now uses scopes.parameter_scope(), and DefInitVar stores that value. Parameter-list closures still close over the parameter environment.

function f(a = () => b, b = 2) { var b = 3; return [a(), b]; }
f(); // [2, 3]

@Basharkhan7776
Basharkhan7776 requested a review from a team as a code owner November 9, 2026 13:18
@github-actions github-actions Bot added the Waiting On Review Waiting on reviews from the maintainers label Nov 9, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Nov 9, 2026
@github-actions github-actions Bot added C-Tests Issues and PRs related to the tests. C-VM Issues and PRs related to the Boa Virtual Machine. labels Nov 9, 2026
@abdulhamid999

Copy link
Copy Markdown

Hi @Basharkhan7776, great work on tracking this down!

The fix cleanly addresses ECMAScript \FunctionDeclarationInstantiation\ step 28.h.iv. Reading from \scopes.parameter_scope()\ rather than the uninitialized \�arEnv\ correctly preserves the parameter binding value, and removing the erroneous \emit_store_undefined\ prevents clobbering that copied value before \DefInitVar.

Tested locally against \main\ via \cargo test -p boa_engine function\ and all tests pass cleanly. The added test cases in \core/engine/src/tests/function.rs\ cover arrow functions, default parameter expressions, and closure capture thoroughly.

Looks solid!

@Basharkhan7776

Copy link
Copy Markdown
Author

Thanks for the review. Glad the parameter-environment read and the removed emit_store_undefined match what you saw locally.

@github-actions

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,578 53,578 0
Passed 51,450 51,451 +1
Ignored 1,648 1,648 0
Failed 480 479 -1
Panics 0 0 0
Conformance 96.03% 96.03% +0.00%
Fixed tests (1):
test/staging/sm/Function/arguments-parameter-shadowing.js (previously Failed)

Tested main commit: bfaa15a7d60d8c92370a423d4134ab19b1b1fae0
Tested PR commit: 469f17bb98618a1f6bd1e7103e529943f16fad62
Compare commits: bfaa15a...469f17b

@HalidOdat HalidOdat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Thanks for the contribution! 🚀

@HalidOdat
HalidOdat enabled auto-merge November 10, 2026 19:27
@HalidOdat
HalidOdat added this pull request to the merge queue Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.17%. Comparing base (6ddc2b4) to head (469f17b).
⚠️ Report is 1086 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5647       +/-   ##
===========================================
+ Coverage   47.24%   63.17%   +15.93%     
===========================================
  Files         476      538       +62     
  Lines       46892    60608    +13716     
===========================================
+ Hits        22154    38292    +16138     
+ Misses      24738    22316     -2422     

☔ View full report in Codecov by Harness.
📢 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.

This branch has not been deployed

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

Labels

C-Tests Issues and PRs related to the tests. C-VM Issues and PRs related to the Boa Virtual Machine. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closures in parameter expressions throw "access of uninitialized binding" when the body redeclares the parameter with var

3 participants