Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default parameter support #988

Closed
wants to merge 1 commit into from
Closed

Conversation

0x7D2B
Copy link
Contributor

@0x7D2B 0x7D2B commented Dec 20, 2020

Modern JavaScript has support for default parameters in functions. Boa has support for the syntax but currently default parameters are ignored. For example, this code:

function test(a, b = 2, c = a + b) {
    console.log(a, b, c);
}
test()
test(1)

Result produced by current Boa master:

undefined undefined undefined
1 undefined undefined
undefined

Expected result:

undefined 2 NaN
1 2 3
undefined

This PR implements support for this feature.

@0x7D2B 0x7D2B changed the title Add default parameters support Add default parameter support Dec 20, 2020
default parameters

use default arguments when explicitly passing undefined

run rustfmt
@codecov
Copy link

codecov bot commented Dec 20, 2020

Codecov Report

Merging #988 (6c7f95f) into master (880792e) will increase coverage by 0.00%.
The diff coverage is 50.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #988   +/-   ##
=======================================
  Coverage   59.67%   59.67%           
=======================================
  Files         166      166           
  Lines       10813    10823   +10     
=======================================
+ Hits         6453     6459    +6     
- Misses       4360     4364    +4     
Impacted Files Coverage Δ
boa/src/object/gcobject.rs 63.34% <50.00%> (-0.87%) ⬇️
boa/src/syntax/ast/node/mod.rs 49.60% <0.00%> (+1.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 880792e...6c7f95f. Read the comment docs.

@0x7D2B 0x7D2B marked this pull request as draft December 20, 2020 16:08
@0x7D2B
Copy link
Contributor Author

0x7D2B commented Dec 20, 2020

Need to handle scope correctly (function body has a separate scope if default parameters are used: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters#Scope_Effects) but can't really test this due to #989.

@Razican Razican added builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request execution Issues or PRs related to code execution labels Dec 25, 2020
@Razican Razican added the blocked Waiting for another code change label Jan 7, 2021
@Razican
Copy link
Member

Razican commented Jan 7, 2021

If I understand this correctly, this is blocked on #989, right?

@0x7D2B
Copy link
Contributor Author

0x7D2B commented Jan 7, 2021

Yeah. I have a commit that sets up the right scopes in theory, but it doesn't work correctly due to issues caused by #989 (the second scope effects example given on the MDN page is a good showcase of the bug) so I can't fully finish this and add tests.

@Razican
Copy link
Member

Razican commented May 9, 2021

Hello @0x7D2B is there any progress on this?

@0x7D2B
Copy link
Contributor Author

0x7D2B commented May 18, 2021

I should probably restart this one from scratch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Waiting for another code change builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants