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

[Merged by Bors] - Fix var collisions in strict eval calls #2382

Closed
wants to merge 2 commits into from

Conversation

jedel1043
Copy link
Member

@jedel1043 jedel1043 commented Oct 26, 2022

This Pull Request allows collisions of var declarations with already existing lexical bindings if the eval call is strict or occurs within strict code. In short, it allows:

{
  let x;
  {
    eval('"use strict"; var x;');
  }
}

and

"use strict";
{
  let x;
  {
    eval('var x;');
  }
}

This is valid since in strict code all eval calls get their own function environment, making it impossible to declare a new var in the outer function environment. This change also skips poisoning environments on strict code, because eval cannot add new declarations for the current environment in that situation.

@jedel1043 jedel1043 added execution Issues or PRs related to code execution vm Issues and PRs related to the Boa Virtual Machine. labels Oct 26, 2022
@jedel1043 jedel1043 added this to the v0.17.0 milestone Oct 26, 2022
@github-actions
Copy link

github-actions bot commented Oct 26, 2022

Test262 conformance changes

Test result main count PR count difference
Total 93,789 93,789 0
Passed 69,176 69,179 +3
Ignored 18,352 18,352 0
Failed 6,261 6,258 -3
Panics 0 0 0
Conformance 73.76% 73.76% +0.00%
Fixed tests (3):
test/language/eval-code/direct/var-env-lower-lex-strict-source.js [strict mode] (previously Failed)
test/language/eval-code/direct/var-env-lower-lex-strict-source.js (previously Failed)
test/language/eval-code/direct/var-env-lower-lex-strict-caller.js [strict mode] (previously Failed)

@codecov
Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Merging #2382 (a66a08a) into main (8a5f141) will increase coverage by 0.09%.
The diff coverage is 21.21%.

@@            Coverage Diff             @@
##             main    #2382      +/-   ##
==========================================
+ Coverage   39.93%   40.02%   +0.09%     
==========================================
  Files         304      304              
  Lines       23308    23306       -2     
==========================================
+ Hits         9307     9328      +21     
+ Misses      14001    13978      -23     
Impacted Files Coverage Δ
boa_engine/src/builtins/eval/mod.rs 11.42% <0.00%> (-1.48%) ⬇️
boa_engine/src/context/mod.rs 35.80% <0.00%> (+1.04%) ⬆️
boa_engine/src/syntax/parser/expression/unary.rs 50.94% <33.33%> (-1.89%) ⬇️
boa_engine/src/environments/runtime.rs 28.00% <42.85%> (+3.00%) ⬆️
boa_engine/src/job.rs 60.00% <0.00%> (-6.67%) ⬇️
boa_engine/src/vm/opcode/push/array.rs 76.47% <0.00%> (-3.53%) ⬇️
boa_engine/src/builtins/generator/mod.rs 10.34% <0.00%> (-1.02%) ⬇️
boa_engine/src/builtins/proxy/mod.rs 9.67% <0.00%> (-0.67%) ⬇️
boa_engine/src/builtins/async_generator/mod.rs 6.20% <0.00%> (-0.65%) ⬇️
... and 13 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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.

Thank you!

@jedel1043
Copy link
Member Author

bors r+

bors bot pushed a commit that referenced this pull request Oct 26, 2022
This Pull Request allows collisions of var declarations with already existing lexical bindings if the `eval` call is strict or occurs within strict code. In short, it allows:

```Javascript
{
  let x;
  {
    eval('"use strict"; var x;');
  }
}
```

and

```Javascript
"use strict";
{
  let x;
  {
    eval('var x;');
  }
}
```

This is valid since in strict code all `eval` calls get their own function environment, making it impossible to declare a new var in the outer function environment. This change also skips poisoning environments on strict code, because `eval` cannot add new declarations for the current environment in that situation.
@bors
Copy link

bors bot commented Oct 26, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Fix var collisions in strict eval calls [Merged by Bors] - Fix var collisions in strict eval calls Oct 26, 2022
@bors bors bot closed this Oct 26, 2022
@bors bors bot deleted the indirect-eval-fix branch October 26, 2022 17:39
@RageKnify RageKnify added the bug Something isn't working label Nov 9, 2022
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 vm Issues and PRs related to the Boa Virtual Machine.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants