Skip to content

Add default parameter support - #988

Closed
0x7D2B wants to merge 1 commit into
boa-dev:masterfrom
0x7D2B:original-master
Closed

0x7D2B wants to merge 1 commit into
boa-dev:masterfrom
0x7D2B:original-master

Conversation

@0x7D2B

@0x7D2B 0x7D2B commented Dec 20, 2020

Copy link
Copy Markdown
Contributor

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

codecov Bot commented Dec 20, 2020 •

Copy link
Copy Markdown

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

0x7D2B commented Dec 20, 2020

Copy link
Copy Markdown
Contributor Author

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 C-Builtins PRs and Issues related to builtins/intrinsics A-Enhancement New feature or request A-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

Razican commented Jan 7, 2021

Copy link
Copy Markdown
Member

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

@0x7D2B

0x7D2B commented Jan 7, 2021

Copy link
Copy Markdown
Contributor Author

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

Razican commented May 9, 2021

Copy link
Copy Markdown
Member

Hello @0x7D2B is there any progress on this?

@0x7D2B

0x7D2B commented May 18, 2021

Copy link
Copy Markdown
Contributor Author

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

A-Enhancement New feature or request A-Execution Issues or PRs related to code execution Blocked Waiting for another code change C-Builtins PRs and Issues related to builtins/intrinsics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants