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

Modify environment binding behaviour of function #1010

Merged
merged 3 commits into from
Jan 8, 2021
Merged

Modify environment binding behaviour of function #1010

merged 3 commits into from
Jan 8, 2021

Conversation

54k1
Copy link
Contributor

@54k1 54k1 commented Dec 29, 2020

This Pull Request fixes/closes #669.

If a binding for the function name already exists, we should simply override it (set_mutable_binding), otherwise we need to create a new binding. For this to be accurate, we need to also fix #858, since now we are simply overriding the binding (potentially let or const).

This seems to fix it, however, I haven't found this in the documentation. The implementation of var also seems to follow this. Could anybody provide a link to the part where this is described in the documentation?

@codecov
Copy link

codecov bot commented Dec 29, 2020

Codecov Report

Merging #1010 (da0f878) into master (ceca316) will increase coverage by 0.01%.
The diff coverage is 69.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1010      +/-   ##
==========================================
+ Coverage   58.61%   58.62%   +0.01%     
==========================================
  Files         172      172              
  Lines       11763    11766       +3     
==========================================
+ Hits         6895     6898       +3     
  Misses       4868     4868              
Impacted Files Coverage Δ
...c/syntax/ast/node/declaration/function_decl/mod.rs 70.73% <69.23%> (+2.31%) ⬆️

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 ceca316...f1dd836. Read the comment docs.

@RageKnify
Copy link
Member

RageKnify commented Dec 30, 2020

Test262 conformance changes:

Test result master count PR count difference
Total 78,493 78,493 0
Passed 24,005 24,037 +32
Ignored 15,585 15,585 0
Failed 38,903 38,871 -32
Panics 90 59 -31
Conformance 30.58 30.62 +0.04%

The numbers look good.

I think adding some tests would be nice to make the desired behaviour clearer.

@RageKnify RageKnify added bug Something isn't working execution Issues or PRs related to code execution labels Dec 30, 2020
@jasonwilliams
Copy link
Member

Thanks for looking at this @54k1
I think currently we don't check for duplicates at parse-time nor is there a mechanism for doing so. So we don't have good early error support for that.

One place to handle that would be here (however this only accounts for when bindings are created as a list.
https://github.com/jasonwilliams/boa/blob/master/boa/src/syntax/parser/statement/declaration/lexical.rs#L145-L208

This could need a new issue, but im open to hear what the others think

This seems to fix it, however, I haven't found this in the documentation. The implementation of var also seems to follow this. Could anybody provide a link to the part where this is described in the documentation?

Could you go into more detail here? What documentation are you referring to? The specification?

I think adding some tests would be nice to make the desired behaviour clearer.

Yep adding some tests here would be good enough as a fix for the "environment side"

@Razican Razican added this to the v0.11.0 milestone Jan 1, 2021
Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

This fix looks good to me. We still need to fix #858, but I believe that is a different issue. We need to implement a pre-parsing strategy I think.

@54k1
Copy link
Contributor Author

54k1 commented Jan 3, 2021

@jasonwilliams Yes, I meant the specification, sorry about the confusion
@Razican Yes, it's not directly related to #858, but assumes that SyntaxError is thrown for those cases mentioned in #858.
@RageKnify , I've added just a basic test. What other things can we test?

@RageKnify
Copy link
Member

I've found CreateGlobalFunctionBinding in the spec, which seems to be the approppriate section of the spec that describes the behaviour we were looking for.

The "call-trace" seems to be ScriptEvaluation -> GlobalDeclarationInstantiation -> env.CreateGlobalFunctionBinding

@RageKnify
Copy link
Member

RageKnify commented Jan 4, 2021

Seems like run for FunctionDecl should be using GlobalEnvironmentRecord::create_global_function_binding, but instead the bindings are created in the LexicalEnvironment. I'm not really familiar with these aspects, maybe @jasonwilliams or other Members have a better understanding of these concepts.

@jasonwilliams
Copy link
Member

@RageKnify that's interesting, the way functions are bound right now is we just use the containing scope. I don't know if we're supposed to be using create_global_function_binding for all of our functions maybe that's some research we need to do. That would in theory make runtime slower though, as every function call would need to traverse the scope chain to the top.

@54k1 you're right in that in theory we would catch this during parsing (as an early error), but we don't have functionality to check duplicates as parsing time just yet, but I see you've created an issue for that anyway.

Looks good to me

@Razican
Copy link
Member

Razican commented Jan 7, 2021

Does this help with #989?

@RageKnify
Copy link
Member

Does this help with #989?

No, just tested it, ran the exemple code from #989 in this branch and the bug remains.

@Razican Razican merged commit d9916fc into boa-dev:master Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working execution Issues or PRs related to code execution
Projects
None yet
5 participants